Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28746][SQL] Add partitionby hint for sql queries - #25464
[SPARK-28746][SQL] Add partitionby hint for sql queries#25464ulysses-you wants to merge 20 commits into
Conversation
maropu
commented
Aug 16, 2019
@gatorsmile@maryannxue We need this? |
maryannxue
commented
Aug 21, 2019
I'm not against it, but is it possible to extend the existing "repartition" hint grammar to achieve this? |
maropu
commented
Aug 21, 2019
Yea, that approach looks more reasonable to me. Could you brush up the code based on the suggestion? @ulysses-you |
ulysses-you
commented
Aug 22, 2019
Thanks for review this. Make hint consistent with repartition api is a good idea. |
ulysses-you
commented
Aug 22, 2019
retest this please |
maropu
commented
Aug 23, 2019
ok to test |
SparkQA
commented
Aug 23, 2019
Test build #109600 has finished for PR 25464 at commit
|
| RepartitionByExpression( | ||
| exprs.map(_.asInstanceOf[UnresolvedAttribute]), h.child, numPartitions) | ||
| } | ||
There was a problem hiding this comment.
How about the case, SELECT /*+ REPARTITION(a) */ * FROM t?
| if (errExprs.nonEmpty) throw new AnalysisException( | ||
| s"""Invalid type exprs : $errExprs | ||
| |expects UnresolvedAttribute type | ||
| """.stripMargin) |
There was a problem hiding this comment.
OK, I will add this later.
SparkQA
commented
Aug 23, 2019
Test build #109603 has finished for PR 25464 at commit
|
SparkQA
commented
Aug 23, 2019
Test build #109615 has finished for PR 25464 at commit
|
ulysses-you
commented
Aug 23, 2019
retest this please |
1 similar comment
maropu
commented
Aug 26, 2019
retest this please |
SparkQA
commented
Aug 26, 2019
Test build #109720 has finished for PR 25464 at commit
|
retet this please |
ulysses-you
commented
Aug 27, 2019
retest this please |
maropu
commented
Aug 27, 2019
oh.. typo.. |
maropu
commented
Aug 27, 2019
retest this please |
SparkQA
commented
Oct 25, 2019
Test build #112637 has finished for PR 25464 at commit
|
maropu
commented
Oct 25, 2019
retest this please |
SparkQA
commented
Oct 25, 2019
Test build #112639 has finished for PR 25464 at commit
|
SparkQA
commented
Oct 25, 2019
Test build #112646 has finished for PR 25464 at commit
|
maropu
commented
Oct 28, 2019
retest this please |
maropu
left a comment
There was a problem hiding this comment.
LGTM. Anyone could do final checks? @cloud-fan@HyukjinKwon
SparkQA
commented
Oct 28, 2019
Test build #112749 has finished for PR 25464 at commit
|
| throw new AnalysisException(s"$hintName Hint parameter should include columns, but " + | ||
| s"${invalidParams.mkString(", ")} found") | ||
| } | ||
| RepartitionByExpression( |
There was a problem hiding this comment.
Can we then consistently throw an exception like Dataset.repartition?
valsortOrders= partitionExprs.filter(_.expr.isInstanceOf[SortOrder])
if (sortOrders.nonEmpty) thrownewIllegalArgumentException(
s"""Invalid partitionExprs specified: $sortOrders
|For range partitioning use repartitionByRange(...) instead.""".stripMargin)There was a problem hiding this comment.
Good point, add an IllegalArgumentException check.
SparkQA
commented
Oct 29, 2019
Test build #112849 has finished for PR 25464 at commit
|
maropu
commented
Oct 29, 2019
Thanks for the contribution, @ulysses-you ! Merged to master. |
maropu
commented
Oct 29, 2019
FYI: I added @ulysses-you in the Spark contributor list. |
ulysses-you
commented
Oct 30, 2019
Thanks for great help ! @maropu@HyukjinKwon@cloud-fan@maryannxue |
| createRepartition(shuffle = false, hint) | ||
| case "REPARTITION_BY_RANGE" => | ||
| createRepartitionByRange(hint) | ||
| case _ => plan |
There was a problem hiding this comment.
shouldn't we return hint here? This will cause stack overflow once the hint is not the root node.
There was a problem hiding this comment.
Ah, yes. I will make a followup. Thanks for catching this.
…unknown hint resolution ### What changes were proposed in this pull request? This is rather a followup of #25464 (see https://github.com/apache/spark/pull/25464/files#r349543286) It will cause an infinite recursion via mapping children - we should return the hint rather than its parent plan in unknown hint resolution. ### Why are the changes needed? Prevent Stack over flow during hint resolution. ### Does this PR introduce any user-facing change? Yes, it avoids stack overflow exception It was caused by #25464 and this is only in the master. No behaviour changes to end users as it happened only in the master. ### How was this patch tested? Unittest was added. Closes#26642 from HyukjinKwon/SPARK-30003. Authored-by: HyukjinKwon <gurwls223@apache.org> Signed-off-by: HyukjinKwon <gurwls223@apache.org>
| s"""Invalid partitionExprs specified: $sortOrders | ||
| |For range partitioning use REPARTITION_BY_RANGE instead. | ||
| """.stripMargin) | ||
| val invalidParams = partitionExprs.filter(!_.isInstanceOf[UnresolvedAttribute]) |
There was a problem hiding this comment.
I think this check breaks the old API, in Spark 2.4 it is possible to use an expression here. I think we need to back this out.
There was a problem hiding this comment.
AFAIK 2.4 only supports something like REPARTITION(5), the parameters here means anything after the partition number parameter, e.g. REPARTITION(5, para1, para2, ...)
There was a problem hiding this comment.
Ah ok, you are right. Never the less I think we should support expressions for REPARTITION here.
| def createRepartitionByExpression( | ||
| numPartitions: Int, partitionExprs: Seq[Any]): RepartitionByExpression = { | ||
| val sortOrders = partitionExprs.filter(_.isInstanceOf[SortOrder]) | ||
| if (sortOrders.nonEmpty) throw new IllegalArgumentException( |
There was a problem hiding this comment.
Style, please put this inside curly braces and on a new line.
There was a problem hiding this comment.
@ulysses-you Could you do follow-up for the two comments from @hvanhovell ?
There was a problem hiding this comment.
Actually it might be better to just handle this later when we happen to touch this codes given that we don't usually make followups for minor styles issues.
| def createRepartitionByExpression( | ||
| numPartitions: Int, partitionExprs: Seq[Any]): RepartitionByExpression = { | ||
| val invalidParams = partitionExprs.filter(!_.isInstanceOf[UnresolvedAttribute]) |
What changes were proposed in this pull request?
Now,
RepartitionByExpressionis allowed at Dataset methodDataset.repartition(). But in spark sql, we do not have an equivalent functionality.In hive, we can use
distribute by, so it's worth to add a hint to support such function.Similar jira SPARK-24940
Why are the changes needed?
Make repartition hints consistent with repartition api .
Does this PR introduce any user-facing change?
This pr intends to support quries below;
How was this patch tested?
UT