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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations