-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-33538][SQL] Directly push IN/NOT predicates to the Hive Metastore #51132
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
Conversation
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
Outdated
Show resolved
Hide resolved
@@ -749,12 +749,14 @@ private[client] class Shim_v2_0 extends Shim with Logging { | |||
} | |||
} | |||
|
|||
def convertInToOr(name: String, values: Seq[String]): String = { | |||
values.map(value => s"$name = $value").mkString("(", " or ", ")") | |||
def convertInDirectly( |
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.
def convertInDirectly( | |
def convertIn( |
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.
ok
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveShim.scala
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
|
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.
Revert this change
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.
done
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveShim.scala
Outdated
Show resolved
Hide resolved
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveShim.scala
Outdated
Show resolved
Hide resolved
…him.scala Co-authored-by: Yuming Wang <[email protected]>
…him.scala Co-authored-by: Yuming Wang <[email protected]>
@yuexing do you have perf numbers for this change? with which kind/version of backend RDBMS of HMS? |
Blindly replacing Worse performance: IN (...) can skip indexes or change query plans NULL behavior differences: col = NULL vs col IN (NULL) behave differently. Plan caching / cursor sharing changes - affects at least Oracle, SQL Server. May be a lesser issue, but could add up for metastores with high qps. Safer Strategy - only rewrite to IN (...): If there's more than one value. |
Separately, |
hi @Tagar Thanks for commenting, let me reply to those questions; 1st, 'in' predicate with null is already skipped in old code, see
2nd, the conf is already removed following the code review comment. please see newest patch |
@@ -749,12 +749,12 @@ private[client] class Shim_v2_0 extends Shim with Logging { | |||
} | |||
} | |||
|
|||
def convertInToOr(name: String, values: Seq[String]): String = { | |||
values.map(value => s"$name = $value").mkString("(", " or ", ")") | |||
def convertIn(name: String, values: Seq[String]): String = { |
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.
all test passed, friendly ping @wangyum
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.
+1, LGTM
@wangyum Do you need to take another look?
@Tagar spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala Lines 324 to 329 in da67217
|
What changes were proposed in this pull request?
This PR refactors the way IN and NOT IN predicates are converted in
HiveShim
. Previously, these predicates were expanded into chains of OR/AND comparisons (e.g.,a = 1
ora = 2
). This change updates the logic to use SQL-native IN and NOT IN syntax (e.g.,a in (1, 2)
), improving readability and possibly query performance.Why are the changes needed?
Efficiency:
Many SQL engines optimize IN/NOT IN natively, which can improve performance and reduce query complexity.
Maintainability:
Simplifies predicate generation logic, making the codebase easier to maintain and extend.
Does this PR introduce any user-facing change?
No user-facing changes; this is an internal refactor that affects query generation logic.
How was this patch tested?
Existing unit tests for predicate conversion and query generation should be sufficient to cover the updated logic.
Was this patch authored or co-authored using generative AI tooling?
No.