Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-6328

The BigQuery functions SAFE_* do not match the BigQuery specification

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.36.0
    • None
    • core
    • None

    Description

      The BigQuery dialect does not support DECIMAL values with arbitrary types: it only supports two fixed types: NUMERIC and BIGNUMERIC, both with fixed precision and scale.

      The runtime implementation of the SAFE_* functions uses the following helper in SqlFunctions:

        /** Returns whether a BigDecimal value is safe (that is, has not overflowed).
         * According to BigQuery, BigDecimal overflow occurs if the precision is greater
         * than 76 or the scale is greater than 38. */
        private static boolean safeDecimal(BigDecimal b) {
          return b.scale() <= 38 && b.precision() <= 76;
        }
      

      This helper does not handle correctly NUMERIC value, only BIGNUMERIC.

      Moreover, all the tests in SqlOperatorTests use a type system which doesn't even support DECIMAL values wider than 38 digits. So a test like the following:

          f.checkNull("safe_add(cast(-9.9e75 as DECIMAL(76, 0)), "
              + "cast(-9.9e75 as DECIMAL(76, 0)))");
      

      cannot even create the expected BigDecimal value correctly.

      This surfaced during the attempt to fix CALCITE-6322: once the casts to DECIMAL are implemented, some of these tests break.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mbudiu Mihai Budiu
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: