mihaibudiu commented on code in PR #5298:
URL: https://github.com/apache/calcite/pull/5298#discussion_r4125626615


##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java:
##########
@@ -160,31 +157,40 @@ public Set<RelTableRef> getTableReferences(TableScan rel, 
RelMetadataQuery mq) {
    * references.
    */
   public @Nullable Set<RelTableRef> getTableReferences(SetOp rel, 
RelMetadataQuery mq) {
-    return getTableReferences(rel.getInputs(), mq);
+    return getTableReferences(rel.getInputs(), ImmutableList.of(), mq);
   }
 
   /**
-   * Table references from the relational inputs of a TableFunctionScan.
+   * Table references from TableFunctionScan.
    *
-   * <p>Returns an empty set if there are no inputs, and {@code null} if the 
table
-   * references of any input cannot be determined. Tables accessed internally

Review Comment:
   why delete this comment?



##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java:
##########
@@ -270,4 +277,29 @@ public Set<RelTableRef> getTableReferences(TableScan rel, 
RelMetadataQuery mq) {
     return mq.getTableReferences(rel.getInput());
   }
 
+  /** Table references from Snapshot. */
+  public @Nullable Set<RelTableRef> getTableReferences(Snapshot rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());

Review Comment:
   don't you need to analyze the period operand to?



##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java:
##########
@@ -270,4 +277,29 @@ public Set<RelTableRef> getTableReferences(TableScan rel, 
RelMetadataQuery mq) {
     return mq.getTableReferences(rel.getInput());
   }
 
+  /** Table references from Snapshot. */
+  public @Nullable Set<RelTableRef> getTableReferences(Snapshot rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());
+  }
+
+  /** Table references from Match. */
+  public @Nullable Set<RelTableRef> getTableReferences(Match rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());
+  }
+
+  /** Table references from Uncollect. */
+  public @Nullable Set<RelTableRef> getTableReferences(Uncollect rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());
+  }
+
+  /** Table references from Collect. */
+  public @Nullable Set<RelTableRef> getTableReferences(Collect rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());
+  }
+
+  /** Table references from Spool. */
+  public @Nullable Set<RelTableRef> getTableReferences(Spool rel, 
RelMetadataQuery mq) {

Review Comment:
   apparently there are still some classes not handled, like Window, Sort, 
TableModify



##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java:
##########
@@ -270,4 +277,29 @@ public Set<RelTableRef> getTableReferences(TableScan rel, 
RelMetadataQuery mq) {
     return mq.getTableReferences(rel.getInput());
   }
 
+  /** Table references from Snapshot. */
+  public @Nullable Set<RelTableRef> getTableReferences(Snapshot rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());
+  }
+
+  /** Table references from Match. */
+  public @Nullable Set<RelTableRef> getTableReferences(Match rel, 
RelMetadataQuery mq) {
+    return mq.getTableReferences(rel.getInput());

Review Comment:
   don't you need to analyze the pattern and measures operands?



##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdTableReferences.java:
##########
@@ -160,31 +157,40 @@ public Set<RelTableRef> getTableReferences(TableScan rel, 
RelMetadataQuery mq) {
    * references.
    */
   public @Nullable Set<RelTableRef> getTableReferences(SetOp rel, 
RelMetadataQuery mq) {
-    return getTableReferences(rel.getInputs(), mq);
+    return getTableReferences(rel.getInputs(), ImmutableList.of(), mq);
   }
 
   /**
-   * Table references from the relational inputs of a TableFunctionScan.
+   * Table references from TableFunctionScan.
    *
-   * <p>Returns an empty set if there are no inputs, and {@code null} if the 
table
-   * references of any input cannot be determined. Tables accessed internally
-   * by the table function are not included.
+   * <p>Returns an empty set when its inputs and call reference no tables.
    */
   public @Nullable Set<RelTableRef> getTableReferences(TableFunctionScan rel,
       RelMetadataQuery mq) {
-    return getTableReferences(rel.getInputs(), mq);
+    return getTableReferences(rel.getInputs(), 
ImmutableList.of(rel.getCall()), mq);
   }
 
-  /** Returns the union of the table references of {@code inputs}, assigning
-   * distinct entity numbers to repeated references to the same table, or 
{@code null}
-   * if the references of any input cannot be determined. */
+  /** Returns the union of the table references of {@code inputs} and 
expression
+   * sub-queries, assigning distinct entity numbers to repeated references to
+   * the same table, or {@code null} if the references of any input or 
sub-query
+   * cannot be determined. */
   private static @Nullable Set<RelTableRef> getTableReferences(
-      List<RelNode> inputs, RelMetadataQuery mq) {
+      List<RelNode> inputs, List<? extends RexNode> expressions, 
RelMetadataQuery mq) {
+    final List<RelNode> rels = new ArrayList<>(inputs);
+    final RexVisitorImpl<Void> visitor = new RexVisitorImpl<Void>(true) {

Review Comment:
   you can reuse the SubQueryCollector visitor



-- 
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]

Reply via email to