[ 
https://issues.apache.org/jira/browse/IMPALA-7887?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul Rogers updated IMPALA-7887:
--------------------------------
    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:

{code:java}
    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());
{code}

Prints:

{noformat}
123.45
2147483647
{noformat}

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:

bq. 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.

  was:
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:

{code:java}
    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());
{code}

Prints:

{noformat}
123.45
2147483647
{noformat}

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

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.


> NumericLiteral fails to detect numeric overflow
> -----------------------------------------------
>
>                 Key: IMPALA-7887
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7887
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>    Affects Versions: Impala 3.0
>            Reporter: Paul Rogers
>            Assignee: Paul Rogers
>            Priority: Minor
>
> 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:
> {code:java}
>     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());
> {code}
> Prints:
> {noformat}
> 123.45
> 2147483647
> {noformat}
> 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:
> bq. 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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscr...@impala.apache.org
For additional commands, e-mail: issues-all-h...@impala.apache.org

Reply via email to