Skip to content
Snippets Groups Projects
  • Dongjoon Hyun's avatar
    92b7e572
    [SPARK-17750][SQL] Fix CREATE VIEW with INTERVAL arithmetic. · 92b7e572
    Dongjoon Hyun authored
    ## 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.
    92b7e572
    History
    [SPARK-17750][SQL] Fix CREATE VIEW with INTERVAL arithmetic.
    Dongjoon Hyun authored
    ## 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.