-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-51805] [SQL] Get function with improper argument should throw proper exception instead of an internal one #50590
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
Conversation
MaxGekk
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.
Could you address another types of null:
spark-sql (default)> SELECT get(cast(null as string), 0);
[INTERNAL_ERROR] The Spark SQL phase analysis failed with an internal error. You hit a bug in Spark or the Spark plugins you use. Please, report this bug to the corresponding communities or vendors, and provide the full stack trace. SQLSTATE: XX000
sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Outdated
Show resolved
Hide resolved
sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Outdated
Show resolved
Hide resolved
|
After offline discussion with @srielau we agreed that throwing is the way to go to make it on par with |
5cc7a9d to
069d411
Compare
|
@MaxGekk PTAL when you have time. Thanks |
...atalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
Outdated
Show resolved
Hide resolved
...atalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala
Outdated
Show resolved
Hide resolved
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
Outdated
Show resolved
Hide resolved
|
@MaxGekk PTAL when you have time. Thanks |
|
|
||
| override def checkInputDataTypes(): TypeCheckResult = { | ||
| (left.dataType, right.dataType) match { | ||
| case (_: ArrayType, e2) if !e2.isInstanceOf[IntegralType] => |
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.
do we have a test to examine this branch?
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.
Yes, they have existed before (please check array.sql). But on the other hand select get(array(1),null) passes because GetArrayItem extends ExpectsInputTypes and because of that NullType is casted to IntegerType. Should we remove this check as it is noop?
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.
I would keep it for safety (so we don't throw internal error if we somehow fail to apply type coercion rule). @cloud-fan
|
thanks, merging to master! |
…roper exception instead of an internal one ### What changes were proposed in this pull request? Following query throw `Cannot cast NullType to Arraytype`: ``` SELECT get(null, 0); ``` instead of throwing a more user friendly one. I propose that we fix that. ### Why are the changes needed? To correct behavior of `get` function. ### Does this PR introduce _any_ user-facing change? Query that were failing with internal error are now throwing a more user friendly one. ### How was this patch tested? Added tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#50590 from mihailoale-db/getnull. Authored-by: mihailoale-db <mihailo.aleksic@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
What changes were proposed in this pull request?
Following query throw
Cannot cast NullType to Arraytype:instead of throwing a more user friendly one. I propose that we fix that.
Why are the changes needed?
To correct behavior of
getfunction.Does this PR introduce any user-facing change?
Query that were failing with internal error are now throwing a more user friendly one.
How was this patch tested?
Added tests.
Was this patch authored or co-authored using generative AI tooling?
No.