-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-49200][SQL] Fix null type non-codegen ordering exception #47707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+13
−3
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
cc @yaooqinn @cloud-fan thank you |
cloud-fan
approved these changes
Aug 12, 2024
Contributor
cloud-fan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
ulysses-you
added a commit
that referenced
this pull request
Aug 12, 2024
### What changes were proposed in this pull request?
Spark mark `NullType` as orderable, and we return 0 when gen comparing code for `NullType`.
```
object OrderUtils {
def isOrderable(dataType: DataType): Boolean = dataType match {
case NullType => true
```
This pr makes `NullType` ordering work for non-codegen path to avoid exception.
### Why are the changes needed?
Fix exception:
```sql
set spark.sql.codegen.factoryMode=NO_CODEGEN;
set spark.sql.optimizer.excludedRules=org.apache.spark.sql.catalyst.optimizer.EliminateSorts;
select * from range(10) order by array(null);
```
```
org.apache.spark.SparkIllegalArgumentException: Type PhysicalNullType does not support ordered operations.
at org.apache.spark.sql.errors.QueryExecutionErrors$.orderedOperationUnsupportedByDataTypeError(QueryExecutionErrors.scala:352)
at org.apache.spark.sql.catalyst.types.PhysicalNullType.ordering(PhysicalDataType.scala:246)
at org.apache.spark.sql.catalyst.types.PhysicalNullType.ordering(PhysicalDataType.scala:243)
at org.apache.spark.sql.catalyst.types.PhysicalArrayType$$anon$1.<init>(PhysicalDataType.scala:283)
at org.apache.spark.sql.catalyst.types.PhysicalArrayType.interpretedOrdering$lzycompute(PhysicalDataType.scala:281)
at org.apache.spark.sql.catalyst.types.PhysicalArrayType.interpretedOrdering(PhysicalDataType.scala:281)
at org.apache.spark.sql.catalyst.types.PhysicalArrayType.ordering(PhysicalDataType.scala:277)
at org.apache.spark.sql.catalyst.expressions.InterpretedOrdering.compare(ordering.scala:67)
at org.apache.spark.sql.catalyst.expressions.InterpretedOrdering.compare(ordering.scala:40)
at org.apache.spark.sql.execution.UnsafeExternalRowSorter$RowComparator.compare(UnsafeExternalRowSorter.java:254)
at org.apache.spark.util.collection.unsafe.sort.UnsafeInMemorySorter$SortComparator.compare(UnsafeInMemorySorter.java:70)
at org.apache.spark.util.collection.unsafe.sort.UnsafeInMemorySorter$SortComparator.compare(UnsafeInMemorySorter.java:44)
```
### Does this PR introduce _any_ user-facing change?
yes, bug fix
### How was this patch tested?
add test
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #47707 from ulysses-you/null-ordering.
Authored-by: ulysses-you <[email protected]>
Signed-off-by: youxiduo <[email protected]>
(cherry picked from commit e3ba74b)
Signed-off-by: youxiduo <[email protected]>
Contributor
Author
|
thanks, merged to master/branch-3.5 |
Member
|
Late LGTM |
Contributor
|
late LGTM |
turboFei
pushed a commit
to turboFei/spark
that referenced
this pull request
Nov 6, 2025
…he#543) ### What changes were proposed in this pull request? Spark mark `NullType` as orderable, and we return 0 when gen comparing code for `NullType`. ``` object OrderUtils { def isOrderable(dataType: DataType): Boolean = dataType match { case NullType => true ``` This pr makes `NullType` ordering work for non-codegen path to avoid exception. ### Why are the changes needed? Fix exception: ```sql set spark.sql.codegen.factoryMode=NO_CODEGEN; set spark.sql.optimizer.excludedRules=org.apache.spark.sql.catalyst.optimizer.EliminateSorts; select * from range(10) order by array(null); ``` ``` org.apache.spark.SparkIllegalArgumentException: Type PhysicalNullType does not support ordered operations. at org.apache.spark.sql.errors.QueryExecutionErrors$.orderedOperationUnsupportedByDataTypeError(QueryExecutionErrors.scala:352) at org.apache.spark.sql.catalyst.types.PhysicalNullType.ordering(PhysicalDataType.scala:246) at org.apache.spark.sql.catalyst.types.PhysicalNullType.ordering(PhysicalDataType.scala:243) at org.apache.spark.sql.catalyst.types.PhysicalArrayType$$anon$1.<init>(PhysicalDataType.scala:283) at org.apache.spark.sql.catalyst.types.PhysicalArrayType.interpretedOrdering$lzycompute(PhysicalDataType.scala:281) at org.apache.spark.sql.catalyst.types.PhysicalArrayType.interpretedOrdering(PhysicalDataType.scala:281) at org.apache.spark.sql.catalyst.types.PhysicalArrayType.ordering(PhysicalDataType.scala:277) at org.apache.spark.sql.catalyst.expressions.InterpretedOrdering.compare(ordering.scala:67) at org.apache.spark.sql.catalyst.expressions.InterpretedOrdering.compare(ordering.scala:40) at org.apache.spark.sql.execution.UnsafeExternalRowSorter$RowComparator.compare(UnsafeExternalRowSorter.java:254) at org.apache.spark.util.collection.unsafe.sort.UnsafeInMemorySorter$SortComparator.compare(UnsafeInMemorySorter.java:70) at org.apache.spark.util.collection.unsafe.sort.UnsafeInMemorySorter$SortComparator.compare(UnsafeInMemorySorter.java:44) ``` ### Does this PR introduce _any_ user-facing change? yes, bug fix ### How was this patch tested? add test ### Was this patch authored or co-authored using generative AI tooling? no Closes apache#47707 from ulysses-you/null-ordering. Authored-by: ulysses-you <[email protected]> (cherry picked from commit e3ba74b) Signed-off-by: youxiduo <[email protected]> Co-authored-by: ulysses-you <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Spark mark
NullTypeas orderable, and we return 0 when gen comparing code forNullType.This pr makes
NullTypeordering work for non-codegen path to avoid exception.Why are the changes needed?
Fix exception:
Does this PR introduce any user-facing change?
yes, bug fix
How was this patch tested?
add test
Was this patch authored or co-authored using generative AI tooling?
no