Github user ericl commented on a diff in the pull request: https://github.com/apache/spark/pull/14842#discussion_r78270169 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SortPrefixUtils.scala --- @@ -40,22 +40,56 @@ object SortPrefixUtils { def getPrefixComparator(sortOrder: SortOrder): PrefixComparator = { sortOrder.dataType match { - case StringType => - if (sortOrder.isAscending) PrefixComparators.STRING else PrefixComparators.STRING_DESC - case BinaryType => - if (sortOrder.isAscending) PrefixComparators.BINARY else PrefixComparators.BINARY_DESC + case StringType => getPrefixComparatorWithNullOrder(sortOrder, "STRING") + case BinaryType => getPrefixComparatorWithNullOrder(sortOrder, "BINARY") case BooleanType | ByteType | ShortType | IntegerType | LongType | DateType | TimestampType => - if (sortOrder.isAscending) PrefixComparators.LONG else PrefixComparators.LONG_DESC + getPrefixComparatorWithNullOrder(sortOrder, "LONG") case dt: DecimalType if dt.precision - dt.scale <= Decimal.MAX_LONG_DIGITS => - if (sortOrder.isAscending) PrefixComparators.LONG else PrefixComparators.LONG_DESC - case FloatType | DoubleType => - if (sortOrder.isAscending) PrefixComparators.DOUBLE else PrefixComparators.DOUBLE_DESC - case dt: DecimalType => - if (sortOrder.isAscending) PrefixComparators.DOUBLE else PrefixComparators.DOUBLE_DESC + getPrefixComparatorWithNullOrder(sortOrder, "LONG") + case FloatType | DoubleType => getPrefixComparatorWithNullOrder(sortOrder, "DOUBLE") + case dt: DecimalType => getPrefixComparatorWithNullOrder(sortOrder, "DOUBLE") case _ => NoOpPrefixComparator } } + private def getPrefixComparatorWithNullOrder( + sortOrder: SortOrder, signedType: String): PrefixComparator = { + sortOrder.direction match { + case Ascending if (sortOrder.nullOrdering == NullLast) => + signedType match { + case "LONG" => PrefixComparators.LONG_NULLLAST --- End diff -- We probably shouldn't use strings here.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org