HyukjinKwon commented on a change in pull request #25464: [SPARK-28746][SQL]
Add partitionby hint for sql queries
URL: https://github.com/apache/spark/pull/25464#discussion_r339968518
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveHints.scala
##########
@@ -137,31 +137,96 @@ object ResolveHints {
}
/**
- * COALESCE Hint accepts name "COALESCE" and "REPARTITION".
- * Its parameter includes a partition number.
+ * COALESCE Hint accepts names "COALESCE", "REPARTITION", and
"REPARTITION_BY_RANGE".
*/
- object ResolveCoalesceHints extends Rule[LogicalPlan] {
- private val COALESCE_HINT_NAMES = Set("COALESCE", "REPARTITION")
+ class ResolveCoalesceHints(conf: SQLConf) extends Rule[LogicalPlan] {
+
+ /**
+ * This function handles hints for "COALESCE" and "REPARTITION".
+ * The "COALESCE" hint only has a partition number as a parameter. The
"REPARTITION" hint
+ * has a partition number, columns, or both of them as parameters.
+ */
+ private def createRepartition(
+ shuffle: Boolean, hint: UnresolvedHint): LogicalPlan = {
+ val hintName = hint.name.toUpperCase(Locale.ROOT)
+
+ def createRepartitionByExpression(
+ numPartitions: Int, partitionExprs: Seq[Any]):
RepartitionByExpression = {
+ val invalidParams =
partitionExprs.filter(!_.isInstanceOf[UnresolvedAttribute])
+ if (invalidParams.nonEmpty) {
+ throw new AnalysisException(s"$hintName Hint parameter should
include columns, but " +
+ s"${invalidParams.mkString(", ")} found")
+ }
+ RepartitionByExpression(
Review comment:
Can we then consistently throw an exception like `Dataset.repartition`?
```scala
val sortOrders = partitionExprs.filter(_.expr.isInstanceOf[SortOrder])
if (sortOrders.nonEmpty) throw new IllegalArgumentException(
s"""Invalid partitionExprs specified: $sortOrders
|For range partitioning use repartitionByRange(...) instead.
""".stripMargin)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]