Search in sources :

Example 91 with RexCall

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall in project druid by druid-io.

the class DoublesSketchListArgBaseOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final double[] args = new double[operands.size() - 1];
    PostAggregator inputSketchPostAgg = null;
    int operandCounter = 0;
    for (RexNode operand : operands) {
        final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operand, postAggregatorVisitor);
        if (convertedPostAgg == null) {
            if (operandCounter > 0) {
                try {
                    if (!operand.isA(SqlKind.LITERAL)) {
                        return null;
                    }
                    double arg = ((Number) RexLiteral.value(operand)).doubleValue();
                    args[operandCounter - 1] = arg;
                } catch (ClassCastException cce) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            if (operandCounter == 0) {
                inputSketchPostAgg = convertedPostAgg;
            } else {
                if (!operand.isA(SqlKind.LITERAL)) {
                    return null;
                }
            }
        }
        operandCounter++;
    }
    if (inputSketchPostAgg == null) {
        return null;
    }
    return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), inputSketchPostAgg, args);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 92 with RexCall

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall in project druid by druid-io.

the class DoublesSketchSingleArgBaseOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final PostAggregator firstOperand = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operands.get(0), postAggregatorVisitor);
    if (firstOperand == null) {
        return null;
    }
    if (!operands.get(1).isA(SqlKind.LITERAL)) {
        return null;
    }
    final float arg = ((Number) RexLiteral.value(operands.get(1))).floatValue();
    return makePostAgg(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), firstOperand, arg);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 93 with RexCall

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall in project druid by druid-io.

the class ThetaSketchSetBaseOperatorConversion method toPostAggregator.

@Nullable
@Override
public PostAggregator toPostAggregator(PlannerContext plannerContext, RowSignature rowSignature, RexNode rexNode, PostAggregatorVisitor postAggregatorVisitor) {
    final List<RexNode> operands = ((RexCall) rexNode).getOperands();
    final List<PostAggregator> inputPostAggs = new ArrayList<>();
    Integer size = null;
    int operandCounter = 0;
    for (RexNode operand : operands) {
        final PostAggregator convertedPostAgg = OperatorConversions.toPostAggregator(plannerContext, rowSignature, operand, postAggregatorVisitor);
        if (convertedPostAgg == null) {
            if (operandCounter == 0) {
                try {
                    if (!operand.isA(SqlKind.LITERAL)) {
                        return null;
                    }
                    size = RexLiteral.intValue(operand);
                } catch (ClassCastException cce) {
                    return null;
                }
            } else {
                return null;
            }
        } else {
            inputPostAggs.add(convertedPostAgg);
            operandCounter++;
        }
    }
    return new SketchSetPostAggregator(postAggregatorVisitor.getOutputNamePrefix() + postAggregatorVisitor.getAndIncrementCounter(), getSetOperationName(), size, inputPostAggs);
}
Also used : RexCall(org.apache.calcite.rex.RexCall) SketchSetPostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator) PostAggregator(org.apache.druid.query.aggregation.PostAggregator) SketchSetPostAggregator(org.apache.druid.query.aggregation.datasketches.theta.SketchSetPostAggregator) ArrayList(java.util.ArrayList) RexNode(org.apache.calcite.rex.RexNode) Nullable(javax.annotation.Nullable)

Example 94 with RexCall

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall in project hive by apache.

the class HiveCalciteUtil method getTypeSafePred.

public static RexNode getTypeSafePred(RelOptCluster cluster, RexNode rex, RelDataType rType) {
    RexNode typeSafeRex = rex;
    if ((typeSafeRex instanceof RexCall) && HiveCalciteUtil.isComparisonOp((RexCall) typeSafeRex)) {
        RexBuilder rb = cluster.getRexBuilder();
        List<RexNode> fixedPredElems = new ArrayList<RexNode>();
        RelDataType commonType = cluster.getTypeFactory().leastRestrictive(RexUtil.types(((RexCall) rex).getOperands()));
        for (RexNode rn : ((RexCall) rex).getOperands()) {
            fixedPredElems.add(rb.ensureType(commonType, rn, true));
        }
        typeSafeRex = rb.makeCall(((RexCall) typeSafeRex).getOperator(), fixedPredElems);
    }
    return typeSafeRex;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) ArrayList(java.util.ArrayList) RexBuilder(org.apache.calcite.rex.RexBuilder) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode)

Example 95 with RexCall

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall in project hive by apache.

the class HiveCalciteUtil method checkMaterializable.

/**
 * Check if the expression is usable for query materialization, returning the first failing expression.
 */
public static RexCall checkMaterializable(RexNode expr) {
    RexCall failingCall = null;
    if (expr == null) {
        return null;
    }
    RexVisitor<Void> visitor = new RexVisitorImpl<Void>(true) {

        @Override
        public Void visitCall(org.apache.calcite.rex.RexCall call) {
            // non-deterministic functions as well as runtime constants are not materializable.
            SqlOperator op = call.getOperator();
            if (!op.isDeterministic() || op.isDynamicFunction() || (op instanceof HiveSqlFunction && ((HiveSqlFunction) op).isRuntimeConstant())) {
                throw new Util.FoundOne(call);
            }
            return super.visitCall(call);
        }
    };
    try {
        expr.accept(visitor);
    } catch (Util.FoundOne e) {
        failingCall = (RexCall) e.getNode();
    }
    return failingCall;
}
Also used : RexCall(org.apache.calcite.rex.RexCall) HiveSqlFunction(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSqlFunction) SqlOperator(org.apache.calcite.sql.SqlOperator) RexUtil(org.apache.calcite.rex.RexUtil) SqlValidatorUtil(org.apache.calcite.sql.validate.SqlValidatorUtil) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Util(org.apache.calcite.util.Util) RexVisitorImpl(org.apache.calcite.rex.RexVisitorImpl)

Aggregations

RexCall (org.apache.calcite.rex.RexCall)213 RexNode (org.apache.calcite.rex.RexNode)172 RexInputRef (org.apache.calcite.rex.RexInputRef)61 ArrayList (java.util.ArrayList)60 RexLiteral (org.apache.calcite.rex.RexLiteral)44 Nullable (javax.annotation.Nullable)35 RelNode (org.apache.calcite.rel.RelNode)26 RelDataType (org.apache.calcite.rel.type.RelDataType)24 SqlOperator (org.apache.calcite.sql.SqlOperator)23 List (java.util.List)22 RexBuilder (org.apache.calcite.rex.RexBuilder)22 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)19 SqlKind (org.apache.calcite.sql.SqlKind)14 ImmutableBitSet (org.apache.calcite.util.ImmutableBitSet)14 RelOptUtil (org.apache.calcite.plan.RelOptUtil)11 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)11 RexCall (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexCall)10 RexNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode)10 RexTableInputRef (org.apache.calcite.rex.RexTableInputRef)10 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)9