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

    https://github.com/apache/spark/pull/14842#discussion_r77143025
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SortPrefixUtils.scala ---
    @@ -40,29 +40,64 @@ 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
    +          case "STRING" => PrefixComparators.STRING_NULLLAST
    +          case "BINARY" => PrefixComparators.BINARY_NULLLAST
    +          case "DOUBLE" => PrefixComparators.DOUBLE_NULLLAST
    +        }
    +      case Ascending =>
    +        // or the default NULLS FIRST
    +        signedType match {
    +          case "LONG" => PrefixComparators.LONG
    +          case "STRING" => PrefixComparators.STRING
    +          case "BINARY" => PrefixComparators.BINARY
    +          case "DOUBLE" => PrefixComparators.DOUBLE
    +        }
    +      case Descending if (sortOrder.nullOrdering == NullFirst) =>
    +        signedType match {
    +          case "LONG" => PrefixComparators.LONG_DESC_NULLFIRST
    +          case "STRING" => PrefixComparators.STRING_DESC_NULLFIRST
    +          case "BINARY" => PrefixComparators.BINARY_DESC_NULLFIRST
    +          case "DOUBLE" => PrefixComparators.DOUBLE_DESC_NULLFIRST
    +        }
    +      case Descending =>
    +        // or the default NULLS LAST
    +        signedType match {
    +          case "LONG" => PrefixComparators.LONG_DESC
    +          case "STRING" => PrefixComparators.STRING_DESC
    +          case "BINARY" => PrefixComparators.BINARY_DESC
    +          case "DOUBLE" => PrefixComparators.DOUBLE_DESC
    +        }
    +      case _ => throw new IllegalArgumentException(
    +        "This should not happen. Contact Spark contributors for this 
error.")
    +    }
    +  }
    +
       /**
        * Creates the prefix comparator for the first field in the given 
schema, in ascending order.
        */
       def getPrefixComparator(schema: StructType): PrefixComparator = {
         if (schema.nonEmpty) {
           val field = schema.head
    -      getPrefixComparator(SortOrder(BoundReference(0, field.dataType, 
field.nullable), Ascending))
    +      getPrefixComparator(
    --- End diff --
    
    revert this.


---
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

Reply via email to