aboutsummaryrefslogtreecommitdiff
path: root/sql/hive
diff options
context:
space:
mode:
authorguowei2 <guowei2@asiainfo.com>2015-04-04 02:02:30 +0800
committerCheng Lian <lian@databricks.com>2015-04-04 02:02:30 +0800
commitc23ba81b8cf86c3a085de8ddfef9403ff6fcd87f (patch)
tree9f42058a301732153b85ede6fed4d8316d2f2892 /sql/hive
parentdc6dff248d8f5d7de22af64b0586dfe3885731df (diff)
downloadspark-c23ba81b8cf86c3a085de8ddfef9403ff6fcd87f.tar.gz
spark-c23ba81b8cf86c3a085de8ddfef9403ff6fcd87f.tar.bz2
spark-c23ba81b8cf86c3a085de8ddfef9403ff6fcd87f.zip
[SPARK-5203][SQL] fix union with different decimal type
When union non-decimal types with decimals, we use the following rules: - FIRST `intTypeToFixed`, then fixed union decimals with precision/scale p1/s2 and p2/s2 will be promoted to DecimalType(max(p1, p2), max(s1, s2)) - FLOAT and DOUBLE cause fixed-length decimals to turn into DOUBLE (this is the same as Hive, but note that unlimited decimals are considered bigger than doubles in WidenTypes) Author: guowei2 <guowei2@asiainfo.com> Closes #4004 from guowei2/SPARK-5203 and squashes the following commits: ff50f5f [guowei2] fix code style 11df1bf [guowei2] fix decimal union with double, double->Decimal(15,15) 0f345f9 [guowei2] fix structType merge with decimal 101ed4d [guowei2] fix build error after rebase 0b196e4 [guowei2] code style fe2c2ca [guowei2] handle union decimal precision in 'DecimalPrecision' 421d840 [guowei2] fix union types for decimal precision ef2c661 [guowei2] fix union with different decimal type
Diffstat (limited to 'sql/hive')
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala11
1 files changed, 11 insertions, 0 deletions
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
index 2065f0d60d..817b9dcb8f 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLQuerySuite.scala
@@ -468,4 +468,15 @@ class SQLQuerySuite extends QueryTest {
sql(s"DROP TABLE $tableName")
}
}
+
+ test("SPARK-5203 union with different decimal precision") {
+ Seq.empty[(Decimal, Decimal)]
+ .toDF("d1", "d2")
+ .select($"d1".cast(DecimalType(10, 15)).as("d"))
+ .registerTempTable("dn")
+
+ sql("select d from dn union all select d * 2 from dn")
+ .queryExecution.analyzed
+ }
+
}