-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33095] Follow up, support alter table column rename. #30142
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
Conversation
|
While testing #30038, I found rename column needs some work for mysql dialect. More details added in the code comments. cc @cloud-fan and @huaxingao |
7c9aa72 to
f4b8a24
Compare
|
Kubernetes integration test starting |
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Kubernetes integration test status failure |
|
Test build #130205 has finished for PR 30142 at commit
|
|
Test build #130207 has finished for PR 30142 at commit
|
|
Test build #130206 has finished for PR 30142 at commit
|
| } | ||
|
|
||
| override def testRenameColumn(tbl: String): Unit = { | ||
| if (db.imageName.matches(".*mysql.5\\.[0-9].*")) { |
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.
we can check the config value here.
| override def testRenameColumn(tbl: String): Unit = { | ||
| if (db.imageName.matches(".*mysql.5\\.[0-9].*")) { | ||
| sql(s"CREATE TABLE $tbl (ID STRING NOT NULL) USING _") | ||
| // Update nullability is unsupported for mysql db. |
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.
rename is unsupported ...
| .createWithDefault("") | ||
|
|
||
| val JDBC_MYSQL_VERSION = | ||
| buildConf("spark.sql.jdbc.mysql.version") |
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.
what if users want to connect to both mysql 5 and 8? I think it's better to make it a catalog option, not a session config.
| tableName: String, | ||
| columnName: String, | ||
| newName: String): String = { | ||
| if (SQLConf.get.jdbcMySQLVersion.matches("^8\\.[0-9].*")) { |
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.
Instead of using a session config, we probably want to get database version using DatabaseMetaData in JdbcUtils.altertable and pass the info here, and only do RENAME if version >= 8
conn.getMetaData.getDatabaseMajorVersion
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.
ah, it's even better if we can get the database version, so that users don't need to specify it.
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.
Thank you @huaxingao and @cloud-fan, for this suggestion.
f4b8a24 to
2e4fd62
Compare
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
@cloud-fan and @huaxingao I have updated the PR with your suggestions and also rebased it with master. Please take a look again. |
55cca16 to
9e1f75a
Compare
|
Test build #130402 has finished for PR 30142 at commit
|
|
Kubernetes integration test starting |
|
Jenkins, retest this please |
|
Kubernetes integration test status success |
| override def sparkConf: SparkConf = super.sparkConf | ||
| .set("spark.sql.catalog.mysql", classOf[JDBCTableCatalog].getName) | ||
| .set("spark.sql.catalog.mysql.url", db.getJdbcUrl(dockerIp, externalPort)) | ||
| override def sparkConf: SparkConf = { |
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.
unnecessary change
|
Kubernetes integration test starting |
| } | ||
|
|
||
| override def testRenameColumn(tbl: String): Unit = { | ||
| assert( mySQLVersion > 0) |
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.
nit: assert(mySQLVersion > 0) (remove extra space)
| val expectedSchema = new StructType().add("ID2", StringType, nullable = true) | ||
| .add("ID1", StringType, nullable = true) | ||
| assert(t.schema === expectedSchema) | ||
| // Rename to already existing column |
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.
This can be put in the test("SPARK-33034: ALTER TABLE ... rename column"), as the behavior should always be the same.
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.
done
|
Kubernetes integration test status success |
|
Test build #130404 has finished for PR 30142 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Test build #130407 has finished for PR 30142 at commit
|
|
Test build #130408 has finished for PR 30142 at commit
|
|
@ScrapCodes seems you forgot to address this #30142 (comment). Everything else is good. |
5b8e45e to
ce70996
Compare
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Test build #130452 has finished for PR 30142 at commit
|
|
Hi @huaxingao and @cloud-fan, Please take a look. |
|
thanks, merging to master! |
What changes were proposed in this pull request?
Support rename column for mysql dialect.
Why are the changes needed?
At the moment, it does not work for mysql version 5.x. So, we should throw proper exception for that case.
Does this PR introduce any user-facing change?
Yes,
column renamewith mysql dialect should work correctly.How was this patch tested?
Added tests for rename column.
Ran the tests to pass with both versions of mysql.
export MYSQL_DOCKER_IMAGE_NAME=mysql:5.7.31export MYSQL_DOCKER_IMAGE_NAME=mysql:8.0