xuzifu666 commented on code in PR #5086:
URL: https://github.com/apache/calcite/pull/5086#discussion_r3565840669
##########
core/src/test/java/org/apache/calcite/sql2rel/CorrelateProjectExtractorTest.java:
##########
@@ -84,6 +84,78 @@ public static Frameworks.ConfigBuilder config() {
assertThat(after, hasTree(planAfter));
}
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-7646">[CALCITE-7646]
+ * CorrelateProjectExtractor does not handle nested field accesses
cor0.field0.field1</a>. */
+ @Test void testNestedCorrelationFieldAccessInFilter() {
Review Comment:
The new logic returns null from `visitCall` for neutral subexpressions. The
Javadoc example `CASE(IS NOT NULL($cor0.PATH), $cor0.PATH, ARRAY(NULL))` is not
covered by any test. can we add a test to verify that
constant/dynamic-parameter operands do not wrongly disqualify the enclosing
correlated call?
##########
core/src/main/java/org/apache/calcite/sql2rel/CorrelateProjectExtractor.java:
##########
@@ -88,15 +88,33 @@ public CorrelateProjectExtractor(RelBuilderFactory factory)
{
this.builderFactory = factory;
}
+ /** Returns whether {@code node} is a direct field access on the correlation
+ * variable with the specified id, such as {@code $cor0.DEPTNO}. A nested
+ * access such as {@code $cor0.REC.DEPTNO} is not direct. */
+ private static boolean isDirectFieldAccess(RexNode node, CorrelationId id) {
+ if (node instanceof RexFieldAccess) {
+ RexFieldAccess access = (RexFieldAccess) node;
+ if (access.getReferenceExpr() instanceof RexCorrelVariable) {
+ RexCorrelVariable var = (RexCorrelVariable) access.getReferenceExpr();
+ return var.id.equals(id);
+ }
+ }
+ return false;
+ }
+
@Override public RelNode visit(LogicalCorrelate correlate) {
RelNode left = correlate.getLeft().accept(this);
RelNode right = correlate.getRight().accept(this);
int oldLeft = left.getRowType().getFieldCount();
// Find the correlated expressions from the right side that can be moved
to the left
Set<RexNode> callsWithCorrelationInRight =
findCorrelationDependentCalls(correlate.getCorrelationId(), right);
+ // Only direct field accesses on the correlation variable, such as
Review Comment:
These comments should be left-aligned.
--
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]