yihua opened a new pull request, #20830:
URL: https://github.com/apache/hudi/pull/20830
### Describe the issue this Pull Request addresses
closes #20824
With schema on read enabled and the default write configs, `ALTER TABLE ...
RENAME COLUMN` and `DROP COLUMN` fail with `MissingSchemaFieldException` on any
table. `AlterTableCommand.commitWithSchema` runs
`HoodieTable#validateSchema()`, which compares the new schema with the last
committed one by field name, so the old name of a renamed or dropped column
counts as a missing field unless
`hoodie.datasource.write.schema.allow.auto.evolution.column.drop` is set.
### Summary and Changelog
ALTER TABLE now validates only that secondary index columns keep compatible
types, which is why the check was added there, and it refuses a rename or drop
of an indexed column with an explicit message instead of the missing-field
error.
- `HoodieTable#validateAlterTableSchema()` runs the secondary index check
without the table schema compatibility check; `validateSchema()` is unchanged
for writes.
- `validateSecondaryIndexSchemaEvolution` takes whether a missing indexed
column is allowed: true for writes, which may carry fewer columns, false for
ALTER TABLE.
- `TestSpark3DDL` renames and drops an added column on COW and MOR with the
default configs and writes after each step. Without the fix it fails with
`MissingSchemaFieldException: ... Fields missing from incoming schema: {extra}`.
- `TestSecondaryIndex` checks that renaming or dropping an indexed column is
refused.
### Impact
RENAME COLUMN and DROP COLUMN work with schema on read without allowing
column drops for writes. No config change.
### Risk Level
low. Before the secondary index check was added, ALTER TABLE ran no schema
validation, and this returns to that apart from the indexed-column guard, which
is kept and extended to renames and drops. With
`hoodie.avro.schema.validate=true`, ALTER TABLE no longer runs the Avro
compatibility check either; the statement still validates the change against
the internal schema.
### Documentation Update
none
### Contributor's checklist
- [ ] Read through [contributor's
guide](https://hudi.apache.org/contribute/how-to-contribute)
- [ ] Enough context is provided in the sections above
- [ ] Adequate tests were added if applicable
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]