Skip to content

Instantly share code, notes, and snippets.

@vithalsamp
vithalsamp / Pre-splitting-HBase-Tables.sh
Last active February 10, 2018 16:45
Pre-splitting-HBase-Tables
$hbase org.apache.hadoop.hbase.util.RegionSplitter table1 HexStringSplit -c 5 -f cf
2018-02-06 12:32:05,595 INFO [main] zookeeper.RecoverableZooKeeper: Process identifier=hconnection-0x2accdbb5 connecting to ZooKeeper ensemble=server.example.co.in:2181, server2.example.co.in:2181
2018-02-06 12:32:05,600 INFO [main] zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.6-1245--1, built on 08/26/2016 00:47 GMT
2018-02-06 12:32:08,808 INFO [main] client.HBaseAdmin: Created table1
hbase(main):009:0> create 'ver_demo', {NAME => 'cf', VERSIONS => 4}
0 row(s) in 2.4730 seconds
=> Hbase::Table - ver_demo
hbase(main):010:0> desc 'ver_demo'
Table ver_demo is ENABLED
ver_demo
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf', BLOOMFILTER => 'ROW', VERSIONS => '4', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '6
hbase(main):011:0> alter 'personalnew', {NAME => 'personal_data',VERSIONS => '4'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.8800 seconds
hbase(main):012:0>
hbase(main):017:0> scan 'personalnew',{VERSIONS=>4}
ROW COLUMN+CELL
1 column=personal_data:age, timestamp=1518070847422, value=25
1 column=personal_data:age, timestamp=1517381138957, value=25
1 column=personal_data:city, timestamp=1518070871233, value=USA
1 column=personal_data:city, timestamp=1517381134473, value=Bengaluru
1 column=personal_data:name, timestamp=1518070904715, value=Ram
1 column=personal_data:name, timestamp=1517381128393, value=Ram
1 row(s) in 0.0110 seconds
hbase(main):003:0> create 'table1', 'cf', SPLITS=> ['a', 'b', 'c']
0 row(s) in 2.2840 seconds
=>Hbase::Table - table1
#!/bin/sh
printf "exists '%s'\n" personalnew | hbase shell 2>&1 | grep -q "does exist" 2>/dev/null
if [ $? -eq 0 ] ; then
printf "table is available.!\n"
else
printf "Table is not present.!\n"
fi
hbase(main):004:0> tab2 = create 'table2','cf'
0 row(s) in 2.3790 seconds
=> Hbase::Table - table2
hbase(main):006:0> tab2.put '001','cf','one'
0 row(s) in 0.0170 seconds
hbase(main):007:0> tab2.scan
ROW COLUMN+CELL
hbase(main):001:0> create 'table1','cf'
0 row(s) in 2.6480 seconds
=> Hbase::Table - table1
hbase(main):002:0> put 'table1','001','cf','one'
0 row(s) in 0.1620 seconds
hbase(main):003:0> scan 'table1'
ROW COLUMN+CELL
hbase(main):016:0> disable 'personal'
0 row(s) in 4.3270 seconds
hbase(main):017:0> snapshot 'personal', 'personalSnapshot'
0 row(s) in 0.4090 seconds
hbase(main):018:0> clone_snapshot 'personalSnapshot', 'personalnew'
0 row(s) in 0.4410 seconds