本文整理匯總了Java中org.apache.hadoop.hbase.client.Increment.setTimeRange方法的典型用法代碼示例。如果您正苦於以下問題:Java Increment.setTimeRange方法的具體用法?Java Increment.setTimeRange怎麽用?Java Increment.setTimeRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hbase.client.Increment
的用法示例。
在下文中一共展示了Increment.setTimeRange方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testIncrementTimeRange
import org.apache.hadoop.hbase.client.Increment; //導入方法依賴的package包/類
@Test
public void testIncrementTimeRange() throws IOException {
byte[] rowKey = dataHelper.randomData("rk1-");
Increment incr = new Increment(rowKey);
incr.setTimeRange(0, 10);
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Setting the time range in an Increment is not implemented");
incrementAdapter.adapt(incr);
}
示例2: testIncrementWithTimerange
import org.apache.hadoop.hbase.client.Increment; //導入方法依賴的package包/類
/**
* Requirement 6.2 - Specify a timerange (min ts, inclusive + max ts, exclusive). This will create
* a new value that is an increment of the first value within this range, and will otherwise
* create a new value.
* Note: This is pretty weird. Not sure who would use it, or if we need to support it.
* Here's the test: 1. Create a cell with three explicit versions: 101, 102, and 103. The values
* are set to the same so we can track the original versions. 2. Call an increment (+1) with a
* time range of [101,103) 3. It should have created a fourth version with the current timestamp
* that incremented version 102. We can ensure this be looking at the new value (103) and the
* number of versions. 4. Now increment (+1) with a time range outside of all versions [100000,
* 200000) 5. It should have create a new version with the current timestamp and value of 1. 6.
* Check all versions for the cell. You should have, in descending version order: a. A value of 1
* with a recent timestamp. b. A value of 103 with a recent timestamp. c. A value of 103 with a
* timestamp of 103. d. A value of 102 with a timestamp of 102. e. A value of 101 with a timestamp
* of 101.
*/
@Test
@Category(KnownGap.class)
public void testIncrementWithTimerange() throws IOException {
// Initialize data
Table table = getConnection().getTable(TABLE_NAME);
byte[] rowKey = dataHelper.randomData("testrow-");
byte[] qual = dataHelper.randomData("qual-");
// Put and increment in range. Test min is inclusive, max is exclusive.
Put put = new Put(rowKey).addColumn(COLUMN_FAMILY, qual, 101L, Bytes.toBytes(101L))
.addColumn(COLUMN_FAMILY, qual, 102L, Bytes.toBytes(102L))
.addColumn(COLUMN_FAMILY, qual, 103L, Bytes.toBytes(103L));
table.put(put);
// Increment doesn't increment in place.
Increment increment = new Increment(rowKey);
increment.setTimeRange(101L, 103L);
increment.addColumn(COLUMN_FAMILY, qual, 1L);
Result result = table.increment(increment);
Assert.assertEquals("Should increment only 1 value", 1, result.size());
Assert.assertEquals("It should have incremented 102", 102L + 1L,
Bytes.toLong(CellUtil.cloneValue(result.getColumnLatestCell(COLUMN_FAMILY, qual))));
Get get = new Get(rowKey).setMaxVersions(10);
result = table.get(get);
Assert.assertEquals("Check there's now a fourth", 4, result.size());
// Test an increment out of range
increment = new Increment(rowKey).addColumn(COLUMN_FAMILY, qual, 1L)
.setTimeRange(100000L, 200000L);
result = table.increment(increment);
Assert.assertEquals("Expect single value", 1, result.size());
Assert.assertTrue("Timestamp should be new",
result.getColumnLatestCell(COLUMN_FAMILY, qual).getTimestamp() > 1000000000000L);
// Check values
get = new Get(rowKey);
get.setMaxVersions(10);
result = table.get(get);
List<Cell> cells = result.getColumnCells(COLUMN_FAMILY, qual);
Assert.assertEquals("Expected five results", 5, cells.size());
Assert.assertTrue("First should be a default timestamp",
cells.get(0).getTimestamp() > 1000000000000L);
Assert.assertEquals("Value should be new", 1L,
Bytes.toLong(CellUtil.cloneValue(cells.get(0))));
Assert.assertTrue("Second should also be a default timestamp",
cells.get(1).getTimestamp() > 1000000000000L);
Assert.assertEquals("Value should be an increment of 102", 102L + 1L,
Bytes.toLong(CellUtil.cloneValue(cells.get(1))));
Assert.assertEquals("Third should be 103", 103L, cells.get(2).getTimestamp());
Assert.assertEquals("103 should still be 103", 103L,
Bytes.toLong(CellUtil.cloneValue(cells.get(2))));
Assert.assertEquals("Fourth should be 102", 102L, cells.get(3).getTimestamp());
Assert.assertEquals("102 should still be 101", 102L,
Bytes.toLong(CellUtil.cloneValue(cells.get(3))));
Assert.assertEquals("Last should be 101", 101L, cells.get(4).getTimestamp());
Assert.assertEquals("101 should still be 101", 101L,
Bytes.toLong(CellUtil.cloneValue(cells.get(4))));
table.close();
}