[
https://issues.apache.org/jira/browse/CALCITE-4519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17449947#comment-17449947
]
C. Alexander Leigh edited comment on CALCITE-4519 at 11/28/21, 3:51 PM:
------------------------------------------------------------------------
The check is in SqlValidatorImpl:4765. In terms of a fix the issue becomes
broader since it appears RelDataTypeField, which contains the nullability for
the field, does not contain the auto-generated status for the field. As far as
I can tell, fixing this issue will require adding the boolean to
RelDataTypeField and then improving gelRelDataType() in JdbcSchema to discern
the auto increment fields somehow and to set the boolean. Then it can be
checked later in SqlValidatorImpl.
was (Author: JIRAUSER280873):
The check is in SqlValidatorImpl:4765. In terms of a fix the issue becomes
broader since it appears RelDataTypeField, which contains the nullability for
the fiend, does not contain the auto-generated status for the field. As far as
I can tell, fixing this issue will require adding the boolean to
RelDataTypeField and then improving gelRelDataType() in JdbcSchema to discern
the auto increment fields somehow and to set the boolean. Then it can be
checked later in SqlValidatorImpl.
> 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
> Priority: Major
>
> I have a mysql table as follow:
> {code:java}
> | 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 |
> {code}
>
> my code as follow:
> {code:java}
> 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
> {code}
>
> 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:
> {code:java}
> final ResultSet resultSet = metaData.getColumns(catalogName, schemaName,
> tableName, null);{code}
>
> 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:
> {code:java}
> INSERT INTO test.my_test(name) VALUES('test...'){code}
> this sql run ok, I can omit the id filed.
> in
> {code:java}
> statement.execute(sql);{code}
> 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.20.1#820001)