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-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org