source 'file-name.hb'
create 'student','personal'
describe 'student'
alter 'student',{NAME=>'personal',IN_MEMORY=>true}
alter 'student',{NAME=>'uni',VERSIONS=>'4'}
alter 'student','delete'=>'uni'
alter 'student',{NAME=>'university',VERSIONS=>5}
alter 'student',{NAME=>'personal',VERSIONS=>3}
put 'student','007','personal:first-name','James'
put 'student','007','personal:last-name','Bond'
put 'student','007','personal:dob','01-OCT-1960'
scan 'student'
put 'student','007','personal:dob','02-OCT-1960'
get 'student','007',{COLUMN=>'personal:dob',VERSIONS=>5}
scan 'student',{COLUMN=>'personal:dob',VERSIONS=>5}
get 'student','666'
get 'student','666',{COLUMN=>'grade',VERSIONS=>5}
get 'student','666',{COLUMN=>'grade:CSCI235',VERSIONS=>5}
get 'student','007',{COLUMN=>'personal:dob',VERSIONS=>5}
count 'student'
scan 'student'
scan 'student',{VERSIONS=>5}
scan 'student',{COLUMNS=>'personal:dob',VERSIONS=>5}
scan 'student',{COLUMNS=>['personal','university']}
scan 'student',{COLUMNS=>'personal:dob',TIMERANGE=>[1,1502609828830],
VERSIONS=>5}
scan 'student',{COLUMNS=>'personal:dob',
FILTER=>"TimestampsFilter(1,1502609828830)",VERSIONS=>5}
scan 'student',{FILTER=>"QualifierFilter(>=,'binary:f')"}
scan 'student',{FILTER=>"ValueFilter(>=,'binary:J')"}
scan 'student',{FILTER=>"ValueFilter(>=,'binary:J') AND
ValueFilter(<=,'binary:K')"}
scan 'student',{COLUMNS=>'personal:dob',FILTER=>
"QualifierFilter(=,'binary:dob') AND
ValueFilter(=,'binary:02-OCT-1960')"}
delete 'student','666','grade:CSCI235'
deleteall 'student', '007
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateTable {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(conf);
HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("my-table"));
tableDescriptor.addFamily(new HColumnDescriptor("Address"));
tableDescriptor.addFamily(new HColumnDescriptor("Name"));
admin.createTable(tableDescriptor);
boolean tableAvailable = admin.isTableAvailable("my-table");
System.out.println("tableAvailable = " + tableAvailable); } }
public class PutRow {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, "my-table");
Put put = new Put(Bytes.toBytes("007"));
put.add(Bytes.toBytes("Address"),Bytes.toBytes("City"),Bytes.toBytes("Dapto"));
put.add(Bytes.toBytes("Address"),Bytes.toBytes("Street"),Bytes.toBytes("Ellenborough"));
put.add(Bytes.toBytes("Name"),Bytes.toBytes("First"),Bytes.toBytes("James"));
put.add(Bytes.toBytes("Name"),Bytes.toBytes("Last"),Bytes.toBytes("Bond"));
table.put(put);
table.flushCommits();
table.close();
}
}
import java.util.Map; import java.util.NavigableMap
public class GetRow {
public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HTable table = new HTable(conf, "my-table");
Get get = new Get(Bytes.toBytes("007"));
get.setMaxVersions(3);
get.addFamily(Bytes.toBytes("Address"));
get.addColumn(Bytes.toBytes("Name"), Bytes.toBytes("First"));
get.addColumn(Bytes.toBytes("Name"), Bytes.toBytes("Last"));
// Get a specific value
Result result = table.get(get);
String row = Bytes.toString(result.getRow());
String specificValue = Bytes.toString(result.getValue(Bytes.toBytes("Address"),
Bytes.toBytes("City")));
System.out.println("Latest Address:City is: " + specificValue);
specificValue = Bytes.toString(result.getValue(Bytes.toBytes("Address"),
Bytes.toBytes("Street")));
System.out.println("Latest Address:Street is: " + specificValue);
specificValue = Bytes.toString(result.getValue(Bytes.toBytes("Name"),
Bytes.toBytes("First")));
System.out.println("Latest Name:First is: " + specificValue);
specificValue = Bytes.toString(result.getValue(Bytes.toBytes("Name"),
Bytes.toBytes("Last")));
System.out.println("Latest Name:Last is: " + specificValue)
// Traverse entire returned row
System.out.println("Row key: " + row);
NavigableMap>> map = result.getMap();
for (Map.Entry>> navigableMapEntry : map.entrySet()) {
String family = Bytes.toString(navigableMapEntry.getKey());
System.out.println("\t" + family);
NavigableMap> familyContents = navigableMapEntry.getValue();
for (Map.Entry> mapEntry : familyContents.entrySet()) {
String qualifier = Bytes.toString(mapEntry.getKey());
System.out.println("\t\t" + qualifier);
NavigableMap qualifierContents = mapEntry.getValue();
for (Map.Entry entry : qualifierContents.entrySet()) {
Long timestamp = entry.getKey();
String value = Bytes.toString(entry.getValue());
System.out.printf("\t\t\t%s, %d\n", value, timestamp);
}
}
}
table.close();
}
}