use of org.apache.calcite.rex.RexCorrelVariable 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.calcite.rex.RexCorrelVariable 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());
}
}
Aggregations