-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-50087] Robust handling of boolean expressions in CASE WHEN for MsSqlServer and future connectors #48621
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 14 commits
7d78be3
7839e1d
0172c49
7ae7397
49d742e
c2001d9
8b1b2da
1f01b77
7e36029
ab79afe
de38a8c
56cea3c
21ec622
468eb89
1bc39ee
6a221c6
ef1bcc8
5d94fa1
f94f8e5
55084a3
7fb6b29
ca0545a
df2fe41
53a4220
cbef9a5
c990ec6
ee4d4fb
6cff9f5
bca7ce8
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 |
|---|---|---|
|
|
@@ -146,4 +146,77 @@ class MsSqlServerIntegrationSuite extends DockerJDBCIntegrationV2Suite with V2JD | |
| |""".stripMargin) | ||
| assert(df.collect().length == 2) | ||
| } | ||
|
|
||
| test("SPARK-50087: SqlServer handle booleans in IF in SELECT test") { | ||
| // This doesn't compile on SqlServer unless result boolean expressions | ||
| // in IF / CASE WHEN are wrapped with a CASE WHEN(<>, 1, 0). | ||
| val df = sql( | ||
| s"""|WITH dummy AS ( | ||
| | SELECT | ||
| | DISTINCT name AS full_name, | ||
| | UPPER(name) AS test_type, | ||
| | name, | ||
| | IF( | ||
| | LOWER(name) = 'legolas' OR LOWER(name) = 'elrond', | ||
| | 'Elf', | ||
| | IF( | ||
| | LOWER(name) = 'gimli' OR LOWER(name) = 'thorin', | ||
| | 'Dwarf', | ||
| | IF( | ||
| | LOWER(name) = 'gandalf' OR LOWER(name) = 'radagast', | ||
| | 'Wizard', | ||
| | LOWER(name) | ||
| | ) | ||
| | ) | ||
| | ) AS test_type_name | ||
| | FROM $catalogName.employee | ||
| |), | ||
| |dummy_new AS ( | ||
| | SELECT * | ||
| | FROM dummy WHERE test_type_name = 'Wizard' | ||
| |) | ||
| |SELECT * FROM dummy_new limit 1""".stripMargin | ||
| ) | ||
| df.collect() | ||
|
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. should we have some pushdown check ?
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'll add an assert with External query check |
||
| } | ||
|
|
||
| test("SPARK-50087: SqlServer handle booleans in CASE WHEN test") { | ||
| val df = sql( | ||
| s"""|SELECT * FROM $catalogName.employee | ||
| |WHERE CASE WHEN name = 'Legolas' THEN name = 'Elf' ELSE NOT (name = 'Wizard') END | ||
| |""".stripMargin | ||
| ) | ||
| df.collect() | ||
| } | ||
|
|
||
| test("SPARK-50087: SqlServer handle booleans in CASE WHEN with always true test") { | ||
| val df = sql( | ||
| s"""|SELECT * FROM $catalogName.employee | ||
| |WHERE CASE WHEN (name = 'Legolas') THEN (name = 'Elf') ELSE (1=1) END | ||
| |""".stripMargin | ||
| ) | ||
| df.collect() | ||
| } | ||
|
|
||
| test("SPARK-50087: SqlServer handle booleans in nested CASE WHEN test") { | ||
| val df = sql( | ||
| s"""|SELECT * FROM $catalogName.employee | ||
| |WHERE CASE WHEN (name = 'Legolas') THEN | ||
| | CASE WHEN (name = 'Elf') THEN (name = 'Elrond') ELSE (name = 'Gandalf') END | ||
| | ELSE (name = 'Sauron') END | ||
| |""".stripMargin | ||
| ) | ||
| df.collect() | ||
| } | ||
|
|
||
| test("SPARK-50087: SqlServer handle non-booleans in nested CASE WHEN test") { | ||
| val df = sql( | ||
| s"""|SELECT * FROM $catalogName.employee | ||
| |WHERE CASE WHEN (name = 'Legolas') THEN | ||
| | CASE WHEN (name = 'Elf') THEN 'Elf' ELSE 'Wizard' END | ||
| | ELSE 'Sauron' END | ||
| |""".stripMargin | ||
| ) | ||
| df.collect() | ||
|
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. im not sure but do we have test case for when type is not boolean ? |
||
| } | ||
| } | ||
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.
does this provide extra test coverage than the following new test cases?
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.
This is a specific edge case. If you use a single IF in a SELECT it won't be pushed down, but this is.