[ 
https://issues.apache.org/jira/browse/CALCITE-5382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17633671#comment-17633671
 ] 

Jiajun Xie edited comment on CALCITE-5382 at 11/14/22 10:39 AM:
----------------------------------------------------------------

Is this a duplicate of CALCITE-5141?

SQL

 
{code:java}
insert into t3 values ('a', 1.0, 1), ('b', 2, 2), ('c', 3.0, CAST(3 AS 
SMALLINT)), ('d', 4.0, 4), ('e', 5.0, 5) {code}
Validated sql

 
{code:java}
INSERT INTO `CATALOG`.`SALES`.`T3`
VALUES ROW('a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)),
ROW('b', 2, CAST(2 AS SMALLINT)),-- Encountered an integer and ended early
ROW('c', 3.0, CAST(3 AS SMALLINT)),Encountered an samllint and ended early
ROW('d', 4.0, 4),  -- missing cast
ROW('e', 5.0, 5)   -- missing cast{code}
the right validated sql is:
{code:java}
INSERT INTO `CATALOG`.`SALES`.`T3`
VALUES ROW('a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)),
ROW('b', 2, CAST(2 AS SMALLINT)),
ROW('c', CAST(3.0 AS INTEGER), CAST(3 AS SMALLINT)),
ROW('d', CAST(4.0 AS INTEGER), CAST(4 AS SMALLINT)),
ROW('e', CAST(5.0 AS INTEGER), CAST(5 AS SMALLINT)) {code}


was (Author: jiajunbernoulli):
Is this a duplicate of CALCITE-5141?

> Values are not casted to correct type in insertion
> --------------------------------------------------
>
>                 Key: CALCITE-5382
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5382
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.32.0
>            Reporter: Yueguang Jiao
>            Priority: Major
>
> Assume we have created a table by
> {code:sql}
> create table test (
>     id int not null,
>     name varchar not null,
>     score double,
>     primary key(id)
> )
> {code}
> Note the column 'score' is nullable.  Then try to parse and validate a 
> statement as
> {code:sql}
> insert into test values
> (1, 'Alice', 1.0),
> (2, 'Betty', null),
> (3, 'Cindy', 3.0)
> {code}
> Before validation, the 'SqlNode' is
> {code:sql}
> INSERT INTO `test`
> VALUES ROW(1, 'Alice', 1.0),
> ROW(2, 'Betty', NULL),
> ROW(3, 'Cindy', 3.0)
> {code}
> After validation, the `SqlNode` is
> {code:sql}
> VALUES ROW(1, 'Alice', CAST(1.0 AS DOUBLE)),
> ROW(2, 'Betty', NULL),
> ROW(3, 'Cindy', 3.0)
> {code}
> The 'score' column in the first row is casted, but not the one in the third 
> row. I think this is not correct.
> This is tested by the following Java code:
> {code:java}
> SqlParser parser = SqlParser.create(sql);
> SqlNode sqlNode = parser.parseQuery();
> log.debug("sqlNode = {}", sqlNode);
> SqlValidator validator = SqlValidatorUtil.newValidator(
>     SqlStdOperatorTable.instance(),
>     catalogReader,
>     new JavaTypeFactoryImpl(),
>     SqlValidator.Config.DEFAULT
> );
> sqlNode = validator.validate(sqlNode);
> log.debug("sqlNode = {}", sqlNode);
> {code}



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

Reply via email to