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-48720][SQL] Align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 #47097

Closed
wants to merge 11 commits into from

Conversation

panbingkun
Copy link
Contributor

@panbingkun panbingkun commented Jun 26, 2024

What changes were proposed in this pull request?

The pr aims to:

  • align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2.
    (this means that in the v1, regardless of whether IF EXISTS is specified or not, when unset a non-existent property, it is ignored and no longer fails.)
  • update the description of ALTER TABLE ... UNSET TBLPROPERTIES ... in the doc docs/sql-ref-syntax-ddl-alter-table.md.
  • unify v1 and v2 ALTER TABLE ... UNSET TBLPROPERTIES ... tests.
  • Add the following scenario for ALTER TABLE ... SET TBLPROPERTIES ... testing
    A.table to alter does not exist
    B.alter table set reserved properties

Why are the changes needed?

  • align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2, avoid confusing end-users.
  • to improve test coverage.
  • align with other similar tests, eg: AlterTableSetTblProperties*

Does this PR introduce any user-facing change?

Yes, in the v1, regardless of whether IF EXISTS is specified or not, when unset a non-existent property, it is ignored and no longer fails

How was this patch tested?

Update some UT & Pass GA.

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

No.

@github-actions github-actions bot added the SQL label Jun 26, 2024
@panbingkun
Copy link
Contributor Author

panbingkun commented Jun 27, 2024

  • In Unify v1 and v2 ALTER TABLE .. UNSET TBLPROPERTIES tests migration, I found syntax:

    ALTER TABLE ... UNSET TBLPROPERTIES IF EXISTS ('key1');
    

    v1:

    If the property `key1` of the table do not exist, it will throw exception `UNSET_NONEXISTENT_PROPERTIES`
    

    v2 :

    If the property `key1` of the table do not exist,  it will ignore the property `key1` (non-existent) and finally succeed (slience)
    
  • I originally planned to align its logic, which was to throw the same exception UNSET_NONEXISTENT_PROPERTIES as v1. However, based on the previous discussion in [SPARK-48668][SQL] Support ALTER NAMESPACE ... UNSET PROPERTIES in v2 #47038, it seems that we can keep the current logic and only reflect this difference in UT, while also note it in the document:

`ALTER TABLE UNSET` is used to drop the table property.

@cloud-fan What do you think?

@cloud-fan
Copy link
Contributor

cloud-fan commented Jul 1, 2024

Yea UNSET non-existing property should be noop. BTW we should throw table not found error if table does not exist.

@panbingkun
Copy link
Contributor Author

Okay, let me update it.

@github-actions github-actions bot added the DOCS label Jul 2, 2024
@panbingkun panbingkun changed the title [SPARK-48720][SQL] Fix IF EXISTS ignored for ALTER TABLE ... UNSET … TBLPROPERTIES ... in v2 [SPARK-48720][SQL] Explain the diff between command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 in doc docs/sql-ref-syntax-ddl-alter-table.md. Jul 2, 2024
@panbingkun panbingkun changed the title [SPARK-48720][SQL] Explain the diff between command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 in doc docs/sql-ref-syntax-ddl-alter-table.md. [SPARK-48720][SQL] Explain the diff between command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 in doc Jul 2, 2024
@panbingkun panbingkun changed the title [SPARK-48720][SQL] Explain the diff between command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 in doc [SPARK-48720][SQL] Clarify the command ALTER TABLE ... UNSET TBLPROPERTIES ... diff between v1 and v2 in doc Jul 2, 2024
@@ -1075,25 +1075,6 @@ class DDLParserSuite extends AnalysisTest {
ifExists = true))
}

// ALTER TABLE table_name UNSET TBLPROPERTIES [IF EXISTS] ('comment', 'key');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests have been migrated to AlterTableUnsetTblPropertiesParserSuite

@@ -107,18 +107,6 @@ class DDLParserSuite extends AnalysisTest with SharedSparkSession {
stop = 98))
}

test("alter table unset properties - property values must NOT be set") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test has been migrated to AlterTableUnsetTblPropertiesParserSuite

sql("ALTER TABLE tab1 UNSET TBLPROPERTIES IF EXISTS ('c', 'xyz')")
assert(getProps == Map("x" -> "y"))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above test was migrated to AlterTableUnsetTblPropertiesSuite* and split into table to alter does not exist, alter table unset properties and alter table unset non-existent properties, as alter table unset non-existent properties behaves differently in v1 and v2.

// property to unset does not exist
checkError(
exception = intercept[AnalysisException] {
sql(s"ALTER TABLE $t UNSET TBLPROPERTIES ('k3', 'k4')")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This scenario uses different behaviors in v1 and v2.

@panbingkun
Copy link
Contributor Author

@cloud-fan It's ready now, thanks.

@panbingkun panbingkun marked this pull request as ready for review July 2, 2024 07:41

-- Unset Table Properties
**Note:** If the specified property key does not exist, when you use the v1 command and do not specify `IF EXISTS`,
it will throw the error-condition `UNSET_NONEXISTENT_PROPERTIES` and finally `failed`,
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we change the v1 behavior as well? It's not a breaking change to change from failure to no failure.

Copy link
Contributor

Choose a reason for hiding this comment

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

and we should avoid mentioning v1/v2 in the doc. It's an internal concept and should not be exposed to end users

Copy link
Contributor Author

@panbingkun panbingkun Jul 2, 2024

Choose a reason for hiding this comment

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

shall we change the v1 behavior as well? It's not a breaking change to change from failure to no failure.

Sure, let me update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and we should avoid mentioning v1/v2 in the doc. It's an internal concept and should not be exposed to end users

Okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shall we change the v1 behavior as well? It's not a breaking change to change from failure to no failure.

Done.

@panbingkun panbingkun changed the title [SPARK-48720][SQL] Clarify the command ALTER TABLE ... UNSET TBLPROPERTIES ... diff between v1 and v2 in doc [SPARK-48720][SQL] Align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 Jul 3, 2024
@panbingkun panbingkun changed the title [SPARK-48720][SQL] Align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 [SPARK-48720][SQL] Align the command ALTER TABLE ... UNSET TBLPROPERTIES ... in v1 and v2 Jul 3, 2024
##### Syntax

```sql
-- Unset Properties
ALTER TABLE table_identifier UNSET TBLPROPERTIES [ IF EXISTS ] ( key1, key2, ... )
Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove [ IF EXISTS ] as a way to deprecate. It's no longer effective.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@LuciferYang LuciferYang 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

ericm-db pushed a commit to ericm-db/spark that referenced this pull request Jul 10, 2024
…TIES ...` in v1 and v2

### What changes were proposed in this pull request?
The pr aims to:
- align the command `ALTER TABLE ... UNSET TBLPROPERTIES ...` in v1 and v2.
(this means that in the v1, regardless of whether `IF EXISTS` is specified or not, when unset a `non-existent` property, it is `ignored` and no longer `fails`.)
- update the description of `ALTER TABLE ... UNSET TBLPROPERTIES ...` in the doc `docs/sql-ref-syntax-ddl-alter-table.md`.
- unify v1 and v2 `ALTER TABLE ... UNSET TBLPROPERTIES ...` tests.
- Add the following `scenario` for `ALTER TABLE ... SET TBLPROPERTIES ...` testing
A.`table to alter does not exist`
B.`alter table set reserved properties`

### Why are the changes needed?
- align the command `ALTER TABLE ... UNSET TBLPROPERTIES ...` in v1 and v2, avoid confusing end-users.
- to improve test coverage.
- align with other similar tests, eg: `AlterTableSetTblProperties*`

### Does this PR introduce _any_ user-facing change?
Yes, in the `v1`, regardless of whether `IF EXISTS` is specified or not, when unset a `non-existent` property, it is `ignored` and no longer `fails`

### How was this patch tested?
Update some UT & Pass GA.

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

Closes apache#47097 from panbingkun/alter_unset_table.

Authored-by: panbingkun <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
jingz-db pushed a commit to jingz-db/spark that referenced this pull request Jul 22, 2024
…TIES ...` in v1 and v2

### What changes were proposed in this pull request?
The pr aims to:
- align the command `ALTER TABLE ... UNSET TBLPROPERTIES ...` in v1 and v2.
(this means that in the v1, regardless of whether `IF EXISTS` is specified or not, when unset a `non-existent` property, it is `ignored` and no longer `fails`.)
- update the description of `ALTER TABLE ... UNSET TBLPROPERTIES ...` in the doc `docs/sql-ref-syntax-ddl-alter-table.md`.
- unify v1 and v2 `ALTER TABLE ... UNSET TBLPROPERTIES ...` tests.
- Add the following `scenario` for `ALTER TABLE ... SET TBLPROPERTIES ...` testing
A.`table to alter does not exist`
B.`alter table set reserved properties`

### Why are the changes needed?
- align the command `ALTER TABLE ... UNSET TBLPROPERTIES ...` in v1 and v2, avoid confusing end-users.
- to improve test coverage.
- align with other similar tests, eg: `AlterTableSetTblProperties*`

### Does this PR introduce _any_ user-facing change?
Yes, in the `v1`, regardless of whether `IF EXISTS` is specified or not, when unset a `non-existent` property, it is `ignored` and no longer `fails`

### How was this patch tested?
Update some UT & Pass GA.

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

Closes apache#47097 from panbingkun/alter_unset_table.

Authored-by: panbingkun <[email protected]>
Signed-off-by: yangjie01 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants