@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 }
@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); }
@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); }