-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-33034][SQL] Support ALTER TABLE in JDBC v2 Table Catalog: add, update type and nullability of columns (Oracle dialect) #29912
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
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #129273 has finished for PR 29912 at commit
|
|
@dongjoon-hyun @maropu @huaxingao May I ask you to review this PR. |
| * $ export ORACLE_DOCKER_IMAGE_NAME=oracle/database:18.4.0-xe | ||
| * $ cd $SPARK_HOME | ||
| * $ ./build/sbt -Pdocker-integration-tests | ||
| * "test-only org.apache.spark.sql.jdbc.OracleIntegrationSuite" |
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.
super nit: you mean "org.apache.spark.sql.jdbc.v2.OracleIntegrationSuite", right?
|
LGTM |
| import org.apache.spark.sql.jdbc.{DatabaseOnDocker, DockerJDBCIntegrationSuite} | ||
| import org.apache.spark.sql.test.SharedSparkSession | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.tags.DockerTest |
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.
plz remove all the unused imports.
| * It has been validated with 18.4.0 Express Edition. | ||
| */ | ||
| @DockerTest | ||
| class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSparkSession { |
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.
Could we run the existing tests of o.a.s.s.jdbc.OracleIntegrationSuite for the V2 JDBC path? I think it is okay to fix it in a separate PR though.
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 opened the JIRA ticket for that https://issues.apache.org/jira/browse/SPARK-33066, let's do that separately. Probably, we will need to split the ticket per each supported dialect.
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.
Yea, looks okay. Thanks for opening it, Max!
| test("SPARK-33034: alter table ... add column") { | ||
| withTable("oracle.alt_table") { | ||
| sql("CREATE TABLE oracle.alt_table (ID STRING) USING _") | ||
| sql("ALTER TABLE oracle.alt_table ADD COLUMNS (C1 STRING, C2 STRING)") |
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.
Does this ALTER command always succeed? What if we add a new column having the same name with the existing column? Anyway, I think it is better to add some tests for error cases.
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 test here dialect specific changes:
ALTER TABLE ... ALTER COLUMN vs ALTER TABLE ... ADD
I believe the test for error handling should be added to JDBCTableCatalogSuite since error handling should be generic.
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 added negative tests to the common tests #29945
| test("SPARK-33034: alter table ... update column type") { | ||
| withTable("oracle.alt_table") { | ||
| sql("CREATE TABLE oracle.alt_table (ID INTEGER) USING _") | ||
| sql("ALTER TABLE oracle.alt_table ALTER COLUMN id TYPE STRING") |
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.
ditto: We can alter a column from a string type to a int one?
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.
No:
rg.apache.spark.sql.AnalysisException: Cannot update alt_table field ID: string cannot be cast to int; line 1 pos 0;
[info] AlterTable org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog@3ebc40fe, alt_table, RelationV2[ID#25] alt_table, [org.apache.spark.sql.connector.catalog.TableChange$UpdateColumnType@ce035e83]
[info] at org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:42)
[info] at org.apache.spark.sql.catalyst.analysis.CheckAnalysis.$anonfun$checkAnalysis$31(CheckAnalysis.scala:528)
[info] at scala.collection.immutable.List.foreach(List.scala:392)
[info] at org.apache.spark.sql.catalyst.analysis.CheckAnalysis.$anonfun$checkAnalysis$1(CheckAnalysis.scala:489)
I will add a check for that.
| test("SPARK-33034: alter table ... update column nullability") { | ||
| withTable("oracle.alt_table") { | ||
| sql("CREATE TABLE oracle.alt_table (ID STRING NOT NULL) USING _") | ||
| sql("ALTER TABLE oracle.alt_table ALTER COLUMN ID DROP NOT NULL") |
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.
ditto: What if we drop a non-existent 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.
I will add negative tests.
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #129408 has finished for PR 29912 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
|
Test build #129411 has finished for PR 29912 at commit
|
|
The last build failure is not related to the changes. |
maropu
left a comment
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've checked that v2/OracleIntegrationSuite passed in my local env. cc: @dongjoon-hyun
| override val connectionTimeout = timeout(7.minutes) | ||
| override def dataPreparation(conn: Connection): Unit = {} | ||
|
|
||
| test("SPARK-33034: alter table ... add 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.
nit: upper case the sql keyword: ALTER TABLE ... add new columns
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.
isn't the SQL parser case agnostic one ? ;-)
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.
yes it is. It's a convention that people upper case the sql keyword when writing sql queries.
| expectedSchema = expectedSchema.add("C3", StringType) | ||
| assert(t.schema === expectedSchema) | ||
| // Add already existing column | ||
| intercept[AnalysisException] { |
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.
can we check the error message?
| } | ||
| } | ||
| // Add a column to not existing table | ||
| intercept[AnalysisException] { |
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.
ditto
| val expectedSchema = new StructType().add("ID", StringType) | ||
| assert(t.schema === expectedSchema) | ||
| // Update column type from STRING to INTEGER | ||
| intercept[AnalysisException] { |
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.
ditto
| sql("ALTER TABLE oracle.alt_table ALTER COLUMN bad_column TYPE DOUBLE") | ||
| } | ||
| // Update column to wrong type | ||
| intercept[AnalysisException] { |
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 should be ParseException?
cloud-fan
left a comment
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.
LGTM except some minor comments in tests
|
Kubernetes integration test starting |
|
Kubernetes integration test starting |
|
Kubernetes integration test status failure |
|
Kubernetes integration test status success |
|
Test build #129459 has finished for PR 29912 at commit
|
|
Test build #129460 has finished for PR 29912 at commit
|
|
thanks, merging to master! |
What changes were proposed in this pull request?
jdbc/v2/OracleIntegrationSuite.scalaWhy are the changes needed?
In SPARK-24907, we implemented JDBC v2 Table Catalog but it doesn't support some
ALTER TABLEat the moment. This PR supports Oracle specificALTER TABLE.Does this PR introduce any user-facing change?
Yes
How was this patch tested?
By running new integration test suite: