hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tom Nichols" <tmnich...@gmail.com>
Subject DSL for Groovy
Date Tue, 25 Nov 2008 13:53:23 GMT
Hi --

I've created a builder-style HBase client DSL for Groovy -- currently
it just wraps the client API to make inserts and row scans a little
easier.  There probably plenty of room for improvement so I wanted to
submit it to the community.  Any feedback or suggestions are welcome.

Here's an example:

def hbase = HBase.connect() // may optionally pass host name
/* Create:  this will create a table if it does not exist, or disable
& update column families
   if the table already does exist.  The table will be enabled when
the create statement returns */
hbase.create( 'myTable' ) {
  family( 'familyOne' ) {
    inMemory = true
    bloomFilter = false
  }
}

/* Insert/ update rows:
hbase.update( 'myTable' ) {
  row( 'rowOne' ) {
    family( 'familyOne' ) {
      col 'one', 'someValue'
      col 'two', 'anotherValue'
      col 'three', 1234
    }
    // alternate form that doesn't use nested family name:
    col 'familyOne:four', 12345
  }
  row( 'rowTwo' ) { /* more column values */ }
  // etc
}

So a more realistic example -- if you were iterating through some data
and inserting it would look like this:

hbase.update( 'myTable' ) {
	new URL( someCSV ).eachLine { line ->
		def values = line.split(',')	
		row( values[0] ) {
			col 'fam1:val1', values[1]
			// etc...	
		}
	}
}

There is also wrapper for the scanner API as well:

hbase.scan( cols : ['fam:col1', 'fam:col2'],
            start : '001', end : '200',
            // any timestamp args may be long, Date or Calendar
            timestamp : Date.parse( 'yy/mm/dd HH:MM:ss', '08/11/25 05:00:00' )
            ) { row ->

	// each row is a RowResult instance -- which is a Map!  So all map
operations are valid here:
  row.each { println '${it.key} : ${it.value}' }
}

Mime
View raw message