return new QueryNodeTemplate(queryNode, vars);
}
public static QueryNodeTemplate applyQueryToBagIndex(Bytes prefix, List query, BagIndex index, long revNum) {
Map<String, QueryNode> vars = new HashMap<String, QueryNode>();
QueryNode queryNode;
ArrayList<QueryNode> clauses;
if (query == null) {
queryNode = index.getRange(ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, ArrayBytes.EMPTY_BYTES, false, false, revNum);
} else {
int opHash = query.get(0).hashCode();
int numArgs = query.size();
switch(opHash) {
case DbServiceUtil.OP_HASH_AS:
queryNode = index.getRange(prefix, null, null, false, false, revNum);
if (query.size() > 2) {
throw new RuntimeException("Not yet supported");
// QueryNodeTemplate subNode=applyQueryToBagIndex(prefix, (List)query.get(2), index, revNum);
// vars.put((String)query.get(1), ExternalTermQueryNode.make(subNode.queryNode, queryNode));
// queryNode = subNode.queryNode;
// vars = subNode.varMappings;
} else {
vars.put((String)query.get(1), queryNode);
}
break;
case DbServiceUtil.OP_HASH_OR:
case DbServiceUtil.OP_HASH_AND:
clauses = new ArrayList<QueryNode>(numArgs-1);
for(int i=1; i<numArgs; i++) {
QueryNodeTemplate node=applyPatternToBagIndex(prefix, query.get(i), index, revNum);
if (node.queryNode != null) clauses.add(node.queryNode);
vars.putAll(node.varMappings);
}
if (opHash == DbServiceUtil.OP_HASH_OR) {
queryNode = new OrderedOrQueryNode(clauses, null, null, null, false, false);
} else {
queryNode = AndQueryNode.make(clauses);
}
break;
case DbServiceUtil.OP_HASH_NOT:
QueryNode matchesSoFar = index.getRange(prefix, null, null, false, false, revNum);
clauses = new ArrayList<QueryNode>(numArgs-1);
for(int i=1; i<numArgs; i++) {
QueryNodeTemplate node=applyPatternToBagIndex(prefix, query.get(i), index, revNum);
if (node.queryNode != null) clauses.add(node.queryNode);
}
QueryNode negativeMatches = OrderedOrQueryNode.make(clauses);
queryNode = AndNotQueryNode.make(matchesSoFar, negativeMatches);
break;
default:
Bytes term1 = null;
Bytes term2 = null;