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

NumericLiteral fails to detect numeric overflow

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • Impala 3.0
    • None
    • Frontend
    • None
    • ghx-label-3

    Description

      The NumericLiteral constructor takes a value and a type. The code does not check that the value is within range of the type, allowing nonsensical values:

          NumericLiteral n = new NumericLiteral(new BigDecimal("123.45"),
              ScalarType.createDecimalType(3, 1));
          System.out.println(n.getValue().toString());
          n = new NumericLiteral(new BigDecimal(Integer.MAX_VALUE),
              Type.TINYINT);
          System.out.println(n.getValue().toString());
      

      Prints:

      123.45
      2147483647
      

      The value 123.45 is not valid for DECIMAL(3,1), nor is 2^31 valid for TINYINT.

      According to the SQL-2016 standard, section 4.4:

      If an assignment of some number would result in a loss of its most significant digit, an exception condition is raised.

      The purpose of the constructor appears to be for "friendly" use where the caller promises not to create incorrect literals. Better would be to enforce this rule.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: