-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix: common_sub_expression_eliminate optimizer rule failed #16066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alamb
merged 4 commits into
apache:main
from
Col-Waltz:fix_common_subexpression_eliminate
Sep 28, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6936394
Fix: common_sub_expression_eliminate optimizer rule failed
Col-Waltz f5b6a24
Merge branch 'main' into fix_common_subexpression_eliminate
alamb 416e585
Merge branch 'main' into fix_common_subexpression_eliminate
alamb 182c655
Merge branch 'main' into fix_common_subexpression_eliminate
alamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -739,6 +739,31 @@ SELECT c2, var_samp(c12) FILTER (WHERE c12 > 0.95) FROM aggregate_test_100 GROUP | |
4 NULL | ||
5 NULL | ||
|
||
statement ok | ||
CREATE TABLE t ( | ||
a DOUBLE, | ||
b BIGINT, | ||
c INT | ||
) AS VALUES | ||
(1.0, 10, -5), | ||
(2.0, 20, -5), | ||
(3.0, 20, 4); | ||
|
||
# https://github.com/apache/datafusion/issues/15291 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some reason this query is failing for me
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nm, I can get it to reproduce like this > set datafusion.sql_parser.dialect = 'postgres';
0 row(s) fetched.
Elapsed 0.000 seconds.
> CREATE TABLE t (
a DOUBLE,
b BIGINT,
c INT
) AS VALUES
(1.0, 10, -5),
(2.0, 20, -5),
(3.0, 20, 4);
0 row(s) fetched.
Elapsed 0.002 seconds.
> WITH s AS (
SELECT
COUNT(a) FILTER (WHERE (b * b) - 3600 <= b),
COUNT(a) FILTER (WHERE (b * b) - 3000 <= b AND (c >= 0)),
COUNT(a) FILTER (WHERE (b * b) - 3000 <= b AND (c >= 0) AND (c >= 0))
FROM t
) SELECT * FROM s
;
Optimizer rule 'common_sub_expression_eliminate' failed
caused by
Schema error: No field named "count(t.a) FILTER (WHERE t.b * t.b - Int64(3600) <= t.b)". Did you mean 'count(t.a) FILTER (WHERE __common_expr_1 AS t.b * t.b - Int64(3600) <= t.b)'?. |
||
query III | ||
WITH s AS ( | ||
SELECT | ||
COUNT(a) FILTER (WHERE (b * b) - 3600 <= b), | ||
COUNT(a) FILTER (WHERE (b * b) - 3000 <= b AND (c >= 0)), | ||
COUNT(a) FILTER (WHERE (b * b) - 3000 <= b AND (c >= 0) AND (c >= 0)) | ||
FROM t | ||
) SELECT * FROM s | ||
---- | ||
3 1 1 | ||
|
||
statement ok | ||
DROP TABLE t | ||
|
||
# Restore the default dialect | ||
statement ok | ||
set datafusion.sql_parser.dialect = 'Generic'; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the same as a vec of all None?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, thanks for the comment. But this will not work, because vec! requires value to implement Clone trait but the Option<SavedName> doesn't. It seems to me easier to do this by map instead of adding trait to SavedName.