Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-2268

implicit casting of string to timestamp for functions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Impala 2.2
    • None
    • Frontend

    Description

      Consider date_add() builtin. string is automatically cast to a timestamp.

      select date_add( "1900-01-01", 1 ) ; 
      Query: select date_add( "1900-01-01", 1 ) 
      +---------------------------+ 
      | date_add('1900-01-01', 1) | 
      +---------------------------+ 
      | 1900-01-02 00:00:00 | 
      +---------------------------+ 
      Fetched 1 row(s) in 0.12s 
      

      However with an "interval"

      select date_add( '1900-01-01', interval 72 days ) ; 
      Query: select date_add( '1900-01-01', interval 72 days ) 
      ERROR: AnalysisException: Operand ''1900-01-01'' of timestamp arithmetic expression 'DATE_ADD('1900-01-01', INTERVAL 72 days)' returns type 'STRING'. Expected type 'TIMESTAMP'. 
      

      We need to manually cast it to a timestamp, something like,

      select date_add(cast("1900-01-01" as TIMESTAMP), interval 10 days ) ; 
      Query: select date_add(cast("1900-01-01" as TIMESTAMP), interval 10 days ) 
      +-------------------------------------------------------------+ 
      | date_add(cast('1900-01-01' as timestamp), interval 10 days) | 
      +-------------------------------------------------------------+ 
      | 1900-01-11 00:00:00 | 
      +-------------------------------------------------------------+ 
      Fetched 1 row(s) in 0.02s 
      

      Its convenient to make this behavior consistent across all builtins.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              bharathv Bharath Vissapragada
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: