use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project storm by apache.
the class TridentFilterRel method tridentPlan.
@Override
public void tridentPlan(TridentPlanCreator planCreator) throws Exception {
// SingleRel
RelNode input = getInput();
StormRelUtils.getStormRelInput(input).tridentPlan(planCreator);
Stream inputStream = planCreator.pop().toStream();
String stageName = StormRelUtils.getStageName(this);
List<RexNode> childExps = getChildExps();
RelDataType inputRowType = getInput(0).getRowType();
String filterClassName = StormRelUtils.getClassName(this);
ExecutableExpression filterInstance = planCreator.createScalarInstance(childExps, inputRowType, filterClassName);
IAggregatableStream finalStream = inputStream.filter(new EvaluationFilter(filterInstance, planCreator.getDataContext())).name(stageName);
planCreator.addStream(finalStream);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project storm by apache.
the class RelNodeCompiler method visitFilter.
@Override
public Void visitFilter(Filter filter, List<Void> inputStreams) throws Exception {
beginStage(filter);
List<RexNode> childExps = filter.getChildExps();
RelDataType inputRowType = filter.getInput(0).getRowType();
pw.print("Context context = new StormContext(Processor.dataContext);\n");
pw.print("context.values = _data.toArray();\n");
pw.print("Object[] outputValues = new Object[1];\n");
pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
String r = "((Boolean) outputValues[0])";
if (filter.getCondition().getType().isNullable()) {
pw.print(String.format(" if (%s != null && %s) { ctx.emit(_data); }\n", r, r));
} else {
pw.print(String.format(" if (%s) { ctx.emit(_data); }\n", r, r));
}
endStage();
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project storm by apache.
the class RelNodeCompiler method visitProject.
@Override
public Void visitProject(Project project, List<Void> inputStreams) throws Exception {
beginStage(project);
List<RexNode> childExps = project.getChildExps();
RelDataType inputRowType = project.getInput(0).getRowType();
int outputCount = project.getRowType().getFieldCount();
pw.print("Context context = new StormContext(Processor.dataContext);\n");
pw.print("context.values = _data.toArray();\n");
pw.print(String.format("Object[] outputValues = new Object[%d];\n", outputCount));
pw.write(rexCompiler.compileToBlock(childExps, inputRowType).toString());
pw.print(" ctx.emit(new Values(outputValues));\n");
endStage();
return null;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project flink by apache.
the class FlinkAggregateExpandDistinctAggregatesRule method createSelectDistinct.
/**
* Given an {@link org.apache.calcite.rel.logical.LogicalAggregate}
* and the ordinals of the arguments to a
* particular call to an aggregate function, creates a 'select distinct'
* relational expression which projects the group columns and those
* arguments but nothing else.
*
* <p>For example, given
*
* <blockquote>
* <pre>select f0, count(distinct f1), count(distinct f2)
* from t group by f0</pre>
* </blockquote>
*
* and the argument list
*
* <blockquote>{2}</blockquote>
*
* returns
*
* <blockquote>
* <pre>select distinct f0, f2 from t</pre>
* </blockquote>
*
* '
*
* <p>The <code>sourceOf</code> map is populated with the source of each
* column; in this case sourceOf.get(0) = 0, and sourceOf.get(1) = 2.</p>
*
* @param relBuilder Relational expression builder
* @param aggregate Aggregate relational expression
* @param argList Ordinals of columns to make distinct
* @param filterArg Ordinal of column to filter on, or -1
* @param sourceOf Out parameter, is populated with a map of where each
* output field came from
* @return Aggregate relational expression which projects the required
* columns
*/
private RelBuilder createSelectDistinct(RelBuilder relBuilder, Aggregate aggregate, List<Integer> argList, int filterArg, Map<Integer, Integer> sourceOf) {
relBuilder.push(aggregate.getInput());
final List<Pair<RexNode, String>> projects = new ArrayList<>();
final List<RelDataTypeField> childFields = relBuilder.peek().getRowType().getFieldList();
for (int i : aggregate.getGroupSet()) {
sourceOf.put(i, projects.size());
projects.add(RexInputRef.of2(i, childFields));
}
for (Integer arg : argList) {
if (filterArg >= 0) {
// Implement
// agg(DISTINCT arg) FILTER $f
// by generating
// SELECT DISTINCT ... CASE WHEN $f THEN arg ELSE NULL END AS arg
// and then applying
// agg(arg)
// as usual.
//
// It works except for (rare) agg functions that need to see null
// values.
final RexBuilder rexBuilder = aggregate.getCluster().getRexBuilder();
final RexInputRef filterRef = RexInputRef.of(filterArg, childFields);
final Pair<RexNode, String> argRef = RexInputRef.of2(arg, childFields);
RexNode condition = rexBuilder.makeCall(SqlStdOperatorTable.CASE, filterRef, argRef.left, rexBuilder.ensureType(argRef.left.getType(), rexBuilder.constantNull(), true));
sourceOf.put(arg, projects.size());
projects.add(Pair.of(condition, "i$" + argRef.right));
continue;
}
if (sourceOf.get(arg) != null) {
continue;
}
sourceOf.put(arg, projects.size());
projects.add(RexInputRef.of2(arg, childFields));
}
relBuilder.project(Pair.left(projects), Pair.right(projects));
// Get the distinct values of the GROUP BY fields and the arguments
// to the agg functions.
relBuilder.push(aggregate.copy(aggregate.getTraitSet(), relBuilder.build(), false, ImmutableBitSet.range(projects.size()), null, ImmutableList.<AggregateCall>of()));
return relBuilder;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexNode in project flink by apache.
the class FlinkAggregateJoinTransposeRule method populateEquivalences.
private static void populateEquivalences(Map<Integer, BitSet> equivalence, RexNode predicate) {
switch(predicate.getKind()) {
case EQUALS:
RexCall call = (RexCall) predicate;
final List<RexNode> operands = call.getOperands();
if (operands.get(0) instanceof RexInputRef) {
final RexInputRef ref0 = (RexInputRef) operands.get(0);
if (operands.get(1) instanceof RexInputRef) {
final RexInputRef ref1 = (RexInputRef) operands.get(1);
populateEquivalence(equivalence, ref0.getIndex(), ref1.getIndex());
populateEquivalence(equivalence, ref1.getIndex(), ref0.getIndex());
}
}
}
}
Aggregations