la-hbase-crud - meetup
TRANSCRIPT
© Hortonworks Inc. 2013
HBase CRUD Beginning concepts
Jeff Markham Solution Engineer [email protected]
© Hortonworks Inc. 2013
HBase CRUD
Page 2
• Table design considerations – Column families
– How many – What data
– Versions – How many
– Rowkey – Structure
© Hortonworks Inc. 2013
HBase CRUD
• Create record
Put p = new Put(Bytes.toBytes(”my_rk")); p.add(Bytes.toBytes("info"),! Bytes.toBytes("name"),! Bytes.toBytes(”Jeff Markham"));!p.add(Bytes.toBytes("info"),! Bytes.toBytes(”company"),! Bytes.toBytes(”Hortonworks"));!
© Hortonworks Inc. 2013
HBase CRUD
• Read record
Get g = new Get(Bytes.toBytes(”my_rk"));!g.addFamily(Bytes.toBytes("info"));!!byte[] b = r.getValue(! Bytes.toBytes("info"),! Bytes.toBytes(”company"));!String company= Bytes.toString(b);!!‘company’: Hortonworks
© Hortonworks Inc. 2013
HBase CRUD
• Delete record
Delete d = new Delete(Bytes.toBytes(”my_rk"));!usersTable.delete(d);!!-OR-!!Delete d = new Delete(Bytes.toBytes(”my_rk"));!d.deleteColumns(! Bytes.toBytes("info"),! Bytes.toBytes(”company"));!usersTable.delete(d);
© Hortonworks Inc. 2013
HBase CRUD
• Table access
HTablePool pool = new HTablePool(conf, Integer.MAX_VALUE);!!HTableInterface table = pool.getTable(“my_table”);!table.put(p);!table.get(g);!table.delete(d);!!table.close();
© Hortonworks Inc. 2013
HBase CRUD
• Scans // Scan the entire table Scan scan = new Scan();!!// Scan a range Scan scan = new Scan(startRow, stopRow);!ResultsScanner rs = table.getScanner(scan);!
© Hortonworks Inc. 2013
HBase CRUD
• Filters
// Filter the scan for pagination Scan scan = new Scan();!PageFilter filter = new PageFilter(10);!scan.setFilter(filter);!ResultsScanner rs = table.getScanner(scan);!
© Hortonworks Inc. 2013
HBase CRUD
• Coprocessors – Observers
– Modify data – Interception – Trigger analogy
– Endpoints – More arbitrary – Extends HBase
• Use cases are limitless – Search – Secondary indexing – Multi row execution (i.e. MultiRowMutationEndpoint)
© Hortonworks Inc. 2013
HBase CRUD
• Coprocessors – Observers
– Modify data – Interception – Trigger analogy
– Endpoints – More arbitrary – Extends HBase
• Use cases are limitless – Search – Secondary indexing – Multi row execution (i.e. MultiRowMutationEndpoint)