Repository navigation
Beam SQL Primary Keys - #40826
Beam SQL Primary Keys#40826ahmedabu98 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR cleanly adds DDL and catalog support for PRIMARY KEY ... NOT ENFORCED in CREATE EXTERNAL TABLE and ALTER TABLE statements, along with Iceberg catalog integration for identifier fields. The implementation is well-structured and includes thorough parser and Iceberg tests.
🔍 General Feedback
- When combining schema updates (
ADD COLUMNS/DROP COLUMNS) and primary key updates in a singleALTER TABLEstatement,SqlAlterTablecurrently validates the primary key against the pre-alter table schema, which can lead to inconsistent state or unexpected validation failures. InMemoryMetaStore.alterTabledoes not refresh its cachedTablemetadata when the underlyingTableProviderupdates the table during anALTER TABLEoperation.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
💬 Inline Findings
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlAlterTable.java(line 138): 🟡 Medium:validatePrimaryKeycheckstable.getSchema(), which reflects the schema beforecolumnsToAddandcolumnsToDropare applied inalterOps.updateSchema(...).
Because the grammar allows combining column changes and primary key changes in a single ALTER TABLE statement (as tested in testUnparseAlter_AllOperations), this leads to two issues:
ALTER TABLE t DROP COLUMNS (pk_col) DROP PRIMARY KEY ADD PRIMARY KEY (other_col) NOT ENFORCED(orDROP COLUMNS (id) ADD PRIMARY KEY (id) NOT ENFORCED) will passvalidatePrimaryKeybecauseidstill exists intable.getSchema()prior toupdateSchema, and then fail later inside the storage engine after already committing the column drop.ALTER TABLE t ADD COLUMNS (c1 INT NOT NULL) ADD PRIMARY KEY (c1) NOT ENFORCEDwill failvalidatePrimaryKeybecausec1is not yet intable.getSchema().
Consider accounting for columnsToAdd and columnsToDropList when validating the primary key columns (or rejecting combined column and primary key alterations if they are not meant to be supported in one statement).
sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlAlterTable.java(line 288): 🟢 Nit:getOperandList()includesname,setProps, andresetProps, but omitsprimaryKeyToAdd(as well as the previously added column/partition lists). Consider addingprimaryKeyToAddif non-null so Calcite AST traversal can inspect allSqlNodeoperands.
|
R: @chamikaramj |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #40826 +/- ##
=============================================
- Coverage 80.04% 64.39% -15.66%
- Complexity 0 2383 +2383
=============================================
Files 490 322 -168
Lines 82916 15684 -67232
Branches 0 2043 +2043
=============================================
- Hits 66373 10100 -56273
+ Misses 16543 4806 -11737
- Partials 0 778 +778
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Full proposal here: https://docs.google.com/document/d/1lGynrfHlyvcmmyzJZ2gkL9zK8KF1ZnfkcImnMmM_ciw/edit?tab=t.0#heading=h.kmw5c7qyihe9
Adds support for the following in Beam SQL:
Each table type should have its own logic to modify the underlying data source's table PK