asolimando commented on code in PR #4328:
URL: https://github.com/apache/calcite/pull/4328#discussion_r2068604432
##########
core/src/main/java/org/apache/calcite/plan/RelOptUtil.java:
##########
@@ -4552,6 +4552,37 @@ private void acceptFields(final List<RelDataTypeField>
fields) {
}
}
+ /** Extension of {@link RelOptUtil.InputFinder} with subquery lookup. */
Review Comment:
```suggestion
/** Extension of {@link RelOptUtil.InputFinder} with optional subquery
lookup. */
```
##########
core/src/main/java/org/apache/calcite/sql2rel/RelFieldTrimmer.java:
##########
@@ -473,6 +477,77 @@ public TrimResult trimFields(
return result(newCalc, mapping, calc);
}
+ /**
+ * Shuttle that finds all {@link TableScan}s inside a given {@link RelNode}.
+ */
+ private static class TableScanCollector extends RelHomogeneousShuttle {
+ private ImmutableSet.Builder<List<String>> builder =
ImmutableSet.builder();
+
+ /** Qualified names. */
+ Set<List<String>> tables() {
+ return builder.build();
+ }
+
+ @Override public RelNode visit(TableScan scan) {
+ builder.add(scan.getTable().getQualifiedName());
+ return super.visit(scan);
+ }
+ }
+
+ /**
+ * Shuttle that finds all {@link TableScan}`s inside a given {@link RexNode}.
+ */
+ private static class InputTablesVisitor extends RexVisitorImpl<Void> {
+ private ImmutableSet.Builder<List<String>> builder =
ImmutableSet.builder();
+
+ protected InputTablesVisitor() {
+ super(false);
+ }
+
+ /** Qualified names. */
+ Set<List<String>> tables() {
+ return builder.build();
+ }
+
+ @Override public Void visitSubQuery(RexSubQuery subQuery) {
+ if (subQuery.getKind() == SqlKind.SCALAR_QUERY) {
+ subQuery.rel.accept(new RelHomogeneousShuttle() {
+ @Override public RelNode visit(TableScan scan) {
+ builder.add(scan.getTable().getQualifiedName());
+ return super.visit(scan);
+ }
+ });
+ }
+ return null;
+ }
+ }
+
+ private boolean inputContainSubQueryTables(Project project, RelNode input) {
Review Comment:
```suggestion
private boolean inputContainsSubQueryTables(Project project, RelNode
input) {
``` (missing 's')
##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -910,6 +910,24 @@ private static void matchJoin(SubQueryRemoveRule rule,
RelOptRuleCall call) {
int nFieldsLeft = join.getLeft().getRowType().getFieldCount();
int nFieldsRight = join.getRight().getRowType().getFieldCount();
+ // Correlation columns are also should be considered.
Review Comment:
```suggestion
// Correlation columns should also be considered.
```
##########
core/src/main/java/org/apache/calcite/rel/rules/SubQueryRemoveRule.java:
##########
@@ -910,6 +910,24 @@ private static void matchJoin(SubQueryRemoveRule rule,
RelOptRuleCall call) {
int nFieldsLeft = join.getLeft().getRowType().getFieldCount();
int nFieldsRight = join.getRight().getRowType().getFieldCount();
+ // Correlation columns are also should be considered.
+ // For example:
+ // LogicalJoin
+ // left right
+ // | |
+ // LogicalProject,inputs=0..1)
LogicalValues.NONE.[0]
Review Comment:
`LogicalProject,inputs=0..1)` <-- seems incorrectly formatted, can you check?
--
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]