Hbase:Javaからの利用(Timestampの実験)

出典: LunaBiblos

Software > DataBase > KeyValueストア > Hbaseの利用 > Hbase:Javaからの利用(Timestampの実験)

目次

概要

Hbaseは値を取得する際にTimestampを指定する事が出来ますが、そのTimestampの指定の仕方を色々変えて実験してみました。

利用Data

ValueTimestamp
ts20002000
ts15001500
ts10001000

Test Code

Timestamp指定なし

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = ts2000

1500を指定

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")).setTimeStamp(1500));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = ts1500

1200を指定

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")).setTimeStamp(1200));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = null

0~1200を範囲指定

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")).setTimeRange(0, 1200));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = ts1000

0~1500を範囲指定

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")).setTimeRange(0, 1500));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = ts1000

0~1501を範囲指定

HTable hTable = new HTable(this.conf, "TS_TEST");
Result r = this.hTable.get(new Get(Bytes.toBytes("1")).setTimeRange(0, 1501));
byte[] value = r.getValue(Bytes.toBytes("CF1"), Bytes.toBytes("C1"));
System.out.println("Value = " + Bytes.toString(value));

結果 Value = ts1500