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

    https://github.com/apache/spark/pull/21231#discussion_r186668643
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SortOrder.scala
 ---
    @@ -147,7 +148,44 @@ case class SortPrefix(child: SortOrder) extends 
UnaryExpression {
           (!child.isAscending && child.nullOrdering == NullsLast)
       }
     
    -  override def eval(input: InternalRow): Any = throw new 
UnsupportedOperationException
    +  private lazy val calcPrefix: Any => Long = child.child.dataType match {
    +    case BooleanType => (raw) =>
    +      if (raw.asInstanceOf[Boolean]) 1 else 0
    +    case _: IntegralType => (raw) =>
    +      raw.asInstanceOf[java.lang.Number].longValue()
    +    case DateType | TimestampType =>
    +      _.asInstanceOf[java.lang.Number].longValue()
    +    case FloatType | DoubleType => (raw) => {
    +      val dVal = raw.asInstanceOf[java.lang.Number].doubleValue()
    +      DoublePrefixComparator.computePrefix(dVal)
    +    }
    +    case StringType => (raw) =>
    +      StringPrefixComparator.computePrefix(raw.asInstanceOf[UTF8String])
    +    case BinaryType => (raw) =>
    +      BinaryPrefixComparator.computePrefix(raw.asInstanceOf[Array[Byte]])
    +    case dt: DecimalType if dt.precision - dt.scale <= 
Decimal.MAX_LONG_DIGITS => (raw) => {
    +      val value = raw.asInstanceOf[Decimal]
    +      if (dt.precision <= Decimal.MAX_LONG_DIGITS) {
    --- End diff --
    
    Can we split this into two function closures? No need to do this at runtime.


---

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

Reply via email to