You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Yueguang Jiao (Jira)" <ji...@apache.org> on 2022/11/14 09:46:00 UTC

[jira] [Created] (CALCITE-5382) Values are not casted to correct type in insertion

Yueguang Jiao created CALCITE-5382:
--------------------------------------

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


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)