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

Round functions return types for decimals(X, 0) increase precision by 1

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Frontend
    • None
    • ghx-label-7

    Description

      select typeof(ceil(cast(1 as decimal(1, 0))));
      result: DECIMAL(2,0)

      select typeof(ceil(cast(1 as decimal(38, 0))));
      ERROR: AnalysisException: No matching function with signature: typeof(INVALID_TYPE).

      Meanwhile precision is not increased if it was non-0:
      select typeof(ceil(cast(1 as decimal(38, 1))));
      result: DECIMAL(38,0)

      select typeof(ceil(cast(1 as decimal(38, 37))));
      result: DECIMAL(2,0)

      Hive works the same way as Impala.

      Generally ceil/floor/round is NOOP for integer types (and decimals with scale 0)

      Note that I don't know how other databases handle this, e.g. https://docs.microsoft.com/en-us/sql/t-sql/functions/round-transact-sql?view=sql-server-ver15 says
      Expression result Return type
      decimal and numeric category (p, s) decimal(p, s)

      which looks very different than the way we work.

      Attachments

        Activity

          People

            Unassigned Unassigned
            csringhofer Csaba Ringhofer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: