use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project calcite by apache.
the class RelFieldTrimmer method result.
protected TrimResult result(RelNode r, final Mapping mapping) {
final RexBuilder rexBuilder = relBuilder.getRexBuilder();
for (final CorrelationId correlation : r.getVariablesSet()) {
r = r.accept(new CorrelationReferenceFinder() {
protected RexNode handle(RexFieldAccess fieldAccess) {
final RexCorrelVariable v = (RexCorrelVariable) fieldAccess.getReferenceExpr();
if (v.id.equals(correlation) && v.getType().getFieldCount() == mapping.getSourceCount()) {
final int old = fieldAccess.getField().getIndex();
final int new_ = mapping.getTarget(old);
final RelDataTypeFactory.Builder typeBuilder = relBuilder.getTypeFactory().builder();
for (int target : Util.range(mapping.getTargetCount())) {
typeBuilder.add(v.getType().getFieldList().get(mapping.getSource(target)));
}
final RexNode newV = rexBuilder.makeCorrel(typeBuilder.build(), v.id);
if (old != new_) {
return rexBuilder.makeFieldAccess(newV, new_);
}
}
return fieldAccess;
}
});
}
return new TrimResult(r, mapping);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project calcite by apache.
the class RelStructuredTypeFlattener method updateRelInMap.
// ~ Methods ----------------------------------------------------------------
public void updateRelInMap(SortedSetMultimap<RelNode, CorrelationId> mapRefRelToCorVar) {
for (RelNode rel : Lists.newArrayList(mapRefRelToCorVar.keySet())) {
if (oldToNewRelMap.containsKey(rel)) {
SortedSet<CorrelationId> corVarSet = mapRefRelToCorVar.removeAll(rel);
mapRefRelToCorVar.putAll(oldToNewRelMap.get(rel), corVarSet);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project calcite by apache.
the class RelStructuredTypeFlattener method updateRelInMap.
public void updateRelInMap(SortedMap<CorrelationId, LogicalCorrelate> mapCorVarToCorRel) {
for (CorrelationId corVar : mapCorVarToCorRel.keySet()) {
LogicalCorrelate oldRel = mapCorVarToCorRel.get(corVar);
if (oldToNewRelMap.containsKey(oldRel)) {
RelNode newRel = oldToNewRelMap.get(oldRel);
assert newRel instanceof LogicalCorrelate;
mapCorVarToCorRel.put(corVar, (LogicalCorrelate) newRel);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project drill by apache.
the class LateralUnnestRowIDVisitor method visitLateral.
@Override
public Prel visitLateral(LateralJoinPrel prel, Boolean isRightOfLateral) throws RuntimeException {
List<RelNode> children = Lists.newArrayList();
children.add(((Prel) prel.getInput(0)).accept(this, isRightOfLateral));
children.add(((Prel) prel.getInput(1)).accept(this, true));
if (!isRightOfLateral) {
return (Prel) prel.copy(prel.getTraitSet(), children);
} else {
// Adjust the column numbering due to an additional column "$drill_implicit_field$" is added to the inputs.
Map<Integer, Integer> requiredColsMap = new HashMap<>();
for (Integer corrColIndex : prel.getRequiredColumns()) {
requiredColsMap.put(corrColIndex, corrColIndex + 1);
}
ImmutableBitSet requiredColumns = prel.getRequiredColumns().shift(1);
CorrelationId corrId = prel.getCluster().createCorrel();
RexCorrelVariable updatedCorrel = (RexCorrelVariable) prel.getCluster().getRexBuilder().makeCorrel(children.get(0).getRowType(), corrId);
RelNode rightChild = children.get(1).accept(new CorrelateVarReplacer(new ProjectCorrelateTransposeRule.RexFieldAccessReplacer(prel.getCorrelationId(), updatedCorrel, prel.getCluster().getRexBuilder(), requiredColsMap)));
return (Prel) prel.copy(prel.getTraitSet(), children.get(0), rightChild, corrId, requiredColumns, prel.getJoinType());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.CorrelationId in project drill by apache.
the class ComplexUnnestVisitor method visit.
@Override
public RelNode visit(LogicalCorrelate correlate) {
RelNode left = correlate.getLeft().accept(this);
leftInputs.put(correlate.getCorrelationId(), left);
RelNode right = correlate.getRight().accept(this);
// after rewriting right input, no need to create Correlate with new CorrelationId
if (correlate.getRight() == right || left == leftInputs.get(correlate.getCorrelationId())) {
if (correlate.getLeft() == left) {
return correlate;
}
// changed only inputs, but CorrelationId left the same
return correlate.copy(correlate.getTraitSet(), Arrays.asList(left, right));
}
Correlate newCorrelate = correlate.copy(correlate.getTraitSet(), leftInputs.get(correlate.getCorrelationId()), right, updatedCorrelationIds.get(correlate.getCorrelationId()), ImmutableBitSet.of(left.getRowType().getFieldCount()), correlate.getJoinType());
RelBuilder builder = DrillRelFactories.LOGICAL_BUILDER.create(correlate.getCluster(), null);
builder.push(newCorrelate);
List<RexNode> topProjectExpressions = left.getRowType().getFieldList().stream().map(field -> builder.getRexBuilder().makeInputRef(newCorrelate, field.getIndex())).collect(Collectors.toList());
// Accommodate the new $COMPLEX_FIELD_NAME column.
int rightStartIndex = left.getRowType().getFieldList().size() + 1;
switch(correlate.getJoinType()) {
case LEFT:
case INNER:
// adds field from the right input of correlate to the top project
topProjectExpressions.addAll(right.getRowType().getFieldList().stream().map(field -> builder.getRexBuilder().makeInputRef(newCorrelate, field.getIndex() + rightStartIndex)).collect(Collectors.toList()));
// fall through
case ANTI:
case SEMI:
builder.project(topProjectExpressions, correlate.getRowType().getFieldNames());
}
return builder.build();
}
Aggregations