Github user kiszk commented on a diff in the pull request: https://github.com/apache/spark/pull/21231#discussion_r186022301 --- 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 + override def eval(input: InternalRow): Any = { + val value = child.child.eval(input) + if (value == null) { + return null + } + val prefix = child.child.dataType match { + case BooleanType => + if (value.asInstanceOf[Boolean]) 1L else 0L + case _: IntegralType => + value.asInstanceOf[java.lang.Number].longValue() + case DateType | TimestampType => + value.asInstanceOf[java.lang.Number].longValue() + case FloatType | DoubleType => + val dVal = value.asInstanceOf[java.lang.Number].doubleValue() + DoublePrefixComparator.computePrefix(dVal) + case StringType => + StringPrefixComparator.computePrefix(value.asInstanceOf[UTF8String]) + case BinaryType => + BinaryPrefixComparator.computePrefix(value.asInstanceOf[Array[Byte]]) + case dt: DecimalType if dt.precision - dt.scale <= Decimal.MAX_LONG_DIGITS => + val dtValue = value.asInstanceOf[Decimal] + if (dt.precision <= Decimal.MAX_LONG_DIGITS) { + dtValue.toUnscaledLong + } else { + val p = Decimal.MAX_LONG_DIGITS + val s = p - (dt.precision - dt.scale) + if (dtValue.changePrecision(p, s)) dtValue.toUnscaledLong else Long.MinValue + } + case dt: DecimalType => + val dtValue = value.asInstanceOf[Decimal].toDouble + DoublePrefixComparator.computePrefix(dtValue) + } + prefix --- End diff -- Would it be possible to remove `prefix` and `val prefix = ` to directly return the value of the block?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org