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

Inconsistent typing of pure-constant expressions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Impala 3.1.0
    • None
    • Frontend
    • None
    • ghx-label-4

    Description

      Impala implements a very subtle rule for computing the type of constant expressions. See IMPALA-4213. The desired rules when performing constant folding are:

      • Pure-literal numeric expressions take the natural (smallest) type of the result.
      • All other expressions preserve the type of the expression.

      Examples:

       -- simple literal
      100 -> 100:TINYINT
      
       -- explicit cast
      CAST(100 AS SMALLINT) --> 100:SMALLINT
      
       -- pure literal expression
      2 + 3 --> 5:TINYINT
      
        -- addition is done at next wider type up from that of tinyint_col
      tinyint_col + 3 --> SMALLINT
      
       -- explicit type given, math done with that type, mimics above
      CAST(2 AS TINYINT) + 3 --> 5:SMALLINT
      
       -- Impala uses C++ semantics, with overflow
      CAST(257 AS TINYINT) --> 2:TINYINT
      

      At present, some parts of the code follow these rules, but the constant folding rule does not. As a result, PlannerTest fails for subtle changes in unrelated areas. Some PlannerTest results, such as the Kudu test mentioned in IMPALA-4213 do observe the rules. But, some constant folding test do not observe the rules.

      Expected that the rules would be followed on all code paths to ensure consistent results.

      Attachments

        Activity

          People

            Unassigned Unassigned
            Paul.Rogers Paul Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: