aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src
diff options
context:
space:
mode:
authorDongjoon Hyun <dongjoon@apache.org>2016-10-06 09:42:30 -0700
committergatorsmile <gatorsmile@gmail.com>2016-10-06 09:42:30 -0700
commit92b7e5728025b1bb6ed3aab5f1753c946a73568c (patch)
tree7620ed80d9295210f5ce36eaa25b0a2ebb8a65f0 /sql/catalyst/src
parent5e9f32dd87e58e909a579eaa310e67d31c3b6573 (diff)
downloadspark-92b7e5728025b1bb6ed3aab5f1753c946a73568c.tar.gz
spark-92b7e5728025b1bb6ed3aab5f1753c946a73568c.tar.bz2
spark-92b7e5728025b1bb6ed3aab5f1753c946a73568c.zip
[SPARK-17750][SQL] Fix CREATE VIEW with INTERVAL arithmetic.
## What changes were proposed in this pull request? Currently, Spark raises `RuntimeException` when creating a view with timestamp with INTERVAL arithmetic like the following. The root cause is the arithmetic expression, `TimeAdd`, was transformed into `timeadd` function as a VIEW definition. This PR fixes the SQL definition of `TimeAdd` and `TimeSub` expressions. ```scala scala> sql("CREATE TABLE dates (ts TIMESTAMP)") scala> sql("CREATE VIEW view1 AS SELECT ts + INTERVAL 1 DAY FROM dates") java.lang.RuntimeException: Failed to analyze the canonicalized SQL: ... ``` ## How was this patch tested? Pass Jenkins with a new testcase. Author: Dongjoon Hyun <dongjoon@apache.org> Closes #15318 from dongjoon-hyun/SPARK-17750.
Diffstat (limited to 'sql/catalyst/src')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala2
1 files changed, 2 insertions, 0 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
index 04c17bdaf2..7ab68a13e0 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
@@ -682,6 +682,7 @@ case class TimeAdd(start: Expression, interval: Expression)
override def right: Expression = interval
override def toString: String = s"$left + $right"
+ override def sql: String = s"${left.sql} + ${right.sql}"
override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, CalendarIntervalType)
override def dataType: DataType = TimestampType
@@ -762,6 +763,7 @@ case class TimeSub(start: Expression, interval: Expression)
override def right: Expression = interval
override def toString: String = s"$left - $right"
+ override def sql: String = s"${left.sql} - ${right.sql}"
override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType, CalendarIntervalType)
override def dataType: DataType = TimestampType