You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "wang_da_ye (Jira)" <ji...@apache.org> on 2021/03/02 07:09:00 UTC

[jira] [Created] (CALCITE-4519) INSERT mysql table operate failure

wang_da_ye created CALCITE-4519:
-----------------------------------

             Summary: INSERT mysql table operate failure
                 Key: CALCITE-4519
                 URL: https://issues.apache.org/jira/browse/CALCITE-4519
             Project: Calcite
          Issue Type: Bug
    Affects Versions: 1.26.0
         Environment: JDK: 15.0.2

calcite: 1.26.0

mysql: 5.7.31
            Reporter: wang_da_ye


I have a mysql table as follow:I have a mysql table as follow:| my_test | CREATE TABLE `my_test` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `name` varchar(200) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 |

my code as follow:Connection connection = Util.getConnect("/model.json");Statement statement = connection.createStatement();String sql = "INSERT INTO test.my_test(name) VALUES('test...')";statement.execute(sql); //a error here

debug calcite code, I found:JdbcSchema#getRelDataType() maybe some problem.   this function parse row name, and transform to RelProtoDataType object.get meta data used DatabaseMetaData class.

then,the result set of the metadata is obtained,as follow code:final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null);
after,in while loop, resultSet get each row meta, like sqlType,nullable.my test table "my_test" id is primary key, so this filed is not null, but this filed has a "auto_increment" attribute.it means that:INSERT INTO test.my_test(name) VALUES('test...')this sql run ok, I can omit the id filed.

in "statement.execute(sql);" this sentence, trigger validate,and throws a exeception:Column 'id' has no default value and does not allow NULLs
the same sql in mysql 5.7.31 run ok, but in calcite get a error,JdbcSchema#getRelDataType() there may be a lack of judgment.in this function,add a "IS_AUTOINCREMENT" meta info, may be can deal with that,in validate logic,if a filed has "nullable" and "autoincrement" attribute may be can skip the validate.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)