@Override public LogicalExpression visitBooleanOperator(BooleanOperator op, Void value) throws RuntimeException { List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.addAll(op.args); Collections.sort(newArgs, costComparator); return new BooleanOperator(op.getName(), newArgs, op.getPosition()); }
@Override public int getCumulativeCost() { // return the average cost of operands for a boolean "and" | "or" int cost = this.getSelfCost(); int i = 0; for (LogicalExpression e : this) { cost += e.getCumulativeCost(); i++; } return cost / i; }
@Override public LogicalExpression visitBooleanOperator(BooleanOperator op, Set<LogicalExpression> value) { List<LogicalExpression> childPredicates = new ArrayList<>(); String functionName = op.getName(); for (LogicalExpression arg : op.args) { LogicalExpression childPredicate = arg.accept(this, value); if (childPredicate == null) { if (functionName.equals("booleanOr") || !omitUnsupportedExprs) { // we can't include any leg of the OR if any of the predicates cannot be converted // or prohibited omitting of unconverted operands return null; } } else { if (childPredicate instanceof TypedFieldExpr) { // Calcite simplifies `= true` expression to field name, wrap it with is true predicate childPredicate = ParquetIsPredicate.createIsPredicate(FunctionGenerationHelper.IS_TRUE, childPredicate); } childPredicates.add(childPredicate); } } if (childPredicates.size() == 0) { return null; // none leg is qualified, return null. } else if (childPredicates.size() == 1) { return childPredicates.get(0); // only one leg is qualified, remove boolean op. } else { return ParquetBooleanPredicate.createBooleanPredicate(functionName, op.getName(), childPredicates, op.getPosition()); } }
public static LogicalExpression createBooleanOperator(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ return new BooleanOperator(replaceOpWithFuncName(functionName), args, ep); }
private ValueHolder visitBooleanOr(BooleanOperator op, Integer inIndex) { ValueHolder [] args = new ValueHolder [op.args.size()]; boolean hasNull = false; for (int i = 0; i < op.args.size(); i++) { args[i] = op.args.get(i).accept(this, inIndex); Trivalent flag = isBitOn(args[i]); switch (flag) { case TRUE: return op.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL? TypeHelper.nullify(ValueHolderHelper.getBitHolder(1)) : ValueHolderHelper.getBitHolder(1); case NULL: hasNull = true; case FALSE: } } if (hasNull) { return ValueHolderHelper.getNullableBitHolder(true, 0); } else { return op.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL? TypeHelper.nullify(ValueHolderHelper.getBitHolder(0)) : ValueHolderHelper.getBitHolder(0); } }
@Override public Void visitBooleanOperator(BooleanOperator op, ErrorCollector errors) throws RuntimeException { int i = 0; for (LogicalExpression arg : op.args) { if ( arg.getMajorType().getMinorType() != MinorType.BIT) { errors .addGeneralError( arg.getPosition(), String .format( "Failure composing boolean operator %s. All conditions must return a boolean type. Condition %d was of Type %s.", op.getName(), i, arg.getMajorType().getMinorType())); } i++; } return null; }
public static LogicalExpression createExpression(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ String name = replaceOpWithFuncName(functionName); if (isBooleanOperator(name)) { return new BooleanOperator(name, args, ep); } else { return new FunctionCall(name, args, ep); } }
private ValueHolder visitBooleanAnd(BooleanOperator op, Integer inIndex) { ValueHolder [] args = new ValueHolder [op.args.size()]; boolean hasNull = false; for (int i = 0; i < op.args.size(); i++) { args[i] = op.args.get(i).accept(this, inIndex); Trivalent flag = isBitOn(args[i]); switch (flag) { case FALSE: return op.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL? TypeHelper.nullify(ValueHolderHelper.getBitHolder(0)) : ValueHolderHelper.getBitHolder(0); case NULL: hasNull = true; case TRUE: } } if (hasNull) { return ValueHolderHelper.getNullableBitHolder(true, 0); } else { return op.getMajorType().getMode() == TypeProtos.DataMode.OPTIONAL? TypeHelper.nullify(ValueHolderHelper.getBitHolder(1)) : ValueHolderHelper.getBitHolder(1); } }
@Override public LogicalExpression visitBooleanOperator(BooleanOperator op, Void value) throws RuntimeException { List<LogicalExpression> newArgs = Lists.newArrayList(); newArgs.addAll(op.args); Collections.sort(newArgs, costComparator); return new BooleanOperator(op.getName(), newArgs, op.getPosition()); }
public static LogicalExpression createBooleanOperator(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ return new BooleanOperator(replaceOpWithFuncName(functionName), args, ep); }
private HoldingContainer visitBooleanOr(BooleanOperator op, ClassGenerator<?> generator) { HoldingContainer out = generator.declare(op.getMajorType());
@Override public int getCumulativeCost() { // return the average cost of operands for a boolean "and" | "or" int cost = this.getSelfCost(); int i = 0; for (LogicalExpression e : this) { cost += e.getCumulativeCost(); i++; } return cost / i; }
@Override public LogicalExpression visitBooleanOperator(BooleanOperator op, FunctionLookupContext functionLookupContext) { List<LogicalExpression> args = Lists.newArrayList(); for (int i = 0; i < op.args.size(); ++i) { LogicalExpression newExpr = op.args.get(i).accept(this, functionLookupContext); assert newExpr != null : String.format("Materialization of %s return a null expression.", op.args.get(i)); args.add(newExpr); } //replace with a new function call, since its argument could be changed. return new BooleanOperator(op.getName(), args, op.getPosition()); }
@Override public ValueHolder visitBooleanOperator(BooleanOperator op, Integer inIndex) { // Apply short circuit evaluation to boolean operator. if (op.getName().equals("booleanAnd")) { return visitBooleanAnd(op, inIndex); }else if(op.getName().equals("booleanOr")) { return visitBooleanOr(op, inIndex); } else { throw new UnsupportedOperationException("BooleanOperator can only be booleanAnd, booleanOr. You are using " + op.getName()); } }
public static LogicalExpression createExpression(String functionName, ExpressionPosition ep, List<LogicalExpression> args){ String name = replaceOpWithFuncName(functionName); if (isBooleanOperator(name)) { return new BooleanOperator(name, args, ep); } else { return new FunctionCall(name, args, ep); } }
private HoldingContainer visitBooleanAnd(BooleanOperator op, ClassGenerator<?> generator) { HoldingContainer out = generator.declare(op.getMajorType());
@Override public HoldingContainer visitBooleanOperator(BooleanOperator op, ClassGenerator<?> generator) throws RuntimeException { if (op.getName().equals("booleanAnd")) { return visitBooleanAnd(op, generator); } else if(op.getName().equals("booleanOr")) { return visitBooleanOr(op, generator); } else { throw new UnsupportedOperationException("BooleanOperator can only be booleanAnd, booleanOr. You are using " + op.getName()); } }
@Override public Void visitBooleanOperator(BooleanOperator op, ErrorCollector errors) throws RuntimeException { int i = 0; for (LogicalExpression arg : op.args) { if ( arg.getMajorType().getMinorType() != MinorType.BIT) { errors .addGeneralError( arg.getPosition(), String .format( "Failure composing boolean operator %s. All conditions must return a boolean type. Condition %d was of Type %s.", op.getName(), i, arg.getMajorType().getMinorType())); } i++; } return null; }