use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCorrelate in project calcite by apache.
the class RelStructuredTypeFlattener method rewriteRel.
public void rewriteRel(LogicalCorrelate rel) {
ImmutableBitSet.Builder newPos = ImmutableBitSet.builder();
for (int pos : rel.getRequiredColumns()) {
RelDataType corrFieldType = rel.getLeft().getRowType().getFieldList().get(pos).getType();
if (corrFieldType.isStruct()) {
throw Util.needToImplement("correlation on structured type");
}
newPos.set(getNewForOldInput(pos));
}
LogicalCorrelate newRel = LogicalCorrelate.create(getNewForOldRel(rel.getLeft()), getNewForOldRel(rel.getRight()), rel.getCorrelationId(), newPos.build(), rel.getJoinType());
setNewForOldRel(rel, newRel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCorrelate 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.logical.LogicalCorrelate in project drill by apache.
the class DrillCorrelateRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
final LogicalCorrelate correlate = call.rel(0);
final RelNode left = correlate.getLeft();
final RelNode right = correlate.getRight();
final RelNode convertedLeft = convert(left, left.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
final RelNode convertedRight = convert(right, right.getTraitSet().plus(DrillRel.DRILL_LOGICAL).simplify());
final RelTraitSet traits = correlate.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
DrillLateralJoinRel lateralJoinRel = new DrillLateralJoinRel(correlate.getCluster(), traits, convertedLeft, convertedRight, false, correlate.getCorrelationId(), correlate.getRequiredColumns(), correlate.getJoinType());
call.transformTo(lateralJoinRel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.logical.LogicalCorrelate 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