zzwqqq commented on code in PR #5385:
URL: https://github.com/apache/calcite/pull/5385#discussion_r4534689674
##########
core/src/main/java/org/apache/calcite/sql2rel/CorrelateProjectExtractor.java:
##########
@@ -202,99 +187,77 @@ private static boolean isDirectFieldAccess(RexNode node,
CorrelationId id) {
return builder.build();
}
- /**
- * Traverses a plan and finds all simply correlated row expressions with the
specified id.
- */
- private static Set<RexNode> findCorrelationDependentCalls(CorrelationId
corrId, RelNode plan) {
- SimpleCorrelationCollector finder = new SimpleCorrelationCollector(corrId);
- plan.accept(new RelHomogeneousShuttle() {
- @Override public RelNode visit(RelNode other) {
- // Don't descend into a nested correlate that reuses this id: the refs
below belong to it.
- if (other instanceof Correlate
- && ((Correlate) other).getCorrelationId().equals(corrId)) {
- return other;
+ /** Applies the visitor within the specified correlation scope. */
+ private static RelNode visitCorrelationScope(RelNode root, CorrelationId id,
+ RexShuttle visitor) {
+ return root.accept(new RelHomogeneousShuttle() {
+ @Override public RelNode visit(RelNode rel) {
+ if (rel.getVariablesSet().contains(id)) {
+ if (rel instanceof Correlate) {
+ return visitChild(rel, 0, rel.getInput(0));
+ }
+ if (rel instanceof Project || rel instanceof Filter) {
+ return visitChildren(rel);
+ }
+ return rel;
}
- if (other instanceof Project || other instanceof Filter) {
- other.accept(finder);
- }
- return super.visit(other);
- }
- });
- return finder.correlations;
- }
-
- /**
- * Replaces all row expressions in the plan using the provided mapping.
- *
- * @param plan the relational expression on which we want to perform the
replacements.
- * @param mapping a mapping defining how to replace row expressions in the
plan
- * @return a new relational expression where all expressions present in the
mapping are replaced.
- */
- private static RelNode replaceExpressionsUsingMap(RelNode plan, Map<RexNode,
RexNode> mapping) {
- CallReplacer replacer = new CallReplacer(mapping);
- return plan.accept(new RelHomogeneousShuttle() {
- @Override public RelNode visit(RelNode other) {
- RelNode mNode = super.visitChildren(other);
- return mNode.accept(replacer);
+ final RelNode node = rel instanceof Project || rel instanceof Filter
+ ? rel.accept(visitor) : rel;
+ return visitChildren(node);
}
});
}
- /**
- * A collector of simply correlated row expressions.
+ /** Selects outermost deterministic computations over one correlation.
Review Comment:
Thanks. Each selected expression is stored in a `Map<RexNode, Integer>`. The
integer is its offset among the fields added to the left input. A Project
computes those fields. Selected occurrences in the right input are replaced
with `RexFieldAccess` references to the new fields. I've documented this in the
Javadoc.
--
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]