aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main
diff options
context:
space:
mode:
authorpetermaxlee <petermaxlee@gmail.com>2016-07-27 16:04:43 +0800
committerWenchen Fan <wenchen@databricks.com>2016-07-27 16:04:43 +0800
commitef0ccbcb07252db0ead8509e70d1a9a670d41616 (patch)
treead6140f7ec5c17ab8c2316a2d7425253aaff3fcf /sql/catalyst/src/main
parent5b8e848bbfbc0c99a5faf758e40b188b0bbebb7b (diff)
downloadspark-ef0ccbcb07252db0ead8509e70d1a9a670d41616.tar.gz
spark-ef0ccbcb07252db0ead8509e70d1a9a670d41616.tar.bz2
spark-ef0ccbcb07252db0ead8509e70d1a9a670d41616.zip
[SPARK-16729][SQL] Throw analysis exception for invalid date casts
## What changes were proposed in this pull request? Spark currently throws exceptions for invalid casts for all other data types except date type. Somehow date type returns null. It should be consistent and throws analysis exception as well. ## How was this patch tested? Added a unit test case in CastSuite. Author: petermaxlee <petermaxlee@gmail.com> Closes #14358 from petermaxlee/SPARK-16729.
Diffstat (limited to 'sql/catalyst/src/main')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala9
1 files changed, 2 insertions, 7 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
index b1e89b5de8..a12fba047b 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
@@ -52,7 +52,8 @@ object Cast {
case (DateType, TimestampType) => true
case (_: NumericType, TimestampType) => true
- case (_, DateType) => true
+ case (StringType, DateType) => true
+ case (TimestampType, DateType) => true
case (StringType, CalendarIntervalType) => true
@@ -228,18 +229,12 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w
// throw valid precision more than seconds, according to Hive.
// Timestamp.nanos is in 0 to 999,999,999, no more than a second.
buildCast[Long](_, t => DateTimeUtils.millisToDays(t / 1000L))
- // Hive throws this exception as a Semantic Exception
- // It is never possible to compare result when hive return with exception,
- // so we can return null
- // NULL is more reasonable here, since the query itself obeys the grammar.
- case _ => _ => null
}
// IntervalConverter
private[this] def castToInterval(from: DataType): Any => Any = from match {
case StringType =>
buildCast[UTF8String](_, s => CalendarInterval.fromString(s.toString))
- case _ => _ => null
}
// LongConverter