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

Evgeny Stanilovsky updated CALCITE-6190:
----------------------------------------
    Description: 
Test highlights the problem :


{code:java}
  @Test void testTypeOfAs() {
    sql("select DECIMAL '100.01' as c1 from (values (true))")
        .columnType("DECIMAL(5, 2) NOT NULL");
    sql("select DECIMAL '-100.01' as c1 from (values (true))")
        .columnType("DECIMAL(5, 2) NOT NULL");
}
{code}


Throws exception for second expression:

{noformat}
Expected: is "DECIMAL(5, 2) NOT NULL"
     but: was "DECIMAL(6, 2) NOT NULL"
{noformat}

Seems root cause in SqlLiteral#createExactNumeric precision derivation not 
consider negative numbers.

  was:
Test highlights the problem :


{code:java}
  @Test void testTypeOfAs() {
    sql("select DECIMAL '*100.01*' as c1 from (values (true))")
        .columnType("DECIMAL(*5, 2*) NOT NULL");
    sql("select DECIMAL '*-100.01*' as c1 from (values (true))")
        .columnType("DECIMAL(*5, 2*) NOT NULL");
}
{code}


Throws check exception for second expression:

{noformat}
Expected: is "DECIMAL(5, 2) NOT NULL"
     but: was "DECIMAL(6, 2) NOT NULL"
{noformat}

Seems root cause in SqlLiteral#createExactNumeric precision derivation not 
consider negative numbers.


> Incorrect precision derivation for negative numeric types
> ---------------------------------------------------------
>
>                 Key: CALCITE-6190
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6190
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.36.0
>            Reporter: Evgeny Stanilovsky
>            Priority: Major
>
> Test highlights the problem :
> {code:java}
>   @Test void testTypeOfAs() {
>     sql("select DECIMAL '100.01' as c1 from (values (true))")
>         .columnType("DECIMAL(5, 2) NOT NULL");
>     sql("select DECIMAL '-100.01' as c1 from (values (true))")
>         .columnType("DECIMAL(5, 2) NOT NULL");
> }
> {code}
> Throws exception for second expression:
> {noformat}
> Expected: is "DECIMAL(5, 2) NOT NULL"
>      but: was "DECIMAL(6, 2) NOT NULL"
> {noformat}
> Seems root cause in SqlLiteral#createExactNumeric precision derivation not 
> consider negative numbers.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to