Zoltan Borok-Nagy has posted comments on this change. ( 
http://gerrit.cloudera.org:8080/25183 )

Change subject: IMPALA-15615: Create required fields for NOT NULL columns in 
Iceberg ADD COLUMN
......................................................................


Patch Set 1: Code-Review+1

(2 comments)

nits for readability, otherwise LGTM!

http://gerrit.cloudera.org:8080/#/c/25183/1//COMMIT_MSG
Commit Message:

http://gerrit.cloudera.org:8080/#/c/25183/1//COMMIT_MSG@9
PS1, Line 9: ALTER TABLE ... ADD COLUMN(S) on an Iceberg V3 table silently 
dropped
           : NOT NULL when the column had a DEFAULT. The new column was added 
as an
           : optional field ("required":false), DESCRIBE showed it as nullable, 
and
           : NULL could be inserted into it. CREATE TABLE with the same column
           : definition correctly produced a required field.
           : 
           : Since IMPALA-15364, analysis rejects a NOT NULL column without a
           : DEFAULT, and a DEFAULT requires 'format-version' >= 3. So a NOT 
NULL
           : column only reaches the catalog on V3 tables, and always with a 
DEFAULT.
           : IcebergCatalogOpExecutor.addColumns() ignored TColumn.is_nullable 
and
           : always called UpdateSchema.addColumn().
           :
           : This patch makes addColumns() call 
UpdateSchema.addRequiredColumn() when
           : is_nullable is set to false, passing the default literal when 
there is
           : one. Iceberg allows adding a required column when it has a 
default, so
           : no allowIncompatibleChanges() is needed. Existing rows read the
           : initial-default and INSERTs that omit the column get the 
write-default
           : while nullable columns still use addColumn() as before.
           :
           : Testing:
           : - Added e2e tests to iceberg-v3-default-values.test for ADD COLUMN 
and
           :   ADD COLUMNS with NOT NULL DEFAULT:
           :   * DESCRIBE shows nullable=false
           :   * existing rows read the initial-default
           :   * INSERT omitting the columns gets the write-default
           :   * INSERT of explicit NULL fails
nit: could it be less verbose?


http://gerrit.cloudera.org:8080/#/c/25183/1/fe/src/main/java/org/apache/impala/service/IcebergCatalogOpExecutor.java
File fe/src/main/java/org/apache/impala/service/IcebergCatalogOpExecutor.java:

http://gerrit.cloudera.org:8080/#/c/25183/1/fe/src/main/java/org/apache/impala/service/IcebergCatalogOpExecutor.java@179
PS1, Line 179: if (isRequired) {
             :             schema.addRequiredColumn(name, type, doc, 
defaultValue);
             :           } else {
             :             schema.addColumn(name, type, doc, defaultValue);
             :           }
For readability, this could be moved to a helper method:

 void addColumnHelper(boolean isRequired, String name, ...) {
   if (isRequired) {
     schema.addRequiredColumn(name, type, doc, defaultValue);
   } else {
     schema.addColumn(name, type, doc, defaultValue);
   }
 }

Also, in this try block we should just try to parse the default value, adding 
the column to the schema can happen on the common path:

 org.apache.iceberg.expressions.Literal<?> defaultValue = null;
 if (defaultStr != null) {
   try {
     defaultValue =
              IcebergSchemaConverter.parseStringToIcebergLiteral(defaultStr, 
type);
   } catch (Exception e) {
     throw new ImpalaRuntimeException(String.format(
         "Failed to parse default value '%s' for column '%s': %s",
         defaultStr, name, e.getMessage()));
   }
 }
 addColumnHelper(name, type, doc, defaultValue);



--
To view, visit http://gerrit.cloudera.org:8080/25183
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: comment
Gerrit-Change-Id: Idd7e882b1fd86f60fede0964dbcad1a55bea3691
Gerrit-Change-Number: 25183
Gerrit-PatchSet: 1
Gerrit-Owner: Arnab Karmakar <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Zoltan Borok-Nagy <[email protected]>
Gerrit-Comment-Date: Thu, 22 Oct 2026 11:44:27 +0000
Gerrit-HasComments: Yes

Reply via email to