Github user nonstop-qfchen commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/255#discussion_r49484458
--- Diff: core/sql/src/main/java/org/trafodion/sql/HTableClient.java ---
@@ -358,6 +365,417 @@ void resetAutoFlush() {
table.setAutoFlush(true, true);
}
+ private enum Op {
+ EQUAL, EQUAL_NULL, NOT_EQUAL, NOT_EQUAL_NULL, LESS, LESS_NULL,
LESS_OR_EQUAL, LESS_OR_EQUAL_NULL, GREATER, GREATER_NULL,
+ GREATER_OR_EQUAL, GREATER_OR_EQUAL_NULL, NO_OP,
NO_OP_NULL,IS_NULL, IS_NULL_NULL, IS_NOT_NULL, IS_NOT_NULL_NULL, AND, OR};
+
+ private Filter SingleColumnValueExcludeOrNotFilter(byte[]
columnToFilter,
+
CompareOp op,
+
ByteArrayComparable comparator,
+
HashMap<String,Object> columnsToRemove,
+
Boolean... filterIfMissing){
+ Filter result;
+ boolean fMissing =
filterIfMissing.length>0?filterIfMissing[0]:false;//default to false
+ if ((columnsToRemove == null) ||
!columnsToRemove.containsKey(new String(columnToFilter))){
+ result = new
SingleColumnValueFilter(getFamily(columnToFilter), getName(columnToFilter), op,
comparator);
+
((SingleColumnValueFilter)result).setFilterIfMissing(fMissing);
+ }
+ else{
+ result= new
SingleColumnValueExcludeFilter(getFamily(columnToFilter),
getName(columnToFilter), op, comparator);
+
((SingleColumnValueExcludeFilter)result).setFilterIfMissing(fMissing);
+ }
+ return result;
+ }
+
+ // construct the hbase filter
+ // optimizes for OR and AND associativity
+ // optimizes for detection of a<? and a>? on nullable and non nullable
column equivalent to a<>?
+ // optimize for null check factorization (A not null and (A <op> ?)) or
(A not null and A <op2> ?) -> A not null and (A <op> ? or A <op2> ?)
+ // this is an important optimzation for IN statement on
non null column
+ // uses the columnToRemove parametter to know if we need to use the
SingleColumnValue Exclude or not method to limit returned columns
+
+ private Filter constructV2Filter(Object[] colNamesToFilter,
+ Object[] compareOpList,
+ Object[] colValuesToCompare,
+ HashMap<String,Object> columnsToRemove){
+ LinkedList linkedList = new LinkedList();
+ //populate the list with nodes in reverse polish notation order.
+ int k=0;//column index
+ int kk=0;//value index
+ for (int i=1; i<compareOpList.length; i++){ // skip first one
containing "V2" marker
+ String opStr = new String((byte[])compareOpList[i]);
+ switch(Op.valueOf(opStr)){
+
+ case EQUAL:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove
+ ));
+ k++;kk++;
+ break;
+ case EQUAL_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+
new BinaryPrefixComparator(new byte[]{0x00}),//check for null
indicator = 0 representing non null
+
columnsToRemove,
+
true //filterIfMissing
+
),
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+
new BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case NOT_EQUAL:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.NOT_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case NOT_EQUAL_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.NOT_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case LESS:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.LESS,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case LESS_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.LESS,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case LESS_OR_EQUAL:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.LESS_OR_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case LESS_OR_EQUAL_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.LESS_OR_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case GREATER:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.GREATER,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case GREATER_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.GREATER,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case GREATER_OR_EQUAL:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.GREATER_OR_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case GREATER_OR_EQUAL_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.GREATER_OR_EQUAL,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case NO_OP:
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.NO_OP,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+ columnsToRemove));
+ k++;kk++;
+ break;
+ case NO_OP_NULL:
+ linkedList.addLast(new
FilterList(FilterList.Operator.MUST_PASS_ALL, //AND between if not null and the
actual
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+ new
BinaryPrefixComparator(new byte[]{0x00}),//check for null indicator = 0
representing non null
+
columnsToRemove,
+ true),
//filterIfMissing,
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.NO_OP,
+ new
BinaryComparator((byte[])colValuesToCompare[kk]),
+
columnsToRemove)));
+ k++;kk++;
+ break;
+ case IS_NULL:
+ // is null on a non nullable column!
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.NO_OP,
//exclude everything
+ new
BinaryPrefixComparator((new byte[]{})),
+ columnsToRemove));
+ k++;
+ break;
+ case IS_NULL_NULL:
+ // is_null on nullable column: is
absent OR has the first byte set to FF indicating NULL.
+ linkedList.addLast(
+ new
FilterList(FilterList.Operator.MUST_PASS_ONE, //OR
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+
new NullComparator(),//is absent?
+
columnsToRemove),
+
SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+
CompareOp.EQUAL,
+
new BinaryPrefixComparator(new byte[]{-1}),//0xFF has null prefix
indicator
+
columnsToRemove)));
+ k++;
+ break;
+ case IS_NOT_NULL:
+ // is not null on a non nullable column!
+ // do nothing, always true
+ k++;
+ break;
+ case IS_NOT_NULL_NULL:
+ // is_not_null on nullable column: is
not absent AND has the first byte not set to FF indicating NULL.
+
linkedList.addLast(SingleColumnValueExcludeOrNotFilter(
+
(byte[])colNamesToFilter[k],
+ CompareOp.NOT_EQUAL,
+ new
BinaryPrefixComparator(new byte[]{-1}),// 0xFF has null prefix indicator
+ columnsToRemove,
+ true));//filter if
missing (if absent null)
+ k++;
+ break;
+ case AND:
+ linkedList.addLast("AND");
+ break;
+ case OR:
+ linkedList.addLast("OR");
+ break;
+ default:
+ }//switch
+ }//for
--- End diff --
This for loop just puts items in reverse order. Where do we do the
in-order traversal? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at [email protected] or file a JIRA ticket with INFRA. ---
