Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21247][SQL] Type comparison should respect case-sensitive SQL conf - #18460
[SPARK-21247][SQL] Type comparison should respect case-sensitive SQL conf#18460dongjoon-hyun wants to merge 9 commits into
Conversation
SparkQA
commented
Jun 29, 2017
Test build #78831 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jun 29, 2017
Retest this please. |
SparkQA
commented
Jun 29, 2017
Test build #78845 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jun 29, 2017
Hi, @hvanhovell . |
dongjoon-hyun
commented
Jun 30, 2017
Hi, @gatorsmile . |
dongjoon-hyun
commented
Jul 3, 2017
Hi, @cloud-fan . |
There was a problem hiding this comment.
maybe we should not consider field names in sameType, @gatorsmile what do you think?
There was a problem hiding this comment.
Oh, that sounds to be a big change. Is there any side-effect to users with JSON and Parquet?
There was a problem hiding this comment.
May we have some cases that we do care about field names in sameType? To completely ignore it in sameType seems risky?
dongjoon-hyun
commented
Jul 5, 2017
Hi, @cloud-fan and @gatorsmile . |
SparkQA
commented
Jul 5, 2017
Test build #79192 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 5, 2017
Retest this please . |
SparkQA
commented
Jul 5, 2017
Test build #79201 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 5, 2017
Retest this please |
SparkQA
commented
Jul 5, 2017
Test build #79226 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 5, 2017
Hi, @cloud-fan and @gatorsmile . |
There was a problem hiding this comment.
Since we already have DataType.equalsIgnoreCaseAndNullability, we can use this according to the SQL configuration.
dongjoon-hyun
commented
Jul 6, 2017
Hi, @hvanhovell . |
There was a problem hiding this comment.
We should follow the ArrayType case and update the nullability.
There was a problem hiding this comment.
How can we handle metadata?
There was a problem hiding this comment.
is <i long> a wider type of <i int>? can we check with Hive?
There was a problem hiding this comment.
Sorry for making this confused.
I added the comment in the test.
StructType does not widen the types, but supports case-sensitive options.
This line are guarded by if st1.sameType(st2). So, we always have the same dataType.
The reason to use findWiderTypeForTwo is to get the final nested complex type with the new nullability.
Also, this function is findWiderTypeForTwo.
There was a problem hiding this comment.
For Hive, it's the same.
hive> select * from t1 union all select * from t2;
FAILED: SemanticException 1:41 Schema of both sides of union should match: Column _c0 is of type struct<a:int> on first table and type struct<a:bigint> on second table. Error encountered near token 't2'
SparkQA
commented
Jul 6, 2017
Test build #79275 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 6, 2017
Rebased to the master to resolve conflicts. |
SparkQA
commented
Jul 6, 2017
Test build #79295 has finished for PR 18460 at commit
|
SparkQA
commented
Jul 7, 2017
Test build #79319 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 7, 2017
Retest this please. |
SparkQA
commented
Jul 7, 2017
Test build #79322 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 7, 2017
Rebased to resolve conflicts. |
SparkQA
commented
Jul 7, 2017
Test build #79338 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Jul 7, 2017
Hi, @cloud-fan and @gatorsmile and @viirya . |
dongjoon-hyun
commented
Jul 8, 2017
Hi, @cloud-fan and @gatorsmile . |
There was a problem hiding this comment.
Shall we also do this in findWiderTypeWithoutStringPromotionForTwo?
dongjoon-hyun
commented
Oct 6, 2017
The test cases are added. Thank you, @gatorsmile ! |
SparkQA
commented
Oct 6, 2017
Test build #82523 has finished for PR 18460 at commit
|
SparkQA
commented
Oct 6, 2017
Test build #82527 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Oct 8, 2017
When you have a chance, could you review this please, @gatorsmile ? |
dongjoon-hyun
commented
Oct 8, 2017
Retest this please. |
SparkQA
commented
Oct 8, 2017
Test build #82544 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Oct 9, 2017
Gentle ping~, @gatorsmile . :) |
dongjoon-hyun
commented
Oct 10, 2017
Hi, @gatorsmile . |
| // - Different nullabilities: `nullable` is true iff one of them is nullable. | ||
| val name = if (f1.name == f2.name) f1.name else f1.name.toLowerCase(Locale.ROOT) | ||
| val dataType = findTightestCommonType(f1.dataType, f2.dataType).get | ||
| StructField(name, dataType, nullable = f1.nullable || f2.nullable) |
There was a problem hiding this comment.
Should we follow what we are doing for union/except/intersect? Always pick the name of the head one?
There was a problem hiding this comment.
See the example,
sql("SELECT 1 as a UNION ALL (SELECT 1 as A)").show()
sql("SELECT 1 as A UNION ALL (SELECT 1 as a)").show()There was a problem hiding this comment.
This PR works as you want. This function is used to compare the equality only. BTW, for this function, it should use one of lower or upper case because it should be commutative.
scala> sql("SELECT struct(1 a) UNION ALL (SELECT struct(2 A))").printSchema
root
|-- named_struct(a, 1 AS `a`): struct (nullable = false)
| |-- a: integer (nullable = false)
scala> sql("SELECT struct(1 A) UNION ALL (SELECT struct(2 a))").printSchema
root
|-- named_struct(A, 1 AS `A`): struct (nullable = false)
| |-- A: integer (nullable = false)
There was a problem hiding this comment.
val name = if (f1.name == f2.name) f1.name else f1.name.toLowerCase(Locale.ROOT)
The above code changes the case, right?
There was a problem hiding this comment.
Sure, right. It's for commutativity.
There was a problem hiding this comment.
Please see TypeCoercionSuite.checkWidenType.
In order to use the first type name, we need to loosen this test helper function and to break the existing commutative assumption. I'm ok for that if you want.
dongjoon-hyun
commented
Oct 11, 2017
Please let me know if there is something to do more~ Thank you always, @gatorsmile . |
| t2: DataType, | ||
| expected: Option[DataType]): Unit = { | ||
| expected: Option[DataType], | ||
| isSymmetric: Boolean = true): Unit = { |
There was a problem hiding this comment.
@gatorsmile . I extended this function for using non-symmetric tests and addressed your comments.
SparkQA
commented
Oct 11, 2017
Test build #82647 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Oct 11, 2017
It seems to be an irrelevant Python failure. |
dongjoon-hyun
commented
Oct 11, 2017
Retest this please. |
SparkQA
commented
Oct 12, 2017
Test build #82649 has finished for PR 18460 at commit
|
dongjoon-hyun
commented
Oct 12, 2017
Thanks you, @gatorsmile . Now, it's simplified more. |
dongjoon-hyun
commented
Oct 13, 2017
Hi, @gatorsmile and @cloud-fan . |
gatorsmile
commented
Oct 13, 2017
LGTM cc @cloud-fan |
gatorsmile
commented
Oct 13, 2017
BTW, we are unable to merge this to Spark 2.2 although this is a bug fix. |
dongjoon-hyun
commented
Oct 13, 2017
Thank you, @gatorsmile . Sure, I agree. |
cloud-fan
commented
Oct 13, 2017
LGTM, merging to master! |
dongjoon-hyun
commented
Oct 13, 2017
Thank you, @cloud-fan , @gatorsmile , and @viirya !!! |
What changes were proposed in this pull request?
This is an effort to reduce the difference between Hive and Spark. Spark supports case-sensitivity in columns. Especially, for Struct types, with
spark.sql.caseSensitive=true, the following is supported.And vice versa, with
spark.sql.caseSensitive=false, the following is supported.However, types are considered different. For example, SET operations fail.
This PR aims to support case-insensitive type equality. For example, in Set operation, the above operation succeed when
spark.sql.caseSensitive=false.How was this patch tested?
Pass the Jenkins with a newly add test case.