org.apache.calcite.rel.core.Uncollect Java Examples
The following examples show how to use
org.apache.calcite.rel.core.Uncollect.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrillUnnestRule.java From Bats with Apache License 2.0 | 5 votes |
@Override public void onMatch(RelOptRuleCall call) { final Uncollect uncollect = call.rel(0); final LogicalProject project = call.rel(1); RexNode projectedNode = project.getProjects().iterator().next(); if (projectedNode.getKind() != SqlKind.FIELD_ACCESS) { return; } final RelTraitSet traits = uncollect.getTraitSet().plus(DrillRel.DRILL_LOGICAL); DrillUnnestRel unnest = new DrillUnnestRel(uncollect.getCluster(), traits, uncollect.getRowType(), projectedNode); call.transformTo(unnest); }
Example #2
Source File: ComplexUnnestVisitor.java From Bats with Apache License 2.0 | 5 votes |
@Override public RelNode visit(RelNode other) { if (other instanceof Uncollect) { return visit((Uncollect) other); } return super.visit(other); }
Example #3
Source File: PostOrderRelNodeVisitor.java From streamline with Apache License 2.0 | 5 votes |
public final T traverse(RelNode n) throws Exception { List<T> inputStreams = new ArrayList<>(); for (RelNode input : n.getInputs()) { inputStreams.add(traverse(input)); } if (n instanceof Aggregate) { return visitAggregate((Aggregate) n, inputStreams); } else if (n instanceof Calc) { return visitCalc((Calc) n, inputStreams); } else if (n instanceof Collect) { return visitCollect((Collect) n, inputStreams); } else if (n instanceof Correlate) { return visitCorrelate((Correlate) n, inputStreams); } else if (n instanceof Delta) { return visitDelta((Delta) n, inputStreams); } else if (n instanceof Exchange) { return visitExchange((Exchange) n, inputStreams); } else if (n instanceof Project) { return visitProject((Project) n, inputStreams); } else if (n instanceof Filter) { return visitFilter((Filter) n, inputStreams); } else if (n instanceof Sample) { return visitSample((Sample) n, inputStreams); } else if (n instanceof Sort) { return visitSort((Sort) n, inputStreams); } else if (n instanceof TableModify) { return visitTableModify((TableModify) n, inputStreams); } else if (n instanceof TableScan) { return visitTableScan((TableScan) n, inputStreams); } else if (n instanceof Uncollect) { return visitUncollect((Uncollect) n, inputStreams); } else if (n instanceof Window) { return visitWindow((Window) n, inputStreams); } else if (n instanceof Join) { return visitJoin((Join) n, inputStreams); } else { return defaultValue(n, inputStreams); } }
Example #4
Source File: PigRelBuilder.java From calcite with Apache License 2.0 | 5 votes |
/** * Flattens the top relation will all multiset columns. Call this method only if * the top relation contains multiset columns only. * * @return This builder. */ public RelBuilder multiSetFlatten() { // [CALCITE-3193] Add RelBuilder.uncollect method, and interface // UncollectFactory, to instantiate Uncollect Uncollect uncollect = Uncollect.create( cluster.traitSetOf(Convention.NONE), build(), false, Collections.emptyList()); push(uncollect); return this; }
Example #5
Source File: RelToSqlConverter.java From calcite with Apache License 2.0 | 5 votes |
public Result visit(Uncollect e) { final Result x = visitChild(0, e.getInput()); final SqlNode unnestNode = SqlStdOperatorTable.UNNEST.createCall(POS, x.asStatement()); final List<SqlNode> operands = createAsFullOperands(e.getRowType(), unnestNode, x.neededAlias); final SqlNode asNode = SqlStdOperatorTable.AS.createCall(POS, operands); return result(asNode, ImmutableList.of(Clause.FROM), e, null); }
Example #6
Source File: EnumerableUncollectRule.java From calcite with Apache License 2.0 | 5 votes |
public RelNode convert(RelNode rel) { final Uncollect uncollect = (Uncollect) rel; final RelTraitSet traitSet = uncollect.getTraitSet().replace(EnumerableConvention.INSTANCE); final RelNode input = uncollect.getInput(); final RelNode newInput = convert(input, input.getTraitSet().replace(EnumerableConvention.INSTANCE)); return EnumerableUncollect.create(traitSet, newInput, uncollect.withOrdinality); }
Example #7
Source File: RelBuilder.java From calcite with Apache License 2.0 | 5 votes |
/** * Creates an {@link Uncollect} with given item aliases. * * @param itemAliases Operand item aliases, never null * @param withOrdinality If {@code withOrdinality}, the output contains an extra * {@code ORDINALITY} column */ public RelBuilder uncollect(List<String> itemAliases, boolean withOrdinality) { Frame frame = stack.pop(); stack.push( new Frame( new Uncollect( cluster, cluster.traitSetOf(Convention.NONE), frame.rel, withOrdinality, Objects.requireNonNull(itemAliases)))); return this; }
Example #8
Source File: RelStructuredTypeFlattener.java From Bats with Apache License 2.0 | 4 votes |
public void rewriteRel(Uncollect rel) { rewriteGeneric(rel); }
Example #9
Source File: DrillUnnestRule.java From Bats with Apache License 2.0 | 4 votes |
private DrillUnnestRule() { super(RelOptHelper.some(Uncollect.class, RelOptHelper.some(LogicalProject.class, RelOptHelper.any(LogicalValues.class, Convention.NONE))), DrillRelFactories.LOGICAL_BUILDER, "DrillUnnestRule"); }
Example #10
Source File: ComplexUnnestVisitor.java From Bats with Apache License 2.0 | 4 votes |
public RelNode visit(Uncollect uncollect) { RelBuilder builder = DrillRelFactories.LOGICAL_BUILDER.create(uncollect.getCluster(), null); RexBuilder rexBuilder = builder.getRexBuilder(); assert uncollect.getInput() instanceof Project : "Uncollect should have Project input"; Project project = (Project) uncollect.getInput(); // If project below uncollect contains only field references, no need to rewrite it List<RexNode> projectChildExps = project.getChildExps(); assert projectChildExps.size() == 1 : "Uncollect does not support multiple expressions"; RexNode projectExpr = projectChildExps.iterator().next(); if (projectExpr.getKind() == SqlKind.FIELD_ACCESS) { return uncollect; } // Collects CorrelationId instances used in current rel node RelOptUtil.VariableUsedVisitor variableUsedVisitor = new RelOptUtil.VariableUsedVisitor(null); project.accept(variableUsedVisitor); assert variableUsedVisitor.variables.size() == 1 : "Uncollect supports only single correlated reference"; CorrelationId oldCorrId = variableUsedVisitor.variables.iterator().next(); RelNode left = leftInputs.get(oldCorrId); // Creates new project to be placed on top of the left input of correlate List<RexNode> leftProjExprs = new ArrayList<>(); List<String> fieldNames = new ArrayList<>(); for (RelDataTypeField field : left.getRowType().getFieldList()) { leftProjExprs.add(rexBuilder.makeInputRef(left, field.getIndex())); fieldNames.add(field.getName()); } fieldNames.add(COMPLEX_FIELD_NAME); builder.push(left); // Adds complex expression with replaced correlation // to the projected list from the left leftProjExprs.add(new RexFieldAccessReplacer(builder).apply(projectExpr)); RelNode leftProject = builder.project(leftProjExprs, fieldNames) .build(); leftInputs.put(oldCorrId, leftProject); builder.push(project.getInput()); CorrelationId newCorrId = uncollect.getCluster().createCorrel(); // stores new CorrelationId to be used during the creation of new Correlate updatedCorrelationIds.put(oldCorrId, newCorrId); RexNode rexCorrel = rexBuilder.makeCorrel(leftProject.getRowType(), newCorrId); // constructs Project below Uncollect with updated RexCorrelVariable builder.project( ImmutableList.of(rexBuilder.makeFieldAccess(rexCorrel, leftProjExprs.size() - 1)), ImmutableList.of(COMPLEX_FIELD_NAME)); return uncollect.copy(uncollect.getTraitSet(), builder.build()); }
Example #11
Source File: PostOrderRelNodeVisitor.java From streamline with Apache License 2.0 | 4 votes |
public T visitUncollect(Uncollect uncollect, List<T> inputStreams) throws Exception { return defaultValue(uncollect, inputStreams); }
Example #12
Source File: EnumerableUncollectRule.java From calcite with Apache License 2.0 | 4 votes |
EnumerableUncollectRule() { super(Uncollect.class, Convention.NONE, EnumerableConvention.INSTANCE, "EnumerableUncollectRule"); }
Example #13
Source File: RelStructuredTypeFlattener.java From calcite with Apache License 2.0 | 4 votes |
public void rewriteRel(Uncollect rel) { rewriteGeneric(rel); }
Example #14
Source File: UncollectNode.java From calcite with Apache License 2.0 | 4 votes |
public UncollectNode(Compiler compiler, Uncollect uncollect) { super(compiler, uncollect); }
Example #15
Source File: Nodes.java From calcite with Apache License 2.0 | 4 votes |
public void visit(Uncollect uncollect) { node = new UncollectNode(this, uncollect); }