-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28746][SQL] Add partitionby hint for sql queries #25464
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 10 commits
b259859
33a8b0e
5c7e871
ebe9220
4f06914
bed289e
67ce5d5
c204ce3
c57805b
4fbf34a
b0ae689
18ed232
5cc98b7
4182994
62f8c4f
8af48d3
507735c
e5eb369
44aa0b8
4ac7eb6
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 |
|---|---|---|
|
|
@@ -143,22 +143,41 @@ object ResolveHints { | |
| object ResolveCoalesceHints extends Rule[LogicalPlan] { | ||
| private val COALESCE_HINT_NAMES = Set("COALESCE", "REPARTITION") | ||
|
|
||
| private def createRepartitionByExpression( | ||
| numPartitions: Int, parameters: Seq[Any], h: UnresolvedHint): RepartitionByExpression = { | ||
| val exprs = parameters.drop(1) | ||
| val errExprs = exprs.filter(!_.isInstanceOf[UnresolvedAttribute]) | ||
| if (errExprs.nonEmpty) throw new AnalysisException( | ||
| s"""Invalid type exprs : $errExprs | ||
| |expects UnresolvedAttribute type | ||
| """.stripMargin) | ||
|
||
| RepartitionByExpression( | ||
| exprs.map(_.asInstanceOf[UnresolvedAttribute]), h.child, numPartitions) | ||
| } | ||
|
|
||
|
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. How about the case, |
||
| def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperators { | ||
| case h: UnresolvedHint if COALESCE_HINT_NAMES.contains(h.name.toUpperCase(Locale.ROOT)) => | ||
| val hintName = h.name.toUpperCase(Locale.ROOT) | ||
| val shuffle = hintName match { | ||
| case "REPARTITION" => true | ||
| case "COALESCE" => false | ||
| } | ||
| val numPartitions = h.parameters match { | ||
|
|
||
| h.parameters match { | ||
| case Seq(IntegerLiteral(numPartitions)) => | ||
| numPartitions | ||
| Repartition(numPartitions, shuffle, h.child) | ||
| case Seq(numPartitions: Int) => | ||
| numPartitions | ||
| Repartition(numPartitions, shuffle, h.child) | ||
|
|
||
| case param @ Seq(IntegerLiteral(numPartitions), _*) if shuffle => | ||
| createRepartitionByExpression(numPartitions, param, h) | ||
|
||
| case param @ Seq(numPartitions: Int, _*) if shuffle => | ||
| createRepartitionByExpression(numPartitions, param, h) | ||
|
|
||
| case _ => | ||
| throw new AnalysisException(s"$hintName Hint expects a partition number as parameter") | ||
| throw new AnalysisException("Repartition hint expects a partition number " + | ||
|
||
| "and columns") | ||
| } | ||
| Repartition(numPartitions, shuffle, h.child) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
Plz update the description in the top: https://github.com/apache/spark/pull/25464/files#diff-746a6d090224c7cfbe15daa27fa27408R141