Github user rdblue commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21911#discussion_r206740826
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveHints.scala
 ---
    @@ -102,6 +104,39 @@ object ResolveHints {
         }
       }
     
    +  /**
    +   * For coalesce hint, we accept "COALESCE" and "REPARTITION".
    +   * Its parameters include a partition number and an optional boolean to 
indicate
    +   * whether shuffle is allowed.
    +   */
    +  class ResolveCoalesceHints(conf: SQLConf) extends Rule[LogicalPlan] {
    +    private val COALESCE_HINT_NAMES = Set("COALESCE", "REPARTITION")
    +
    +    private def applyCoalesceHint(
    +      plan: LogicalPlan,
    +      numPartitions: Int,
    +      shuffle: Boolean): LogicalPlan = {
    +      Repartition(numPartitions, shuffle, plan)
    +    }
    +
    +    def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperators {
    +      case h: UnresolvedHint if 
COALESCE_HINT_NAMES.contains(h.name.toUpperCase(Locale.ROOT)) =>
    +        h.parameters match {
    +          case Seq(Literal(i, IntegerType)) =>
    +            val defaultShuffle = h.name.toUpperCase(Locale.ROOT) match {
    +              case "REPARTITION" => true
    +              case _ => false
    +            }
    +            applyCoalesceHint(h.child, i.asInstanceOf[Int], defaultShuffle)
    --- End diff --
    
    Instead of casting, this should add the expected type to the pattern match.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to