Skip to content
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

[SPARK-45075][SQL] Fix alter table with invalid default value will not report error #42810

Conversation

Hisoka-X
Copy link
Member

@Hisoka-X Hisoka-X commented Sep 5, 2023

What changes were proposed in this pull request?

This PR make sure ALTER TABLE ALTER COLUMN with invalid default value on DataSource V2 will report error, before this PR it will alter sucess.

Why are the changes needed?

Fix the error behavior on DataSource V2 with ALTER TABLE statement.

Does this PR introduce any user-facing change?

Yes, the invalid default value will report error.

How was this patch tested?

Add new test.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Sep 5, 2023
Comment on lines +371 to +379
checkError(
exception = intercept[AnalysisException] {
sql("alter table t add column s bigint default badvalue")
},
errorClass = "INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION",
parameters = Map(
"statement" -> "ALTER TABLE",
"colName" -> "`s`",
"defaultValue" -> "badvalue"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case will report error normally before this PR, but we don't have any test case to prove it.

Comment on lines +382 to +390
checkError(
exception = intercept[AnalysisException] {
sql("alter table t alter column s set default badvalue")
},
errorClass = "INVALID_DEFAULT_VALUE.UNRESOLVED_EXPRESSION",
parameters = Map(
"statement" -> "ALTER TABLE ALTER COLUMN",
"colName" -> "`s`",
"defaultValue" -> "badvalue"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this test case to prove the new change worked. But the more negative case in sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala and only worked for V1, after this PR merged, I will move it to sql/core/src/test/scala/org/apache/spark/sql/SQLInsertTestSuite.scala in #42802

@Hisoka-X
Copy link
Member Author

Hisoka-X commented Sep 5, 2023

cc @cloud-fan @gengliangwang @dtenedor

Copy link
Contributor

@dtenedor dtenedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @Hisoka-X , @dtenedor , @cloud-fan .

dongjoon-hyun pushed a commit that referenced this pull request Sep 8, 2023
…t report error

### What changes were proposed in this pull request?
This PR make sure ALTER TABLE ALTER COLUMN with invalid default value on DataSource V2 will report error, before this PR it will alter sucess.

### Why are the changes needed?
Fix the error behavior on DataSource V2 with ALTER TABLE statement.

### Does this PR introduce _any_ user-facing change?
Yes, the invalid default value will report error.

### How was this patch tested?
Add new test.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #42810 from Hisoka-X/SPARK-45075_alter_invalid_default_value_on_v2.

Authored-by: Jia Fan <fanjiaeminem@qq.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
(cherry picked from commit 4dd4737)
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
dongjoon-hyun pushed a commit that referenced this pull request Sep 8, 2023
…t report error

### What changes were proposed in this pull request?
This PR make sure ALTER TABLE ALTER COLUMN with invalid default value on DataSource V2 will report error, before this PR it will alter sucess.

### Why are the changes needed?
Fix the error behavior on DataSource V2 with ALTER TABLE statement.

### Does this PR introduce _any_ user-facing change?
Yes, the invalid default value will report error.

### How was this patch tested?
Add new test.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #42810 from Hisoka-X/SPARK-45075_alter_invalid_default_value_on_v2.

Authored-by: Jia Fan <fanjiaeminem@qq.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
(cherry picked from commit 4dd4737)
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
@dongjoon-hyun
Copy link
Member

Merged to master/3.5/3.4.

@Hisoka-X
Copy link
Member Author

Thanks @cloud-fan @dongjoon-hyun @dtenedor

@dongjoon-hyun
Copy link
Member

dongjoon-hyun commented Sep 11, 2023

Oh, I realized that branch-3.4 fails. It seems that there is a behavior difference in branch-3.4.

Let me revert this from branch-3.4. Could you make a backporting PR to branch-3.4, @Hisoka-X ?

@dongjoon-hyun
Copy link
Member

This is reverted via e3b8402 from branch-3.4 for now.

@Hisoka-X Hisoka-X deleted the SPARK-45075_alter_invalid_default_value_on_v2 branch September 12, 2023 01:50
dongjoon-hyun pushed a commit that referenced this pull request Sep 12, 2023
…ll not report error

### What changes were proposed in this pull request?
This is a backporting PR to branch-3.4 from #42810

Changed the way of assert the error to adapt to 3.4

### Why are the changes needed?
Fix bug on 3.4

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
add new test.

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #42876 from Hisoka-X/SPARK-45075_followup_3.4_alter_column.

Authored-by: Jia Fan <fanjiaeminem@qq.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
viirya pushed a commit to viirya/spark-1 that referenced this pull request Oct 19, 2023
…t report error

### What changes were proposed in this pull request?
This PR make sure ALTER TABLE ALTER COLUMN with invalid default value on DataSource V2 will report error, before this PR it will alter sucess.

### Why are the changes needed?
Fix the error behavior on DataSource V2 with ALTER TABLE statement.

### Does this PR introduce _any_ user-facing change?
Yes, the invalid default value will report error.

### How was this patch tested?
Add new test.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#42810 from Hisoka-X/SPARK-45075_alter_invalid_default_value_on_v2.

Authored-by: Jia Fan <fanjiaeminem@qq.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
(cherry picked from commit 4dd4737)
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
viirya pushed a commit to viirya/spark-1 that referenced this pull request Oct 19, 2023
…ll not report error

### What changes were proposed in this pull request?
This is a backporting PR to branch-3.4 from apache#42810

Changed the way of assert the error to adapt to 3.4

### Why are the changes needed?
Fix bug on 3.4

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
add new test.

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#42876 from Hisoka-X/SPARK-45075_followup_3.4_alter_column.

Authored-by: Jia Fan <fanjiaeminem@qq.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants