kgyrtkirk commented on code in PR #4077:
URL: https://github.com/apache/calcite/pull/4077#discussion_r1870973995
##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -1336,6 +1338,132 @@ public TrimResult trimFields(
return result(newSnapshot, inputMapping, snapshot);
}
+ /**
+ * Trims {@link LogicalCorrelate} nodes.
+ */
+ public TrimResult trimFields(LogicalCorrelate correlate,
+ ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields) {
+ if (!extraFields.isEmpty()) {
+ // bail out with generic trim
+ return trimFields((RelNode) correlate, fieldsUsed, extraFields);
+ }
+
+ fieldsUsed = fieldsUsed.union(correlate.getRequiredColumns());
+
+ List<RelNode> newInputs = new ArrayList<>();
+ List<Mapping> inputMappings = new ArrayList<>();
+ int changeCount = 0;
+ int offset = 0;
+ for (RelNode input : correlate.getInputs()) {
+ final RelDataType inputRowType = input.getRowType();
+ final int inputFieldCount = inputRowType.getFieldCount();
+
+ ImmutableBitSet currentInputFieldsUsed = fieldsUsed
+ .intersect(ImmutableBitSet.range(offset, offset + inputFieldCount))
+ .shift(-offset);
+
+ TrimResult trimResult =
+ dispatchTrimFields(input, currentInputFieldsUsed, extraFields);
+
+ newInputs.add(trimResult.left);
+ inputMappings.add(trimResult.right);
+
+ offset += inputFieldCount;
+
+ if (trimResult.left != input) {
+ changeCount++;
+ }
+ }
+
+ if (changeCount == 0) {
+ return result(correlate,
+ Mappings.createIdentity(correlate.getRowType().getFieldCount()));
+ }
+
+ Mapping mapping = makeMapping(inputMappings);
+ RexBuilder rexBuilder = relBuilder.getRexBuilder();
+
+ RexCorrelVariableMapShuttle rexVisitor =
+ new RexCorrelVariableMapShuttle(correlate.getCorrelationId(),
+ newInputs.get(0).getRowType(), mapping, rexBuilder);
+ final LogicalCorrelate newCorrelate =
+ correlate
+ .copy(correlate.getTraitSet(),
+ newInputs.get(0),
+ newInputs.get(1).accept(new
RexRewritingRelShuttle(rexVisitor)),
Review Comment:
extracted them to be `newLeft` and `newRight` (I was thinking the same
earlier ; but I've only extracted the `rexVistior`)
`LogicalCorrelate`'s constructor has only `left` and `right` - but that may
change...I've added a check to ensure that this only applies when
`correlate.getInputs().size()` is 2
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]