HBaseStorageManager extends StorageManager { public List<IndexPredication> getIndexPredications(ColumnMapping columnMapping, TableDesc tableDesc, ScanNode scanNode) throws IOException { List<IndexPredication> indexPredications = new ArrayList<IndexPredication>(); Column[] indexableColumns = getIndexableColumns(tableDesc); if (indexableColumns != null && indexableColumns.length == 1) { List<Set<EvalNode>> indexablePredicateList = findIndexablePredicateSet(scanNode, indexableColumns); for (Set<EvalNode> eachEvalSet: indexablePredicateList) { Pair<Datum, Datum> indexPredicationValues = getIndexablePredicateValue(columnMapping, eachEvalSet); if (indexPredicationValues != null) { IndexPredication indexPredication = new IndexPredication(); indexPredication.setColumn(indexableColumns[0]); indexPredication.setColumnId(tableDesc.getLogicalSchema().getColumnId(indexableColumns[0].getQualifiedName())); indexPredication.setStartValue(indexPredicationValues.getFirst()); indexPredication.setStopValue(indexPredicationValues.getSecond()); indexPredications.add(indexPredication); } } } return indexPredications; } HBaseStorageManager(String storeType); @Override void storageInit(); @Override void closeStorageManager(); @Override void createTable(TableDesc tableDesc, boolean ifNotExists); static Configuration getHBaseConfiguration(Configuration conf, TableMeta tableMeta); static HTableDescriptor parseHTableDescriptor(TableMeta tableMeta, Schema schema); @Override void purgeTable(TableDesc tableDesc); @Override List<Fragment> getSplits(String fragmentId, TableDesc tableDesc, ScanNode scanNode); @Override Appender getAppender(OverridableConf queryContext,
                              TaskAttemptId taskAttemptId, TableMeta meta, Schema schema, Path workDir); @Override List<Fragment> getNonForwardSplit(TableDesc tableDesc, int currentPage, int numFragments); HConnection getConnection(Configuration hbaseConf); List<IndexPredication> getIndexPredications(ColumnMapping columnMapping,
                                                     TableDesc tableDesc, ScanNode scanNode); List<Set<EvalNode>> findIndexablePredicateSet(ScanNode scanNode, Column[] indexableColumns); static boolean isIndexableOperator(EvalNode expr); Pair<Datum, Datum> getIndexablePredicateValue(ColumnMapping columnMapping,
                                                       Set<EvalNode> evalNodes); @Override Path commitOutputData(OverridableConf queryContext, ExecutionBlockId finalEbId,
                               LogicalPlan plan, Schema schema,
                               TableDesc tableDesc); @Override TupleRange[] getInsertSortRanges(OverridableConf queryContext, TableDesc tableDesc,
                                          Schema inputSchema, SortSpec[] sortSpecs, TupleRange dataRange); List<LogicalPlanRewriteRule> getRewriteRules(OverridableConf queryContext, TableDesc tableDesc); @Override StorageProperty getStorageProperty(); void beforeInsertOrCATS(LogicalNode node); @Override void rollbackOutputCommit(LogicalNode node); @Override void verifyInsertTableSchema(TableDesc tableDesc, Schema outSchema);  }
@Test public void testGetIndexPredications() throws Exception { Column rowkeyColumn = new Column("rk", Type.TEXT); ScanNode scanNode = new ScanNode(1); EvalNode evalNode1 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("020"))); EvalNode evalNode2 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("055"))); EvalNode evalNodeA = new BinaryEval(EvalType.AND, evalNode1, evalNode2); scanNode.setQual(evalNodeA); HBaseStorageManager storageManager = (HBaseStorageManager) StorageManager.getStorageManager(new TajoConf(), "HBASE"); List<Set<EvalNode>> indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); assertNotNull(indexEvals); assertEquals(1, indexEvals.size()); Pair<Datum, Datum> indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); assertEquals("020", indexPredicateValue.getFirst().asChars()); assertEquals("055", indexPredicateValue.getSecond().asChars()); EvalNode evalNode3 = new BinaryEval(EvalType.EQUAL, new FieldEval(rowkeyColumn),new ConstEval(new TextDatum("075"))); EvalNode evalNodeB = new BinaryEval(EvalType.OR, evalNodeA, evalNode3); scanNode.setQual(evalNodeB); indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); assertEquals(2, indexEvals.size()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); assertEquals("020", indexPredicateValue.getFirst().asChars()); assertEquals("055", indexPredicateValue.getSecond().asChars()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); assertEquals("075", indexPredicateValue.getFirst().asChars()); assertEquals("075", indexPredicateValue.getSecond().asChars()); EvalNode evalNode4 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("072"))); EvalNode evalNode5 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("078"))); EvalNode evalNodeC = new BinaryEval(EvalType.AND, evalNode4, evalNode5); EvalNode evalNodeD = new BinaryEval(EvalType.OR, evalNodeA, evalNodeC); scanNode.setQual(evalNodeD); indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); assertEquals(2, indexEvals.size()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); assertEquals("020", indexPredicateValue.getFirst().asChars()); assertEquals("055", indexPredicateValue.getSecond().asChars()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); assertEquals("072", indexPredicateValue.getFirst().asChars()); assertEquals("078", indexPredicateValue.getSecond().asChars()); evalNode4 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("072"))); evalNode5 = new BinaryEval(EvalType.LEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("078"))); evalNodeC = new BinaryEval(EvalType.AND, evalNode4, evalNode5); EvalNode evalNode6 = new BinaryEval(EvalType.GEQ, new FieldEval(rowkeyColumn), new ConstEval(new TextDatum("073"))); evalNodeD = new BinaryEval(EvalType.AND, evalNodeC, evalNode6); EvalNode evalNodeE = new BinaryEval(EvalType.OR, evalNodeA, evalNodeD); scanNode.setQual(evalNodeE); indexEvals = storageManager.findIndexablePredicateSet(scanNode, new Column[]{rowkeyColumn}); assertEquals(2, indexEvals.size()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(0)); assertEquals("020", indexPredicateValue.getFirst().asChars()); assertEquals("055", indexPredicateValue.getSecond().asChars()); indexPredicateValue = storageManager.getIndexablePredicateValue(null, indexEvals.get(1)); assertEquals("073", indexPredicateValue.getFirst().asChars()); assertEquals("078", indexPredicateValue.getSecond().asChars()); }