-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support create table with primary key in mysql #24930
Add support create table with primary key in mysql #24930
Conversation
bcf63d1
to
06363ce
Compare
06363ce
to
943aa3e
Compare
7929945
to
f5e0909
Compare
I found In Ignite or phoenix will keep primary key information in table properties rather than column properties. So which way is better? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix CI failures.
d76f026
to
ac4e8ef
Compare
it's done! |
@JsonProperty("autoIncrement") boolean autoIncrement, | ||
@JsonProperty("primaryKey") boolean primaryKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about for the datasources/tables which doesn't support primayKey/autoincrement ? Instead of implementing it directly for BaseJDBC module - Can we add them for each datasource and unify them once we are sure on how each datasource behave ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! In the java.sql package, DatabaseMetaData defines methods such as getPrimaryKeys and getColumns. The getColumns method returns information about whether a column is IS_AUTOINCREMENT. I believe this is a common JDBC specification. Therefore, I think it can be placed in the BaseJDBC module.Different data sources may have different implementations. If there is a problem, it is likely to be due to the implementation of the data source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add primary key first, for the autoIncrement it's seems specify to the connectors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can add primary key first, for the autoIncrement it's seems specify to the connectors
Thanks for the feedback! As mentioned in the document, the attributes of a column should include data type, default value, isNullable, isAutoIncrement, comment and so on. In the future, I also want to add default value configurations.
In the current implementation, If user create table with primary key and autoincrement and the datasources/tables which doesn't support primayKey/autoincrement, these pieces of information will not be included in the generated table creation statement.Therefore, I believe this will not result in any erroneous impact, it's just that these configuration will not take effect if datasources/tables which doesn't support.
@Praveen2112 @chenjian2664 It's better to implement custom JdbcColumnHandle and ColumnPropertiesProvider for different JDBC connectors even if their contents are the same? If that's the case, I will open a new PR to implement only mysql first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user create table with primary key and autoincrement and the datasources/tables which doesn't support primayKey/autoincrement, these pieces of information will not be included in the generated table creation statement
Would it be better for this behavior to throw exceptions in such cases?
Since you're modifying the base JDBC module, it's needs to consider carefully as different connectors may have varying driver behaviors. You might also need to update the base connector tests for all connectors, implementing this at the base level could ensure consistency(no matter the connector support or not support), while adding it to a specific connector might keep things cleaner.
I also suggest prioritizing primary key support first, as we've already involved this feature in some connectors, though not support create it directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for this behavior to throw exceptions in such cases?
We should definitely throw an exception if the data source doesn’t support primary keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better for this behavior to throw exceptions in such cases?
We should definitely throw an exception if the data source doesn’t support primary keys.
@chenjian2664 @ebyhr @Praveen2112 So It's better to add primary key in base JDBC module first and check all data source, throw an exception if the data source doesn’t support primary keys in this PR. And then open a new PR to support autoincrement, default value and other attribute in a specified data source such as mysql. Is this implementation feasible?
Or we can first implement these features (such as primary keys, auto-increment, default values, etc.) in MySQL, and then gradually extend them to other data sources.
Please give me suggestions,thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could add primary key in Mysql first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could add primary key in Mysql first
thanks, I am re-implementing it and only support MySQL table creation with primary key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenjian2664 @Praveen2112 @ebyhr could you help review when you have a time? thanks
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/JdbcColumnHandle.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/properties/JdbcColumnProperties.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
testing/trino-testing/src/main/java/io/trino/testing/BaseConnectorTest.java
Outdated
Show resolved
Hide resolved
3d3d9f5
to
3c45452
Compare
bb2f28d
to
5593109
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good % comments, good job.
cc @ebyhr
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
@chenjian2664 Thank you for the assistance you've provided! |
This pull request has gone a while without any activity. Ask for help on #core-dev on Trino slack. |
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MysqlTableProperties.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MysqlTableProperties.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
5593109
to
aa530d1
Compare
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlTableProperties.java
Outdated
Show resolved
Hide resolved
Please add a test that |
aa530d1
to
c3e1d3e
Compare
Done |
c3e1d3e
to
0bbcd5e
Compare
plugin/trino-mysql/src/test/java/io/trino/plugin/mysql/BaseMySqlConnectorTest.java
Outdated
Show resolved
Hide resolved
f197320
to
66a01ae
Compare
plugin/trino-mysql/src/main/java/io/trino/plugin/mysql/MySqlClient.java
Outdated
Show resolved
Hide resolved
66a01ae
to
1ef2ccf
Compare
1ef2ccf
to
87bdd5e
Compare
Description
Add MysqlTableProperties and support create table with primary key in mysql.
Release notes