Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6519#discussion_r31708598
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/TypeUtils.scala 
---
    @@ -41,16 +41,29 @@ object TypeUtils {
       }
     
       def checkForOrderingExpr(t: DataType, caller: String): TypeCheckResult = 
{
    -    if (t.isInstanceOf[AtomicType] || t == NullType) {
    -      TypeCheckResult.TypeCheckSuccess
    -    } else {
    -      TypeCheckResult.TypeCheckFailure(s"$caller accepts non-complex 
types, not $t")
    +    t match {
    +      case i: AtomicType => TypeCheckResult.TypeCheckSuccess
    +      case n: NullType => TypeCheckResult.TypeCheckSuccess
    +      case s: StructType =>
    +        if (s.fields.exists(_.dataType.isInstanceOf[AtomicType])) {
    +          TypeCheckResult.TypeCheckSuccess
    +        } else {
    +          TypeCheckResult.TypeCheckFailure(s"Fields in $s do not support 
ordering")
    +        }
    +      case other => TypeCheckResult.TypeCheckFailure(s"$t doesn't support 
ordering on $caller")
         }
       }
     
       def getNumeric(t: DataType): Numeric[Any] =
         t.asInstanceOf[NumericType].numeric.asInstanceOf[Numeric[Any]]
     
    -  def getOrdering(t: DataType): Ordering[Any] =
    -    t.asInstanceOf[AtomicType].ordering.asInstanceOf[Ordering[Any]]
    +  def getOrdering(t: DataType): Seq[(Ordering[Any], Int)] = {
    +    t match {
    +      case i: AtomicType => 
Seq(i.ordering.asInstanceOf[Ordering[Any]]).zipWithIndex
    +      case s: StructType =>
    +        val atomicFields = 
s.fields.filter(_.dataType.isInstanceOf[AtomicType])
    +        
atomicFields.map(_.dataType.asInstanceOf[AtomicType].ordering.asInstanceOf[Ordering[Any]])
    +            .zipWithIndex
    --- End diff --
    
    Instead of change the return type to `Seq[(Ordering[Any], Int)]`, how about 
we create a `Ordering[Row]` to compare struct?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to