Uh oh!
There was an error while loading. Please reload this page.
[SPARK-51771][SQL] Add DSv2 APIs for ALTER TABLE ADD/DROP CONSTRAINT - #50561
[SPARK-51771][SQL] Add DSv2 APIs for ALTER TABLE ADD/DROP CONSTRAINT#50561gengliangwang wants to merge 8 commits into
Conversation
gengliangwang
commented
Apr 10, 2025
cc @aokolnychyi as well |
| case a: AlterTableCommand if a.table.resolved => | ||
| val table = a.table.asInstanceOf[ResolvedTable] | ||
| ResolveTableConstraints.validateCatalogForTableChange( |
There was a problem hiding this comment.
Note: there will be new tests for this one when the alter table with constraint is supported end-to-end.
| val newConstraint = add.getConstraint | ||
| val existingConstraint = findExistingConstraint(newConstraint.name) | ||
| if (existingConstraint.isDefined) { | ||
| throw new AnalysisException( |
There was a problem hiding this comment.
When do we define dedicated error methods in classes like QueryComplicationErrors? Do we encourage external connectors to use built-in error classes in Spark?
There was a problem hiding this comment.
All the spark errors are with error classes. This is a utility method for external developers to use directly.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| /** A TableChange to alter table and add a constraint. */ | ||
| final class AddConstraint implements TableChange { | ||
| private final Constraint constraint; | ||
| private final boolean validate; |
There was a problem hiding this comment.
During the discussion, the SPIP design evolved to be like this:
class AddConstraint implements TableChange {
private final Constraint constraint;
private final String validatedTableVersion; // if known and was validated …
}
If Spark validated the constraint, it should set the validation status in the constraint to VALID. The table version will be there, if known.
interface Table {
…
// reports the current table version, if supported
default String currentVersion() { return null; }
…
}
There was a problem hiding this comment.
TBH I am a bit confused on this one. Shall we make it simple and let the external table catalog to track the validatedTableVersion?
There was a problem hiding this comment.
The problem is that Spark will construct a scan to do the validation. We need a way to pass which version of the table was scanned/validated back to the connector so that the connector can check changes that happened concurrently.
Uh oh!
There was an error while loading. Please reload this page.
| }, | ||
| "CONSTRAINT_ALREADY_EXISTS" : { | ||
| "message" : [ | ||
| "Constraint '<constraintName>' already exists. Please delete the existing constraint first.", |
There was a problem hiding this comment.
is constraint name scoped to table? wondering should we also put tableName like the other message?
There was a problem hiding this comment.
This error is from alter table statement, which is usually simple and straightforward. I prefer keeping it as it is now
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Udaundo1973
commented
Apr 14, 2025
James Channel |
| errorClass = "CONSTRAINT_ALREADY_EXISTS", | ||
| messageParameters = | ||
| Map("constraintName" -> existingConstraint.get.name, | ||
| "oldConstraint" -> existingConstraint.get.toDDL)) |
There was a problem hiding this comment.
do we really need to display the old constraints? Are there security issues?
There was a problem hiding this comment.
It would be easier for users to know what is in the old constraint without running a describe table command and find details.
Constraints should be simple. We will show all the constraints in describe table command anyway.
| /** | ||
| * Apply Table Constraints changes to an existing table and return the result. | ||
| */ | ||
| def applyConstraintChanges( |
There was a problem hiding this comment.
this is not apply, but more like collect constraints.
gengliangwang
commented
Apr 15, 2025
@viirya@aokolnychyi@cloud-fan Thanks for the review. Merging this one to master. If there are more comments, I can resolve them in follow-up PRs |
What changes were proposed in this pull request?
This PR adds the following DSv2 TableChange as per SPIP doc:
Why are the changes needed?
For constraints support in Spark
Does this PR introduce any user-facing change?
No
How was this patch tested?
New unit tests
Was this patch authored or co-authored using generative AI tooling?
No