spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viirya <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-7937][SQL] Support comparison on Struct...
Date Thu, 04 Jun 2015 13:18:35 GMT
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6519#discussion_r31718403
  
    --- 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 --
    
    Good point. I will update this later.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message