yihua opened a new issue, #20828:
URL: https://github.com/apache/hudi/issues/20828

   A Hudi table created through Spark SQL does not keep the NOT NULL 
constraints of its columns. After
   
   ```sql
   CREATE TABLE t (id INT NOT NULL, name STRING NOT NULL, price DOUBLE, ts 
BIGINT)
   USING hudi TBLPROPERTIES (primaryKey = 'id', preCombineField = 'ts');
   ```
   
   both `INSERT INTO t VALUES (1, NULL, 1.0, 1000)` and `UPDATE t SET name = 
NULL WHERE id = 2` succeed, on copy-on-write and merge-on-read tables, and 
`name` then reads as NULL.
   
   The constraint is lost in more than one place:
   - `hoodie.table.create.schema` keeps `id` and `name` as non-null, but 
`HoodieCatalogTable#loadTableSchemaByMetaClient` marks every field nullable, so 
the schema in the session catalog has no NOT NULL columns and Spark adds no 
null check on writes.
   - The first write commits an all-nullable schema: the incoming batch's 
schema is nullable, and `HoodieSchemaUtils#deduceWriterSchema` accepts a 
nullable field over a non-null one as a compatible change, so the commit 
metadata schema no longer has the constraint.
   
   Making all fields nullable looks deliberate (it keeps the catalog schema 
aligned with the table schema), so enforcing NOT NULL would change how existing 
tables behave: writes that pass today would start failing, and tables that 
already committed an all-nullable schema have no record of the constraint. 
Proposal: decide whether Hudi should keep and enforce column nullability from 
the DDL; if so, keep it in the catalog schema and refuse to widen a NOT NULL 
column on write unless the DDL changes it.
   


-- 
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]

Reply via email to