Giter VIP home page Giter VIP logo

agiato's Introduction

Agiato is a simple no frill Cassandra NOSQL database API. My goal has been to make sure that
it does not take someone more than hour to learn the API and start using it.


It DOES the following
---------------------
- Supports Cassandra version .7x
- Simple wrapper around thrift API
- API does not support different data types. Basically deals with ByteBuffer
- An Util class is provided for conversion between ByteBuffer and basic data types, which the client app may use
- API only understands ByteBuffer
- The whole API is defined in one class
- There is database connection pooling using appache commons pool library
- There is a simple round robin load balancer, out of the box.
- User defined load balancer can be plugged in
- There is JSON file that defines cluster, connection configuration, key space definitions, indexes and named queries
- The API loads the JSON on start up and creates the key space and column families if necessary
- The client app needs to make sure cassandra.json file is placed in the class path


The API DOES NO DO the following
--------------------------------
- Object mapping
- Data type support


It WILL DO the following in future
----------------------------------
- Support named query and index defined in JSON 

Setup
-----
Here is a sample cassandra.json file. You should change the content to meet your need. Agiato expects this file in the class
path.

{
    "cluster" :
	{
		"hosts" :
		[
			{
				"name" : "localhost",
				"port" : 9160
			}
		],
		"loadBalancerClass" : "agiato.cassandra.connect.RoundRobinLoadBalancer",
		"poolConfig" : 
		{
			"maxActive" : 8,
			"maxIdle" : 8
		}
	},
	"keySpace" :
	{
		"name" : "PatientMonitor",
		"replicaPlacementStrategy" : "org.apache.cassandra.locator.SimpleStrategy",
		"replicationFactor" : 1,
		"endPointSnitch" : "org.apache.cassandra.locator.EndPointSnitch",
		"columnFamilies" : 
		[
			{
				"name" : "MonitorData",
				"columnType" : "Standard",
				"compareWith" : "UTF8Type",
				"keysCached" : 1000,
				"rowsCached" : 10
			},
			{
				"name" : "Patient",
				"columnType" : "Standard",
				"compareWith" : "UTF8Type",
				"keysCached" : 100,
				"rowsCached" : 10
			}

		],
		"indexes" :
	 	[
			{
				"name" : "monitorDataByPatientID",
				"colFamily" : "MonitorData",
				"type" : "1.1.1.2",
				"indexedColumnName" : "patientID",
				"indexedDataType" : 1,
				"storedDataType" : 2,
				"indexKeysCached" : 10,
				"indexRowsCached" : 5
			}
		]

	}
}


Example client code
-------------------
//when your app starts
DataManager.initialize(false);

//insert a super column into MonitorData column family
DataAccess dataAccess = new DataAccess();
List<SuperColumnValue> superColValues = new ArrayList<SuperColumnValue>();

long rowKey = ...
long superColName = ...
List<ColumnValue> colValues = new ArrayList<ColumnValue>();
ColumnValue colVal = new ColumnValue();
colVal.write("ecg", getEcg());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("diaBp", getDiaBp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("sysBp", getSysBp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("temp", getTemp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("pulse", getPulse());
colValues.add(colVal);

SuperColumnValue superColVal = new SuperColumnValue();
superColVal.setNameFromLong(superColName);
superColVal.setValues(colValues);
superColValues.add(superColVal);

dataAccess.insertSuperColumns("MonitorData", rowKey, superColValues, ConsistencyLevel.ALL);

Note
----
Index and named query is not fully tested. It's work in progress. I will provide an update when
it's functional

Reference
---------
For background material on this please visit my following blogs  
http://pkghosh.wordpress.com/2011/03/02/cassandra-secondary-index-patterns/
http://pkghosh.wordpress.com/2010/12/11/easy-cassandra-data-access/






agiato's People

Stargazers

DyanHe avatar  avatar  avatar Giovanni Baleani avatar  avatar Michal Augustýn avatar Pranab Ghosh avatar Liu Chao avatar  avatar

Watchers

Pranab Ghosh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.