-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22548][SQL] Incorrect nested AND expression pushed down to JDBC data source #19776
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
Changes from 2 commits
58de88c
e540790
635768e
3bb7d3c
0aebdfb
ba06181
fc34568
0cbb528
a0b3d4e
7a19ac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -497,7 +497,11 @@ object DataSourceStrategy { | |
| Some(sources.IsNotNull(a.name)) | ||
|
|
||
| case expressions.And(left, right) => | ||
| (translateFilter(left) ++ translateFilter(right)).reduceOption(sources.And) | ||
| // See SPARK-12218 and PR 10362 for detailed discussion | ||
| for { | ||
|
Member
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. Let's add a small comment like the PR you pointed out.
Contributor
Author
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. Sure. Will do. Thanks.
Member
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. Yeah. Follow what @yhuai wrote in the PR https://github.com/apache/spark/pull/10362/files
Contributor
Author
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. Thanks. Just did that as you suggested. |
||
| leftFilter <- translateFilter(left) | ||
| rightFilter <- translateFilter(right) | ||
| } yield sources.And(leftFilter, rightFilter) | ||
|
Contributor
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. do we still need SPARK-12218 after this?
Contributor
Author
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. I would think so. SPARK-12218 put fixes into So this PR does help all data sources to get the correct set of push down predicates. Without this PR we simply got lucky with Parquet and ORC in terms of result correctness because 1) it looks like we always apply JDBC data source does not always come with
Member
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. We do not need to clean up the codes in this PR. Let us minimize the code changes and it can simplify the backport.
Member
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. Although Catalyst predicate expressions are all converted to |
||
|
|
||
| case expressions.Or(left, right) => | ||
| for { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,8 +296,33 @@ class JDBCSuite extends SparkFunSuite | |
| // The older versions of spark have this kind of bugs in parquet data source. | ||
| val df1 = sql("SELECT * FROM foobar WHERE NOT (THEID != 2 AND NAME != 'mary')") | ||
|
||
| val df2 = sql("SELECT * FROM foobar WHERE NOT (THEID != 2) OR NOT (NAME != 'mary')") | ||
| val df3 = sql("SELECT * FROM foobar WHERE (THEID > 0 AND NAME = 'mary') OR (NAME = 'fred')") | ||
| val df4 = sql("SELECT * FROM foobar " + | ||
| "WHERE (THEID > 0 AND TRIM(NAME) = 'mary') OR (NAME = 'fred')") | ||
| val df5 = sql("SELECT * FROM foobar " + | ||
| "WHERE THEID > 0 AND TRIM(NAME) = 'mary' AND LENGTH(NAME) > 3") | ||
| val df6 = sql("SELECT * FROM foobar " + | ||
| "WHERE THEID < 0 OR NAME = 'mary' OR NAME = 'fred'") | ||
| val df7 = sql("SELECT * FROM foobar " + | ||
| "WHERE THEID < 0 OR TRIM(NAME) = 'mary' OR NAME = 'fred'") | ||
| val df8 = sql("SELECT * FROM foobar " + | ||
| "WHERE NOT((THEID < 0 OR NAME != 'mary') AND (THEID != 1 OR NAME != 'fred'))") | ||
| val df9 = sql("SELECT * FROM foobar " + | ||
| "WHERE NOT((THEID < 0 OR NAME != 'mary') AND (THEID != 1 OR TRIM(NAME) != 'fred'))") | ||
| val df10 = sql("SELECT * FROM foobar " + | ||
|
||
| "WHERE (NOT(THEID < 0 OR TRIM(NAME) != 'mary')) OR (THEID = 1 AND NAME = 'fred')") | ||
|
|
||
| assert(df1.collect.toSet === Set(Row("mary", 2))) | ||
| assert(df2.collect.toSet === Set(Row("mary", 2))) | ||
| assert(df3.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df4.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df5.collect.toSet === Set(Row("mary", 2))) | ||
| assert(df6.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df7.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df8.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df9.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
| assert(df10.collect.toSet === Set(Row("fred", 1), Row("mary", 2))) | ||
|
||
|
|
||
|
|
||
| def checkNotPushdown(df: DataFrame): DataFrame = { | ||
| val parentPlan = df.queryExecution.executedPlan | ||
|
|
||
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.
In the comment, you need to give an example to explain why.
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.
Sure. I have added more comments there with an example. Thanks, Sean!
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.
Usually we don't list PR number but just JIRA number is enough.
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.
@viirya I see. Thanks, Simon! I've removed the PR number from the comment.