本文整理汇总了Java中org.apache.hadoop.hbase.index.client.IndexUtils类的典型用法代码示例。如果您正苦于以下问题:Java IndexUtils类的具体用法?Java IndexUtils怎么用?Java IndexUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IndexUtils类属于org.apache.hadoop.hbase.index.client包,在下文中一共展示了IndexUtils类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleIndexExpressionWithOneEqualsExpression
import org.apache.hadoop.hbase.index.client.IndexUtils; //导入依赖的package包/类
@Test
public void testSingleIndexExpressionWithOneEqualsExpression() throws Exception {
String indexName = "idx1";
SingleIndexExpression singleIndexExpression = new SingleIndexExpression(indexName);
byte[] value = "1".getBytes();
Column column = new Column(FAMILY1, QUALIFIER1);
EqualsExpression equalsExpression = new EqualsExpression(column, value);
singleIndexExpression.addEqualsExpression(equalsExpression);
Scan scan = new Scan();
scan.setAttribute(Constants.INDEX_EXPRESSION, IndexUtils.toBytes(singleIndexExpression));
Filter filter = new SingleColumnValueFilter(FAMILY1, QUALIFIER1, CompareOp.EQUAL, value);
scan.setFilter(filter);
ScanFilterEvaluator evaluator = new ScanFilterEvaluator();
List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
IndexSpecification index = new IndexSpecification(indexName);
HColumnDescriptor colDesc = new HColumnDescriptor(FAMILY1);
index.addIndexColumn(colDesc, COL1, ValueType.String, 10);
indices.add(index);
HRegion region =
initHRegion(tableName.getBytes(), null, null,
"testSingleIndexExpressionWithOneEqualsExpression", TEST_UTIL.getConfiguration(), FAMILY1);
IndexRegionScanner scanner = evaluator.evaluate(scan, indices, new byte[0], region, tableName);
// TODO add assertions
}
示例2: testNoIndexExpression
import org.apache.hadoop.hbase.index.client.IndexUtils; //导入依赖的package包/类
@Test
public void testNoIndexExpression() throws Exception {
IndexExpression exp = new NoIndexExpression();
Scan scan = new Scan();
scan.setAttribute(Constants.INDEX_EXPRESSION, IndexUtils.toBytes(exp));
byte[] value1 = Bytes.toBytes("asdf");
scan.setFilter(new SingleColumnValueFilter(FAMILY1, QUALIFIER1, CompareOp.EQUAL, value1));
List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
IndexSpecification is1 = new IndexSpecification("idx1");
HColumnDescriptor colDesc = new HColumnDescriptor(FAMILY1);
is1.addIndexColumn(colDesc, COL1, ValueType.String, 15);
indices.add(is1);
ScanFilterEvaluator evaluator = new ScanFilterEvaluator();
HRegion region =
initHRegion(tableName.getBytes(), null, null, "testNoIndexExpression",
TEST_UTIL.getConfiguration(), FAMILY1);
IndexRegionScanner scanner = evaluator.evaluate(scan, indices, new byte[0], region, tableName);
assertNull(scanner);
}
示例3: testSingleColumnValuePartitionFilterBySettingAsAttributeToScan
import org.apache.hadoop.hbase.index.client.IndexUtils; //导入依赖的package包/类
@Test(timeout = 180000)
public void testSingleColumnValuePartitionFilterBySettingAsAttributeToScan() throws Exception {
Configuration conf = UTIL.getConfiguration();
String userTableName = "testSingleColumnValuePartitionFilterBySettingAsAttributeToScan";
HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
TableIndices indices = new TableIndices();
HColumnDescriptor hcd = new HColumnDescriptor("cf1");
ihtd.addFamily(hcd);
ValuePartition vp = new SeparatorPartition("_", 3);
IndexSpecification iSpec = new IndexSpecification("idx1");
iSpec.addIndexColumn(hcd, "cq", vp, ValueType.String, 200);
indices.addIndex(iSpec);
ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());
admin.createTable(ihtd);
HTable table = new HTable(conf, userTableName);
byte[] value1 = "2ndFloor_solitaire_huawei_bangalore_karnataka".getBytes();
Put p = new Put("row".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(), value1);
table.put(p);
p = new Put("row2".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(),
"7thFloor_solitaire_huawei_bangalore_karnataka".getBytes());
table.put(p);
p = new Put("row3".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(), "rrr_sss_hhh_bangalore_karnataka".getBytes());
table.put(p);
Scan scan = new Scan();
SingleIndexExpression singleIndexExpression = new SingleIndexExpression("idx1");
byte[] value = "huawei".getBytes();
Column column = new Column("cf1".getBytes(), "cq".getBytes(), vp);
EqualsExpression equalsExpression = new EqualsExpression(column, value);
singleIndexExpression.addEqualsExpression(equalsExpression);
scan.setAttribute(Constants.INDEX_EXPRESSION, IndexUtils.toBytes(singleIndexExpression));
scan.setFilter(new SingleColumnValuePartitionFilter(hcd.getName(), "cq".getBytes(),
CompareOp.EQUAL, "huawei".getBytes(), vp));
int i = 0;
ResultScanner scanner = table.getScanner(scan);
List<Result> testRes = new ArrayList<Result>();
Result[] result = scanner.next(1);
while (result != null && result.length > 0) {
testRes.add(result[0]);
i++;
result = scanner.next(1);
}
assertTrue("Index flow should get used.", IndexRegionObserver.getIndexedFlowUsed());
assertTrue("Seekpoints should get added by index scanner",
IndexRegionObserver.getSeekpointAdded());
assertEquals("It should get two seek points from index scanner.", 2, IndexRegionObserver
.getMultipleSeekPoints().size());
assertTrue("Overall result should have only 2 rows", testRes.size() == 2);
}
示例4: testSingleColumnValuePartitionFilterBySettingAsAttributeToScan
import org.apache.hadoop.hbase.index.client.IndexUtils; //导入依赖的package包/类
@Test(timeout = 180000)
public void testSingleColumnValuePartitionFilterBySettingAsAttributeToScan() throws Exception {
HBaseAdmin admin = UTIL.getHBaseAdmin();
Configuration conf = UTIL.getConfiguration();
String userTableName = "testSingleColumnValuePartitionFilterBySettingAsAttributeToScan";
IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
HColumnDescriptor hcd = new HColumnDescriptor("cf1");
ihtd.addFamily(hcd);
ValuePartition vp = new SeparatorPartition("_", 3);
IndexSpecification iSpec = new IndexSpecification("idx1");
iSpec.addIndexColumn(hcd, "cq", vp, ValueType.String, 200);
ihtd.addIndex(iSpec);
admin.createTable(ihtd);
HTable table = new HTable(conf, userTableName);
byte[] value1 = "2ndFloor_solitaire_huawei_bangalore_karnataka".getBytes();
Put p = new Put("row".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(), value1);
table.put(p);
p = new Put("row2".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(),
"7thFloor_solitaire_huawei_bangalore_karnataka".getBytes());
table.put(p);
p = new Put("row3".getBytes());
p.add("cf1".getBytes(), "cq".getBytes(), "rrr_sss_hhh_bangalore_karnataka".getBytes());
table.put(p);
Scan scan = new Scan();
SingleIndexExpression singleIndexExpression = new SingleIndexExpression("idx1");
byte[] value = "huawei".getBytes();
Column column = new Column("cf1".getBytes(), "cq".getBytes(), vp);
EqualsExpression equalsExpression = new EqualsExpression(column, value);
singleIndexExpression.addEqualsExpression(equalsExpression);
scan.setAttribute(Constants.INDEX_EXPRESSION, IndexUtils.toBytes(singleIndexExpression));
scan.setFilter(new SingleColumnValuePartitionFilter(hcd.getName(), "cq".getBytes(),
CompareOp.EQUAL, "huawei".getBytes(), vp));
int i = 0;
ResultScanner scanner = table.getScanner(scan);
List<Result> testRes = new ArrayList<Result>();
Result[] result = scanner.next(1);
while (result != null && result.length > 0) {
testRes.add(result[0]);
i++;
result = scanner.next(1);
}
Assert.assertTrue("Index flow should get used.", IndexRegionObserver.getIndexedFlowUsed());
Assert.assertTrue("Seekpoints should get added by index scanner",
IndexRegionObserver.getSeekpointAdded());
Assert.assertEquals("It should get two seek points from index scanner.", 2, IndexRegionObserver
.getMultipleSeekPoints().size());
Assert.assertTrue("Overall result should have only 2 rows", testRes.size() == 2);
}