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

Vladimir Steshin updated IGNITE-23414:
--------------------------------------
    Description: 
Dynamic parameters aren't casted like literals.

Reproducer:
{code:java}
        sql("CREATE TABLE t(id integer primary key, int_col integer)");
        sql("insert into t values (1, 1)");

        // OK
        assertQuery("SELECT id from t where int_col=CAST('1' as 
INTEGER)").returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST('1' as 
TINYINT)").returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST(1 as 
TINYINT)").returns(1).check();

        // OK
        assertThrows("SELECT id from t where int_col=CAST(11111 as TINYINT)", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col=CAST('11111' as TINYINT)", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col=11111::TINYINT", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col='11111'::TINYINT", 
ArithmeticException.class, "overflow");

        // Fails
        assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
ArithmeticException.class, "overflow", 1111);
        assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
ArithmeticException.class, "overflow", "1111");
        assertThrows("SELECT id from t where int_col=?::TINYINT", 
ArithmeticException.class, "overflow", 1111);
        assertThrows("SELECT id from t where int_col=?::TINYINT", 
ArithmeticException.class, "overflow", "1111");

        // Fails
        assertQuery("SELECT id from t where int_col=CAST(? as 
TINYINT)").withParams('1').returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST(? as 
INTEGER)").withParams('1').returns(1).check();
{code}

Adoption of #IGNITE-18831


  was:
Dynamic parameters aren't casted with `::`.

Reproducer:
{code:java}
        sql("CREATE TABLE t(id integer primary key, int_col integer)");
        sql("insert into t values (1, 1)");

        // OK
        assertQuery("SELECT id from t where int_col=CAST('1' as 
INTEGER)").returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST('1' as 
TINYINT)").returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST(1 as 
TINYINT)").returns(1).check();

        // OK
        assertThrows("SELECT id from t where int_col=CAST(11111 as TINYINT)", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col=CAST('11111' as TINYINT)", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col=11111::TINYINT", 
ArithmeticException.class, "overflow");
        assertThrows("SELECT id from t where int_col='11111'::TINYINT", 
ArithmeticException.class, "overflow");

        // Fails
        assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
ArithmeticException.class, "overflow", 1111);
        assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
ArithmeticException.class, "overflow", "1111");
        assertThrows("SELECT id from t where int_col=?::TINYINT", 
ArithmeticException.class, "overflow", 1111);
        assertThrows("SELECT id from t where int_col=?::TINYINT", 
ArithmeticException.class, "overflow", "1111");

        // Fails
        assertQuery("SELECT id from t where int_col=CAST(? as 
TINYINT)").withParams('1').returns(1).check();
        assertQuery("SELECT id from t where int_col=CAST(? as 
INTEGER)").withParams('1').returns(1).check();
{code}

Adoption of #IGNITE-18831



> Calcite. Fix cast of dynamic parameters by the cast operator.
> -------------------------------------------------------------
>
>                 Key: IGNITE-23414
>                 URL: https://issues.apache.org/jira/browse/IGNITE-23414
>             Project: Ignite
>          Issue Type: Improvement
>            Reporter: Vladimir Steshin
>            Priority: Minor
>              Labels: calcite, ignite-2, ise
>
> Dynamic parameters aren't casted like literals.
> Reproducer:
> {code:java}
>         sql("CREATE TABLE t(id integer primary key, int_col integer)");
>         sql("insert into t values (1, 1)");
>         // OK
>         assertQuery("SELECT id from t where int_col=CAST('1' as 
> INTEGER)").returns(1).check();
>         assertQuery("SELECT id from t where int_col=CAST('1' as 
> TINYINT)").returns(1).check();
>         assertQuery("SELECT id from t where int_col=CAST(1 as 
> TINYINT)").returns(1).check();
>         // OK
>         assertThrows("SELECT id from t where int_col=CAST(11111 as TINYINT)", 
> ArithmeticException.class, "overflow");
>         assertThrows("SELECT id from t where int_col=CAST('11111' as 
> TINYINT)", ArithmeticException.class, "overflow");
>         assertThrows("SELECT id from t where int_col=11111::TINYINT", 
> ArithmeticException.class, "overflow");
>         assertThrows("SELECT id from t where int_col='11111'::TINYINT", 
> ArithmeticException.class, "overflow");
>         // Fails
>         assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
> ArithmeticException.class, "overflow", 1111);
>         assertThrows("SELECT id from t where int_col=CAST(? as TINYINT)", 
> ArithmeticException.class, "overflow", "1111");
>         assertThrows("SELECT id from t where int_col=?::TINYINT", 
> ArithmeticException.class, "overflow", 1111);
>         assertThrows("SELECT id from t where int_col=?::TINYINT", 
> ArithmeticException.class, "overflow", "1111");
>         // Fails
>         assertQuery("SELECT id from t where int_col=CAST(? as 
> TINYINT)").withParams('1').returns(1).check();
>         assertQuery("SELECT id from t where int_col=CAST(? as 
> INTEGER)").withParams('1').returns(1).check();
> {code}
> Adoption of #IGNITE-18831



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

Reply via email to