ehds commented on code in PR #5298:
URL: https://github.com/apache/calcite/pull/5298#discussion_r4140663317
##########
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:
Yes, I've updated the handler to inspect the pattern, measures, and other
RexNode expressions in Match as well.
##########
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:
Window, Sort, and TableModify already had handlers in the existing code.
##########
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:
The existing SubQueryCollector exposed only `collect(Project)`, and its
visitSubQuery stopped after recording a sub-query, so it could miss sub-queries
nested in a sub-query’s operands.
It also had no callers in the current codebase. I updated it to accept a
deep option and reused the visitor in RelMdTableReferences to scan each
expression with deep=true.
--
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]