You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "ian-bertolacci (via GitHub)" <gi...@apache.org> on 2026/01/28 22:26:44 UTC
[PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
ian-bertolacci opened a new pull request, #4779:
URL: https://github.com/apache/calcite/pull/4779
- Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries.
- Fix some gitignore paths (optional)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4315244903
@silundong I think you are one of the most qualified to review this, if you have time
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4009440155
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "caicancai (via GitHub)" <gi...@apache.org>.
caicancai commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4189225646
> I'm hoping to get more reviews on this.
>
> > I prefer a simpler, more intuitive processing logic, even if it affects some of the original plans.
>
> Thats fine, but I imagine that solution will take significant amount of time and effort (which I do not have for this project), and my preference (as I imagine is the preference of many others) is that we solve this severe bug we know about sooner, rather than wait for a better approach to correlation in (at a minimum) SqlToRelConverter.
@ian-bertolacci Hello, are you still working on this project? I can take some time to review it. Do you want to continue?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4254261077
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3821106608
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3814727708
This seems to expose another bug.
If a creating a projection that (a) has a correlated subquery, but (b) does not directly reference its input, then the bloat optimization will kick in, potentially eliminating the fields used as correlated references.
I'm looking to see if a Jira for this already exists.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3836682695
@silundong
> If we create a temporary `Project` with `LogicalProject.create` before correlation detection, instead of using `RelBuilder.projectNamed`, would that resolve the issue? That could be much simpler.
Thats not an unreasonable suggestion, however I expect that change would also create a lot of test changes, both in this project and anything downstream.
I'll check and see (though it'll take me a few days).
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4624077954
How are we feeling about this?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4207712028
Yes I would like it to be reviewed.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "caicancai (via GitHub)" <gi...@apache.org>.
caicancai commented on code in PR #4779:
URL: https://github.com/apache/calcite/pull/4779#discussion_r3068888477
##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -6581,6 +6653,37 @@ private static class CorrelationUse {
}
}
+ /** Wrapper around information collected by {@link #getCorrelationInfo}. */
+ private static class ResolvedCorrelationInfo {
+ public final List<CorrelationId> correlNames;
+ public final ImmutableBitSet requiredColumns;
+ public final Map<Pair<CorrelationId, Integer>, Integer> fieldMapping;
+
+ ResolvedCorrelationInfo(List<CorrelationId> correlNames, ImmutableBitSet requiredColumns,
+ Map<Pair<CorrelationId, Integer>, Integer> fieldMapping) {
+ this.correlNames = correlNames;
+ this.requiredColumns = requiredColumns;
+ this.fieldMapping = fieldMapping;
+ }
+ }
+
+ /** Wrapper around optionally returned results from {@link #massageExpressionsForCorrelation}. */
+ private static class MassagedCorrelationExpressions {
+ /** Modified expressions. */
+ public final List<RexNode> exprs;
Review Comment:
private
##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -3350,29 +3351,92 @@ protected RelNode createAsofJoin(
if (correlNames.isEmpty()) {
// None of the correlating variables originated in this scope.
return null;
+ } else {
+ return new ResolvedCorrelationInfo(correlNames, requiredColumns.build(), fieldMapping);
+ }
+ }
+
+ private @Nullable CorrelationUse getCorrelationUse(Blackboard bb, final RelNode r0) {
+ final Set<CorrelationId> correlatedVariables =
+ RelOptUtil.getVariablesUsed(r0);
+ if (correlatedVariables.isEmpty()) {
+ return null;
+ }
+
+ ResolvedCorrelationInfo correlationInfo = getCorrelationInfo(bb, correlatedVariables);
+ if (correlationInfo == null) {
+ // None of the correlating variables originated in this scope.
+ return null;
}
RelNode r = r0;
- if (correlNames.size() > 1) {
+ if (correlationInfo.correlNames.size() > 1) {
// The same table was referenced more than once.
// So we deduplicate.
r =
- DeduplicateCorrelateVariables.go(rexBuilder, correlNames.get(0),
- Util.skip(correlNames), r0);
+ DeduplicateCorrelateVariables.go(rexBuilder, correlationInfo.correlNames.get(0),
+ Util.skip(correlationInfo.correlNames), r0);
// Add new node to leaves.
leaves.put(r, r.getRowType().getFieldCount());
}
// If there are field mappings (due to aggregation), rewrite the RelNode tree
// to update correlation variable row type and field indices
- if (!fieldMapping.isEmpty()) {
+ if (!correlationInfo.fieldMapping.isEmpty()) {
r =
r.accept(
- new CorrelationFieldMappingShuttle(rexBuilder, correlNames.get(0),
- bb.root().getRowType(), fieldMapping));
+ new CorrelationFieldMappingShuttle(rexBuilder, correlationInfo.correlNames.get(0),
+ bb.root().getRowType(), correlationInfo.fieldMapping));
}
- return new CorrelationUse(correlNames.get(0), requiredColumns.build(), r);
+ return new CorrelationUse(correlationInfo.correlNames.get(0), correlationInfo.requiredColumns,
+ r);
+ }
+
+ /** Before building a RelNode tree with the provided expressions, detect and resolve correlation
+ * names, rewrite expressions, and return a callback to be called after the tree is built.
+ * Returns null if no correlation is detected.
+ */
+ private @Nullable MassagedCorrelationExpressions massageExpressionsForCorrelation(Blackboard bb,
+ final List<RexNode> exprs) {
+ Set<CorrelationId> correlatedVariables = new HashSet<>();
+ for (RexNode e : exprs) {
+ correlatedVariables.addAll(RelOptUtil.getVariablesUsed(e));
+ }
+ if (correlatedVariables.isEmpty()) {
+ return null;
+ }
+
+ ResolvedCorrelationInfo correlationInfo = getCorrelationInfo(bb, correlatedVariables);
+ if (correlationInfo == null) {
+ // None of the correlating variables originated in this scope.
+ return null;
+ }
+
+ List<RexNode> newExprs = new ArrayList<>(exprs);
+ Consumer<RelNode> callback = (RelNode r) -> { };
Review Comment:
The callback first assigns a null operation, which is then overridden within the if block. If someone later inserts code between the two assignments and uses the callback again, the incorrect (null operation) version will be used.
##########
.gitignore:
##########
@@ -33,9 +34,7 @@
/.vscode/*
# IDEA
-/out
Review Comment:
.gitignore changes should be in a separate PR
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4315083606
Where do we stand on this?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on code in PR #4779:
URL: https://github.com/apache/calcite/pull/4779#discussion_r3088409623
##########
.gitignore:
##########
@@ -33,9 +34,7 @@
/.vscode/*
# IDEA
-/out
Review Comment:
Moved to #4887
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4329231966
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4328919146
@silundong that makes sense, and the added tests pass with your changes. I will push a commit with them.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3844772334
I prefer a simpler, more intuitive processing logic, even if it affects some of the original plans. As you mentioned, are there other places where similar issues arise, and would it be better to have a unified logic for handling them?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #4779:
URL: https://github.com/apache/calcite/pull/4779#discussion_r2739436834
##########
.gitignore:
##########
@@ -33,16 +34,15 @@
/.vscode/*
# IDEA
-/out
Review Comment:
Why change .gitignore file?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "silundong (via GitHub)" <gi...@apache.org>.
silundong merged PR #4779:
URL: https://github.com/apache/calcite/pull/4779
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4560946988
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@calcite.apache.org list. Thank you for your contributions.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3821071383
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4779&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4779&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [95.3% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4779&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4779)
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "silundong (via GitHub)" <gi...@apache.org>.
silundong commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-3836244112
If we create a temporary `Project` with `LogicalProject.create` before correlation detection, instead of using `RelBuilder.projectNamed`, would that resolve the issue? That could be much simpler.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4253922819
Changes made and commit rebased to current main head
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4013065094
I'm hoping to get more reviews on this.
> I prefer a simpler, more intuitive processing logic, even if it affects some of the original plans.
Thats fine, I imagine that solution will take significant amount of time and effort (which I do not have for this project), and my preference (as I imagine is the preference of many others) is that we solve this severe bug we know about sooner, rather than wait for a better approach to correlation in (at a minimum) SqlToRelConverter.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Use working Project input instead of Blackboard root when rebuilding Project for correlated subqueries [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on code in PR #4779:
URL: https://github.com/apache/calcite/pull/4779#discussion_r2742706003
##########
.gitignore:
##########
@@ -33,16 +34,15 @@
/.vscode/*
# IDEA
-/out
Review Comment:
When I run with intellij, git detected a ton of extra files.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4624097221
@silundong if you have some time to take another look, it would be great
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "ian-bertolacci (via GitHub)" <gi...@apache.org>.
ian-bertolacci commented on code in PR #4779:
URL: https://github.com/apache/calcite/pull/4779#discussion_r3087952915
##########
core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java:
##########
@@ -3350,29 +3351,92 @@ protected RelNode createAsofJoin(
if (correlNames.isEmpty()) {
// None of the correlating variables originated in this scope.
return null;
+ } else {
+ return new ResolvedCorrelationInfo(correlNames, requiredColumns.build(), fieldMapping);
+ }
+ }
+
+ private @Nullable CorrelationUse getCorrelationUse(Blackboard bb, final RelNode r0) {
+ final Set<CorrelationId> correlatedVariables =
+ RelOptUtil.getVariablesUsed(r0);
+ if (correlatedVariables.isEmpty()) {
+ return null;
+ }
+
+ ResolvedCorrelationInfo correlationInfo = getCorrelationInfo(bb, correlatedVariables);
+ if (correlationInfo == null) {
+ // None of the correlating variables originated in this scope.
+ return null;
}
RelNode r = r0;
- if (correlNames.size() > 1) {
+ if (correlationInfo.correlNames.size() > 1) {
// The same table was referenced more than once.
// So we deduplicate.
r =
- DeduplicateCorrelateVariables.go(rexBuilder, correlNames.get(0),
- Util.skip(correlNames), r0);
+ DeduplicateCorrelateVariables.go(rexBuilder, correlationInfo.correlNames.get(0),
+ Util.skip(correlationInfo.correlNames), r0);
// Add new node to leaves.
leaves.put(r, r.getRowType().getFieldCount());
}
// If there are field mappings (due to aggregation), rewrite the RelNode tree
// to update correlation variable row type and field indices
- if (!fieldMapping.isEmpty()) {
+ if (!correlationInfo.fieldMapping.isEmpty()) {
r =
r.accept(
- new CorrelationFieldMappingShuttle(rexBuilder, correlNames.get(0),
- bb.root().getRowType(), fieldMapping));
+ new CorrelationFieldMappingShuttle(rexBuilder, correlationInfo.correlNames.get(0),
+ bb.root().getRowType(), correlationInfo.fieldMapping));
}
- return new CorrelationUse(correlNames.get(0), requiredColumns.build(), r);
+ return new CorrelationUse(correlationInfo.correlNames.get(0), correlationInfo.requiredColumns,
+ r);
+ }
+
+ /** Before building a RelNode tree with the provided expressions, detect and resolve correlation
+ * names, rewrite expressions, and return a callback to be called after the tree is built.
+ * Returns null if no correlation is detected.
+ */
+ private @Nullable MassagedCorrelationExpressions massageExpressionsForCorrelation(Blackboard bb,
+ final List<RexNode> exprs) {
+ Set<CorrelationId> correlatedVariables = new HashSet<>();
+ for (RexNode e : exprs) {
+ correlatedVariables.addAll(RelOptUtil.getVariablesUsed(e));
+ }
+ if (correlatedVariables.isEmpty()) {
+ return null;
+ }
+
+ ResolvedCorrelationInfo correlationInfo = getCorrelationInfo(bb, correlatedVariables);
+ if (correlationInfo == null) {
+ // None of the correlating variables originated in this scope.
+ return null;
+ }
+
+ List<RexNode> newExprs = new ArrayList<>(exprs);
+ Consumer<RelNode> callback = (RelNode r) -> { };
Review Comment:
I'll make this final and assign the no-op in an else block.
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-7405] Pre-process expressions for correlations before building projection in SqlToRelConverter [calcite]
Posted by "silundong (via GitHub)" <gi...@apache.org>.
silundong commented on PR #4779:
URL: https://github.com/apache/calcite/pull/4779#issuecomment-4318345704
> To circumvent the bloat optimizations, it is necessary to provide the correlation variables (if they exist) to the builder.
As I mentioned before, I create a temporary `Project` with `LogicalProject.create` before correlation detection, instead of using `RelBuilder.projectNamed`, just like:
```
RelNode project =
LogicalProject.create(bb.root(), ImmutableList.of(), exprs, uniqueFieldNames,
ImmutableSet.of());
final RelNode r;
final CorrelationUse p = getCorrelationUse(bb, project);
if (p != null) {
assert p.r instanceof Project;
// correlation variables have been normalized in p.r, we should use expressions
// in p.r instead of the original exprs
Project project1 = (Project) p.r;
r = relBuilder.push(bb.root())
.projectNamed(project1.getProjects(), uniqueFieldNames, true,
ImmutableSet.of(p.id))
.build();
} else {
r = relBuilder.push(bb.root()).projectNamed(exprs, uniqueFieldNames, true).build();
}
```
This approach resolves the issue without causing any other test regressions. IMO, it's not only effective but also simpler and more intuitive. Do you see any drawbacks to it?
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org