Uh oh!
There was an error while loading. Please reload this page.
[SPARK-24586][SQL] Upcast should not allow casting from string to other types - #21586
[SPARK-24586][SQL] Upcast should not allow casting from string to other types#21586cloud-fan wants to merge 8 commits into
Conversation
cloud-fan
commented
Jun 18, 2018
SparkQA
commented
Jun 19, 2018
Test build #92052 has finished for PR 21586 at commit
|
maropu
commented
Jun 19, 2018
retest this please |
There was a problem hiding this comment.
Is the error message of thrown AnalysisException valid under this change? Seems it is not just because truncating?
There was a problem hiding this comment.
super nit: fromPrecedence != -1 && fromPrecedence < toPrecedence is more easy-to-understand?
There was a problem hiding this comment.
Seems nullable of StructField can affect the casting decision?
There was a problem hiding this comment.
added support for complex types
SparkQA
commented
Jun 19, 2018
Test build #92059 has finished for PR 21586 at commit
|
…is wrapped in Cast ## What changes were proposed in this pull request? As mentioned in #21586 , `Cast.mayTruncate` is not 100% safe, string to boolean is allowed. Since changing `Cast.mayTruncate` also changes the behavior of Dataset, here I propose to add a new `Cast.canSafeCast` for partition pruning. ## How was this patch tested? new test cases Author: Wenchen Fan <wenchen@databricks.com> Closes#21712 from cloud-fan/safeCast.
SparkQA
commented
Aug 3, 2018
Test build #94103 has finished for PR 21586 at commit
|
cde33ca to
2a64d59CompareSparkQA
commented
Apr 11, 2019
Test build #104512 has finished for PR 21586 at commit
|
SparkQA
commented
Apr 11, 2019
Test build #104510 has finished for PR 21586 at commit
|
SparkQA
commented
Apr 11, 2019
Test build #104518 has finished for PR 21586 at commit
|
SparkQA
commented
Apr 15, 2019
Test build #104589 has finished for PR 21586 at commit
|
cloud-fan
commented
May 15, 2019
retest this please |
SparkQA
commented
May 15, 2019
Test build #105401 has finished for PR 21586 at commit
|
SparkQA
commented
May 15, 2019
Test build #105398 has finished for PR 21586 at commit
|
SparkQA
commented
May 15, 2019
Test build #105400 has finished for PR 21586 at commit
|
SparkQA
commented
May 15, 2019
Test build #105408 has finished for PR 21586 at commit
|
| * precision lose or possible runtime failures. For example, long -> int, string -> int are not | ||
| * up-cast. | ||
| */ | ||
| def mayTruncate(from: DataType, to: DataType): Boolean = (from, to) match { |
There was a problem hiding this comment.
I know this will be ugly, but I still prefer to adding a conf for falling back to the original behavior.
SparkQA
commented
May 17, 2019
Test build #105490 has finished for PR 21586 at commit
|
SparkQA
commented
May 17, 2019
Test build #105486 has finished for PR 21586 at commit
|
SparkQA
commented
May 20, 2019
Test build #105551 has finished for PR 21586 at commit
|
cloud-fan
commented
May 21, 2019
retest this please |
SparkQA
commented
May 21, 2019
Test build #105598 has finished for PR 21586 at commit
|
cloud-fan
commented
May 21, 2019
retest this please |
SparkQA
commented
May 21, 2019
Test build #105618 has finished for PR 21586 at commit
|
cloud-fan
commented
May 22, 2019
thanks, merging to master! |
dongjoon-hyun
commented
May 22, 2019
cc @dbtsai |
| need to specify a value with units like "30s" now, to avoid being interpreted as milliseconds; otherwise, | ||
| the extremely short interval that results will likely cause applications to fail. | ||
| - When turning a Dataset to another Dataset, Spark will up cast the fields in the original Dataset to the type of corresponding fields in the target DataSet. In version 2.4 and earlier, this up cast is not very strict, e.g. `Seq("str").toDS.as[Int]` fails, but `Seq("str").toDS.as[Boolean]` works and throw NPE during execution. In Spark 3.0, the up cast is stricter and turning String into something else is not allowed, i.e. `Seq("str").toDS.as[Boolean]` will fail during analysis. |
There was a problem hiding this comment.
@cloud-fan shall we mention setting spark.sql.legacy.looseUpcast=true to preserve old behavior?
There was a problem hiding this comment.
are you interested in creating a PR (with a new JIRA) to fix the doc? 2.4 is EOL but I think it's good to fix the docs anyway.
What changes were proposed in this pull request?
When turning a Dataset to another Dataset, Spark will up cast the fields in the original Dataset to the type of corresponding fields in the target DataSet.
However, the current upcast behavior is a little weird, we don't allow up casting from string to numeric, but allow non-numeric types as the target, like boolean, date, etc.
As a result,
Seq("str").toDS.as[Int]fails, butSeq("str").toDS.as[Boolean]works and throw NPE during execution.The motivation of the up cast is to prevent things like runtime NPE, it's more reasonable to make up cast stricter.
This PR does 2 things:
Cast.canSafeCasttoCast.canUpcast, and support complex typresCast.mayTruncateand replace it with!Cast.canUpcastNote that, the up cast change also affects persistent view resolution. But since we don't support changing column types of an existing table, there is no behavior change here.
How was this patch tested?
new tests