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 #21231: [SPARK-24119][SQL]Add interpreted execution to So...
Date Wed, 09 May 2018 03:56:11 GMT
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/21231#discussion_r186925349
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/SortOrder.scala
---
    @@ -147,7 +148,40 @@ 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 DateType | TimestampType | _: IntegralType => (raw) =>
    +      raw.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 <= Decimal.MAX_LONG_DIGITS =>
    +      _.asInstanceOf[Decimal].toUnscaledLong
    +    case dt: DecimalType if dt.precision - dt.scale <= Decimal.MAX_LONG_DIGITS =>
(raw) => {
    +      val value = raw.asInstanceOf[Decimal]
    +      val p = Decimal.MAX_LONG_DIGITS
    +      val s = p - (dt.precision - dt.scale)
    --- End diff --
    
    This is a nit but we can move L168 & L169 out of closure too. Like:
    ```scala
    case dt: DecimalType if dt.precision - dt.scale <= Decimal.MAX_LONG_DIGITS =>
      val p = Decimal.MAX_LONG_DIGITS
      val s = p - (dt.precision - dt.scale)
      (raw) => {
        val value = raw.asInstanceOf[Decimal]
        if (value.changePrecision(p, s)) value.toUnscaledLong else Long.MinValue
      }
    ```


---

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


Mime
View raw message