[SPARK-28495][SQL] Introduce ANSI store assignment policy for table insertion#25581
Closed
gengliangwang wants to merge 6 commits into
Closed
[SPARK-28495][SQL] Introduce ANSI store assignment policy for table insertion#25581gengliangwang wants to merge 6 commits into
gengliangwang wants to merge 6 commits into
Conversation
|
Test build #109731 has finished for PR 25581 at commit
|
cloud-fan
reviewed
Aug 26, 2019
cloud-fan
reviewed
Aug 26, 2019
| byName: Boolean, | ||
| resolver: Resolver, | ||
| context: String, | ||
| storeAssignmentPolicy: StoreAssignmentPolicy.Value, |
Contributor
There was a problem hiding this comment.
maybe pass in a boolean flag isStrict?
Member
Author
There was a problem hiding this comment.
I think keeping the original policy is also fine. Otherwise, it is hard to tell that we are using ANSI mode if isStrict is false.
|
Test build #109738 has finished for PR 25581 at commit
|
|
Test build #109739 has finished for PR 25581 at commit
|
|
Test build #109743 has finished for PR 25581 at commit
|
cloud-fan
reviewed
Aug 27, 2019
cloud-fan
reviewed
Aug 27, 2019
|
|
||
| protected def storeAssignmentPolicy: StoreAssignmentPolicy.Value | ||
|
|
||
| def assertAllowed( |
Contributor
There was a problem hiding this comment.
it looks to me that, we can make the code simpler if this method takes the policy parameter. e.g.
test("Check atomic types: write allowed only when casting is safe") {
atomicTypes.foreach { w =>
atomicTypes.foreach { r =>
if (Cast.canUpCast(w, r)) {
assertAllowed(Policy.STRICT, ...)
} else {
assertSingleError(Policy.STRICT, ...)
}
if (Cast.canANSIStoreAssign(w, r)) ...
}
}
}
cloud-fan
reviewed
Aug 27, 2019
cloud-fan
approved these changes
Aug 27, 2019
|
Test build #109808 has finished for PR 25581 at commit
|
Contributor
|
thanks, merging to master! |
cloud-fan
pushed a commit
that referenced
this pull request
Aug 29, 2019
…and long in ASNI mode ### What changes were proposed in this pull request? Disallow conversions between `timestamp` type and `long` type in table insertion with ANSI store assignment policy. ### Why are the changes needed? In the PR #25581, timestamp type is allowed to be converted to long type, since timestamp type is represented by long type internally, and both legacy mode and strict mode allows the conversion. After reconsideration, I think we should disallow it. As per ANSI SQL section "4.4.2 Characteristics of numbers": > A number is assignable only to sites of numeric type. In PostgreSQL, the conversion between timestamp and long is also disallowed. ### Does this PR introduce any user-facing change? Conversion between timestamp and long is disallowed in table insertion with ANSI store assignment policy. ### How was this patch tested? Unit test Closes #25615 from gengliangwang/disallowTimeStampToLong. Authored-by: Gengliang Wang <gengliang.wang@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
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
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?
Introduce ANSI store assignment policy for table insertion.
With ANSI policy, Spark performs the type coercion of table insertion as per ANSI SQL.
Why are the changes needed?
In Spark version 2.4 and earlier, when inserting into a table, Spark will cast the data type of input query to the data type of target table by coercion. This can be super confusing, e.g. users make a mistake and write string values to an int column.
In data source V2, by default, only upcasting is allowed when inserting data into a table. E.g. int -> long and int -> string are allowed, while decimal -> double or long -> int are not allowed. The rules of UpCast was originally created for Dataset type coercion. They are quite strict and different from the behavior of all existing popular DBMS. This is breaking change. It is possible that existing queries are broken after 3.0 releases.
Following ANSI SQL standard makes Spark consistent with the table insertion behaviors of popular DBMS like PostgreSQL/Oracle/Mysql.
Does this PR introduce any user-facing change?
A new optional mode for table insertion.
How was this patch tested?
Unit test