Uh oh!
There was an error while loading. Please reload this page.
[SPARK-21646][SQL] Add new type coercion to compatible with Hive - #18853
[SPARK-21646][SQL] Add new type coercion to compatible with Hive#18853wangyum wants to merge 25 commits into
Conversation
SparkQA
commented
Aug 5, 2017
Test build #80286 has finished for PR 18853 at commit
|
maropu
commented
Aug 7, 2017
How about casting the |
wangyum
commented
Aug 7, 2017
Casting the |
wangyum
commented
Aug 7, 2017
retest this please |
SparkQA
commented
Aug 7, 2017
Test build #80339 has finished for PR 18853 at commit
|
| p.makeCopy(Array(left, Cast(right, TimestampType))) | ||
| case p @ BinaryComparison(left, right) | ||
| if left.isInstanceOf[AttributeReference] && right.isInstanceOf[Literal] => |
There was a problem hiding this comment.
We need to cover all the same cases, but it seems this fix couldn't do, for example;
scala> spark.udf.register("testUdf", () => "85908509832958239058032")
scala> sql("select * from values (1) where testUdf() > 1").explain
== Physical Plan ==
*Filter (cast(UDF:testUdf() as int) > 1)
+- LocalTableScan [col1#104]
wangyum
commented
Aug 12, 2017
Thanks @maropu, There are some problems: So |
maropu
commented
Aug 14, 2017
If we change this behaviour, I think we better modify code in As another option, we could cast |
gatorsmile
commented
Aug 15, 2017
Currently, the type casting has a few issues when types are different. So far, we do not have any good option to resolve all the issues. Thus, we are hesitant to introduce any behavior change unless this is well defined. Could you do a research to see how the others behave? Any rule? |
# Conflicts: # sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
SparkQA
commented
Sep 10, 2017
Test build #81606 has finished for PR 18853 at commit
|
SparkQA
commented
Sep 10, 2017
Test build #81605 has finished for PR 18853 at commit
|
| test("SPARK-17913: compare long and string type column may return confusing result") { | ||
| val df = Seq(123L -> "123", 19157170390056973L -> "19157170390056971").toDF("i", "j") | ||
| checkAnswer(df.select($"i" === $"j"), Row(true) :: Row(false) :: Nil) | ||
| checkAnswer(df.select($"i" === $"j"), Row(true) :: Row(true) :: Nil) |
SparkQA
commented
Sep 11, 2017
Test build #81613 has finished for PR 18853 at commit
|
SparkQA
commented
Sep 11, 2017
Test build #81638 has finished for PR 18853 at commit
|
wangyum
commented
Sep 12, 2017
I provide 2 SQL scripts to validate the different result between Spark and Hive:
|
Thank you for your investigation! I think we need to introduce a type inference conf for it. To avoid impacting the existing Spark users, we should keep the existing behaviors, by default. |
SparkQA
commented
Sep 18, 2017
Test build #81871 has finished for PR 18853 at commit
|
wangyum
commented
Sep 18, 2017
retest this please. |
SparkQA
commented
Sep 18, 2017
Test build #81876 has finished for PR 18853 at commit
|
| buildConf("spark.sql.binary.comparison.compatible.with.hive") | ||
| .doc("Whether compatible with Hive when binary comparison.") | ||
| .booleanConf | ||
| .createWithDefault(true) |
| .createWithDefault(10000) | ||
| val BINARY_COMPARISON_COMPATIBLE_WITH_HIVE = | ||
| buildConf("spark.sql.binary.comparison.compatible.with.hive") |
There was a problem hiding this comment.
-> spark.sql.autoTypeCastingCompatibility
SparkQA
commented
Dec 6, 2017
Test build #84516 has finished for PR 18853 at commit
|
SparkQA
commented
Dec 6, 2017
Test build #84519 has finished for PR 18853 at commit
|
| The <code>default</code> type coercion mode was used in spark prior to 2.3.0, and so it | ||
| continues to be the default to avoid breaking behavior. However, it has logical | ||
| inconsistencies. The <code>hive</code> mode is preferred for most new applications, though | ||
| it may require additional manual casting. |
There was a problem hiding this comment.
Since Spark 2.3, the <code>hive</code> mode is introduced for Hive compatiblity. Spark SQL has its native type cocersion mode, which is enabled by default.
| "and so it continues to be the default to avoid breaking behavior. " + | ||
| "However, it has logical inconsistencies. " + | ||
| "The 'hive' mode is preferred for most new applications, " + | ||
| "though it may require additional manual casting.") |
| } else { | ||
| commonTypeCoercionRules :+ | ||
| InConversion :+ | ||
| PromoteStrings |
There was a problem hiding this comment.
Rename them to NativeInConversion and NativePromoteStrings
| val findCommonTypeToCompatibleWithHive: (DataType, DataType) => Option[DataType] = { | ||
| // Follow hive's binary comparison action: | ||
| // https://github.com/apache/hive/blob/rel/storage-release-2.4.0/ql/src/java/ | ||
| // org/apache/hadoop/hive/ql/exec/FunctionRegistry.java#L781 |
There was a problem hiding this comment.
I saw the change history of this file. It sounds like Hive's type coercion rules are also evolving.
gatorsmile
commented
Dec 6, 2017
Could you please do it? This must take a lot of efforts, but it really helps us to find all the holes. Appreciate it! |
gatorsmile
commented
Dec 6, 2017
Let me open an umbrella JIRA for tracking it. We can do it for both native and Hive compatibility mode. |
The JIRA https://issues.apache.org/jira/browse/SPARK-22722 was just opened. I will create an example and open many sub-tasks. Feel free to take them if you have bandwidth. |
gatorsmile
commented
Jan 9, 2018
cc @wangyum |
# Conflicts: # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
SparkQA
commented
Jan 9, 2018
Test build #85840 has finished for PR 18853 at commit
|
SparkQA
commented
Jan 9, 2018
Test build #85841 has finished for PR 18853 at commit
|
gatorsmile
commented
Jan 9, 2018
retest this please |
SparkQA
commented
Jan 9, 2018
Test build #85846 has finished for PR 18853 at commit
|
SparkQA
commented
Jan 9, 2018
Test build #85849 has finished for PR 18853 at commit
|
# Conflicts: # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala # sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercionSuite.scala
SparkQA
commented
Mar 31, 2018
Test build #88778 has finished for PR 18853 at commit
|
wangyum
commented
Mar 31, 2018
retest this please |
SparkQA
commented
Mar 31, 2018
Test build #88780 has finished for PR 18853 at commit
|
wangyum
commented
May 16, 2018
SparkQA
commented
Jun 10, 2018
Test build #91633 has finished for PR 18853 at commit
|
SparkQA
commented
Sep 6, 2018
Test build #95733 has finished for PR 18853 at commit
|



What changes were proposed in this pull request?
Add
HiveInConversionandHivePromoteStringsrules toTypeCoercion.scalato compatible with Hive.Add SQL configuration
spark.sql.typeCoercion.modeto configure whether usehivecompatibility mode or defaultdefaultmode.All difference between
defaultmode andhivemode:defaultmode (default mode)hivemode (compatible with Hive)The design doc:
https://issues.apache.org/jira/secure/attachment/12891695/Type_coercion_rules_to_compatible_with_Hive.pdf
How was this patch tested?
unit tests