if (result.isEmpty()) { for(ExpressionTree kid: kids) { ExpressionTree or = new ExpressionTree(ExpressionTree.Operator.OR); result.add(or); for(ExpressionTree node: nonAndList) { or.children.add(new ExpressionTree(node)); for(ExpressionTree kid: kids) { for(ExpressionTree or: work) { ExpressionTree copy = new ExpressionTree(or); copy.children.add(kid); result.add(copy);
return new ExpressionTree(TruthValue.YES_NO_NULL); result = new ExpressionTree(ExpressionTree.Operator.OR); addChildren(result, expr, leafCache); } else if (op == GenericUDFOPAnd.class) { result = new ExpressionTree(ExpressionTree.Operator.AND); addChildren(result, expr, leafCache); } else if (op == GenericUDFOPNot.class) { result = new ExpressionTree(ExpressionTree.Operator.NOT); addChildren(result, expr, leafCache); } else if (op == GenericUDFOPEqual.class) { result = new ExpressionTree(TruthValue.YES_NO_NULL);
String columnName = getColumnName(expression, variable); if (columnName == null) { return new ExpressionTree(TruthValue.YES_NO_NULL); return new ExpressionTree(TruthValue.YES_NO_NULL); literalList = getLiteralList(expression, variable + 1); if (literalList == null) { return new ExpressionTree(TruthValue.YES_NO_NULL); literal = getLiteral(expression); if (literal == null) { return new ExpressionTree(TruthValue.YES_NO_NULL); ExpressionTree result = new ExpressionTree(leafCache.size() - 1); if (needSwap) { result = negate(result);
root = new ExpressionTree(ExpressionTree.Operator.AND); generateAllCombinations(root.children, andList, nonAndList); } else { root = new ExpressionTree(TruthValue.YES_NO_NULL);
for(ExpressionTree child: children) { if (p == null) { p = child.translate(leafs); } else { FilterPredicate right = child.translate(leafs); for(ExpressionTree child: children) { if (p == null) { p = child.translate(leafs); } else { FilterPredicate right = child.translate(leafs); FilterPredicate op = children.get(0).translate(leafs); if (op != null) { return FilterApi.not(op); return buildFilterPredicateFromPredicateLeaf(leafs.get(leaf)); case CONSTANT: return null;// no filter will be executed for constant
return pushDownNot(child.children.get(0)); case CONSTANT: return new ExpressionTree(child.constant.not()); case AND: root = new ExpressionTree(ExpressionTree.Operator.OR); for(ExpressionTree kid: child.children) { root.children.add(pushDownNot(new ExpressionTree(ExpressionTree.Operator.NOT, kid))); root = new ExpressionTree(ExpressionTree.Operator.AND); for(ExpressionTree kid: child.children) { root.children.add(pushDownNot(new ExpressionTree (ExpressionTree.Operator.NOT, kid)));
return new ExpressionTree(TruthValue.YES_NO_NULL);
/** * Iterates through the expression, finding all of the leaves. It creates * the leaves list with each unique leaf that is found in the expression. * The expression is updated with the new leaf ids for each leaf. * @param expr the expression to find the leaves in * @param leafCache the list of all of the leaves * @param lookup a map that is used to uniquify the leaves * @return The potentially modified expression */ private ExpressionTree buildLeafList(ExpressionTree expr, List<PredicateLeaf> leafCache, Map<PredicateLeaf, ExpressionTree> lookup) { if (expr.children != null) { for(int i=0; i < expr.children.size(); ++i) { expr.children.set(i, buildLeafList(expr.children.get(i), leafCache, lookup)); } } else if (expr.operator == ExpressionTree.Operator.LEAF) { PredicateLeaf leaf = leafCache.get(expr.leaf); ExpressionTree val = lookup.get(leaf); if (val == null) { val = new ExpressionTree(leaves.size()); lookup.put(leaf, val); leaves.add(leaf); } return val; } return expr; }
private FilterPredicate buildFilterPredicateFromPredicateLeaf(PredicateLeaf leaf) { LeafFilterFactory leafFilterFactory = new LeafFilterFactory(); FilterPredicateLeafBuilder builder; try { builder = leafFilterFactory .getLeafFilterBuilderByType(leaf.getType()); if (builder == null) { return null; } if (isMultiLiteralsOperator(leaf.getOperator())) { return builder.buildPredicate(leaf.getOperator(), leaf.getLiteralList(), leaf.getColumnName()); } else { return builder .buildPredict(leaf.getOperator(), leaf.getLiteral(), leaf.getColumnName()); } } catch (Exception e) { LOG.error("fail to build predicate filter leaf with errors" + e, e); return null; } }
TruthValue evaluate(TruthValue[] leaves) { TruthValue result = null; switch (operator) { case OR: for(ExpressionTree child: children) { result = child.evaluate(leaves).or(result); } return result; case AND: for(ExpressionTree child: children) { result = child.evaluate(leaves).and(result); } return result; case NOT: return children.get(0).evaluate(leaves).not(); case LEAF: return leaves[leaf]; case CONSTANT: return constant; default: throw new IllegalStateException("Unknown operator: " + operator); } }
@Override public Builder in(String column, Object... literal) { ExpressionTree parent = currentTree.getFirst(); if (literal.length == 0) { throw new IllegalArgumentException("Can't create in expression with " + "no arguments"); } List<Object> argList = new ArrayList<Object>(); for(Object lit: literal){ argList.add(boxLiteral(lit)); } PredicateLeaf leaf = new PredicateLeafImpl(PredicateLeaf.Operator.IN, getType(argList.get(0)), column, null, argList); leaves.add(leaf); parent.children.add(new ExpressionTree(leaves.size() - 1)); return this; }
ExpressionTree(ExpressionTree other) { this.operator = other.operator; if (other.children == null) { this.children = null; } else { this.children = new ArrayList<ExpressionTree>(); for(ExpressionTree child: other.children) { children.add(new ExpressionTree(child)); } } this.leaf = other.leaf; this.constant = other.constant; }
@Override public Builder between(String column, Object lower, Object upper) { ExpressionTree parent = currentTree.getFirst(); List<Object> argList = new ArrayList<Object>(); argList.add(boxLiteral(lower)); argList.add(boxLiteral(upper)); PredicateLeaf leaf = new PredicateLeafImpl(PredicateLeaf.Operator.BETWEEN, getType(argList.get(0)), column, null, argList); leaves.add(leaf); parent.children.add(new ExpressionTree(leaves.size() - 1)); return this; }
@Override public TruthValue evaluate(TruthValue[] leaves) { return expression == null ? TruthValue.YES : expression.evaluate(leaves); }
@Override public Builder lessThan(String column, Object literal) { ExpressionTree parent = currentTree.getFirst(); Object box = boxLiteral(literal); PredicateLeaf leaf = new PredicateLeafImpl(PredicateLeaf.Operator.LESS_THAN, getType(box), column, box, null); leaves.add(leaf); parent.children.add(new ExpressionTree(leaves.size() - 1)); return this; }
@Override public Builder startNot() { ExpressionTree node = new ExpressionTree(ExpressionTree.Operator.NOT); if (currentTree.size() != 0) { ExpressionTree parent = currentTree.getFirst(); parent.children.add(node); } currentTree.addFirst(node); return this; }
@Override public FilterPredicate toFilterPredicate() { return expression.translate(leaves); }
@Override public Builder equals(String column, Object literal) { ExpressionTree parent = currentTree.getFirst(); Object box = boxLiteral(literal); PredicateLeaf leaf = new PredicateLeafImpl(PredicateLeaf.Operator.EQUALS, getType(box), column, box, null); leaves.add(leaf); parent.children.add(new ExpressionTree(leaves.size() - 1)); return this; }
@Override public Builder startAnd() { ExpressionTree node = new ExpressionTree(ExpressionTree.Operator.AND); if (currentTree.size() != 0) { ExpressionTree parent = currentTree.getFirst(); parent.children.add(node); } currentTree.addFirst(node); return this; }