ulysses-you 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_r318514500
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveHints.scala
 ##########
 @@ -137,28 +137,83 @@ object ResolveHints {
   }
 
   /**
-   * COALESCE Hint accepts name "COALESCE" and "REPARTITION".
-   * Its parameter includes a partition number.
+   * COALESCE Hint accepts name "COALESCE" and "REPARTITION" and 
"REPARTITIONBYRANGE".
+   * Its parameter includes a partition number and columns.
    */
   object ResolveCoalesceHints extends Rule[LogicalPlan] {
-    private val COALESCE_HINT_NAMES = Set("COALESCE", "REPARTITION")
+    private val COALESCE_HINT_NAMES = Set("COALESCE", "REPARTITION", 
"REPARTITIONBYRANGE")
+
+    /**
+     * same with repartition api
+     */
+    private def createRepartition(
+        shuffle: Boolean, h: UnresolvedHint): LogicalPlan = {
+      def createRepartitionByExpression(
+           numPartitions: Int, exprs: Seq[Any], h: UnresolvedHint): 
RepartitionByExpression = {
+        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)
+      }
+
+      h.parameters match {
+        case Seq(IntegerLiteral(numPartitions)) =>
+          Repartition(numPartitions, shuffle, h.child)
+        case Seq(numPartitions: Int) =>
+          Repartition(numPartitions, shuffle, h.child)
+
+        case param @ Seq(IntegerLiteral(numPartitions), _*) if shuffle =>
+          createRepartitionByExpression(numPartitions, param.tail, h)
+        case param @ Seq(numPartitions: Int, _*) if shuffle =>
+          createRepartitionByExpression(numPartitions, param.tail, h)
+
+        case _ =>
+          throw new AnalysisException(s"${h.name} hint expects a partition 
number " +
+            "and columns")
+      }
+    }
+
+    /**
+     * same with repartitionByRange api
+     */
+    private def createRepartitionByRange(
 
 Review comment:
   Deal with `repartitionByRange` separately, same as 
`Dataset.repartitionByRange()`.

----------------------------------------------------------------
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]

Reply via email to