You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by mi...@apache.org on 2026/10/05 20:36:22 UTC
(impala) 01/02: IMPALA-15364: Reject ALTER TABLE ADD COLUMNS with NOT NULL and no default on Iceberg tables
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git
commit 52c9ac263606587d2d37a3657af01d4b5e297fd2
Author: Nandor Kollar <ko...@gmail.com>
AuthorDate: Fri Sep 25 09:43:49 2026 +0200
IMPALA-15364: Reject ALTER TABLE ADD COLUMNS with NOT NULL and no default on Iceberg tables
Previously, ALTER TABLE ADD COLUMNS on an Iceberg table silently
accepted NOT NULL columns without a default value. The NOT NULL
constraint was then quietly dropped, making the column nullable.
This is incorrect because existing rows would have no valid value
for the new required column.
This patch adds an analysis-time check in AlterTableAddColsStmt
that rejects adding a NOT NULL column without a default value on
Iceberg tables, mirroring the existing validation for Kudu tables.
The error message is: "A new non-null column must have a default
value: <column definition>".
Note that since Iceberg v2 tables do not support default values,
this means NOT NULL columns cannot be added via ALTER TABLE on v2
tables at all. Users can either add the column as nullable, or
upgrade to format version 3 which supports default values:
ALTER TABLE t ADD COLUMNS (j INT NOT NULL DEFAULT 0)
Testing:
- Updated AnalyzeDDLTest#TestAlterTableAddColumn to expect an
AnalysisError for NOT NULL without default on Iceberg.
- Added a new AnalysisError case in TestAlterTableAddColumns for
multi-column ADD COLUMNS on Iceberg.
- Added an end-to-end test case in iceberg-alter-v2.test.
Change-Id: I9bf294664ef83d26ca90db28df0993805d5ce67e
Assisted-by: Claude Opus 4.6 (Claude Code)
Reviewed-on: http://gerrit.cloudera.org:8080/24944
Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
.../java/org/apache/impala/analysis/AlterTableAddColsStmt.java | 7 +++++--
.../test/java/org/apache/impala/analysis/AnalyzeDDLTest.java | 10 ++++++++--
.../functional-query/queries/QueryTest/iceberg-alter-v2.test | 10 ++++++++++
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddColsStmt.java b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddColsStmt.java
index 28bb10f1b..5b316f6b7 100644
--- a/fe/src/main/java/org/apache/impala/analysis/AlterTableAddColsStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/AlterTableAddColsStmt.java
@@ -131,13 +131,16 @@ public class AlterTableAddColsStmt extends AlterTableStmt {
throw new AnalysisException("A new non-null column must have a default " +
"value: " + c.toString());
}
- } else if (t instanceof FeIcebergTable) {
- FeIcebergTable iceTbl = (FeIcebergTable) t;
+ } else if (t instanceof FeIcebergTable iceTbl) {
// For Iceberg tables, only default values are supported as column options
if (c.hasIncompatibleIcebergOptions()) {
throw new AnalysisException("The specified column options are not supported " +
"in Iceberg tables: " + c.toString());
}
+ if (c.isExplicitNotNullable() && !c.hasDefaultValue()) {
+ throw new AnalysisException("A new non-null column must have a " +
+ "default value: " + c.toString());
+ }
if (c.hasDefaultValue() && iceTbl.getFormatVersion() < 3) {
throw new AnalysisException(String.format(
"Adding column with DEFAULT on Iceberg tables requires '%s' >= 3 " +
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
index ddb4f74fc..6cd345b67 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
@@ -585,8 +585,9 @@ public class AnalyzeDDLTest extends FrontendTestBase {
// ALTER TABLE ADD COLUMN(S): allowed on Iceberg.
AnalyzesOk("alter table functional_parquet.iceberg_non_partitioned " +
"add column uuid_col UUID");
- AnalyzesOk("alter table functional_parquet.iceberg_partitioned " +
- "add column uuid_col UUID NOT NULL");
+ AnalysisError("alter table functional_parquet.iceberg_partitioned " +
+ "add column uuid_col UUID NOT NULL",
+ "A new non-null column must have a default value");
AnalyzesOk("alter table functional_parquet.iceberg_non_partitioned " +
"add columns (uuid_col UUID, uuid_col2 UUID)");
}
@@ -668,6 +669,11 @@ public class AnalyzeDDLTest extends FrontendTestBase {
"(new_col int not null)",
"A new non-null column must have a default value: new_col INT NOT NULL");
+ // A non-null column must have a default on Iceberg table.
+ AnalysisError("alter table functional_parquet.iceberg_partitioned " +
+ "add columns (new_col int not null)",
+ "A new non-null column must have a default value: new_col INT NOT NULL");
+
// Cannot ALTER ADD COLUMN complex type on Kudu table.
AnalysisError("alter table functional_kudu.alltypes add columns (c struct<f1:int>)",
"Kudu tables do not support complex types: c STRUCT<f1:INT>");
diff --git a/testdata/workloads/functional-query/queries/QueryTest/iceberg-alter-v2.test b/testdata/workloads/functional-query/queries/QueryTest/iceberg-alter-v2.test
index 695310c9e..a5a01e81a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/iceberg-alter-v2.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/iceberg-alter-v2.test
@@ -505,3 +505,13 @@ DESCRIBE ice_alter_cols;
---- TYPES
STRING,STRING,STRING,STRING
====
+---- QUERY
+# IMPALA-15364: Adding a NOT NULL column without a default value should be
+# rejected because existing rows have no value for the new column.
+CREATE TABLE ice_not_null_no_default (i INT)
+STORED AS ICEBERG TBLPROPERTIES('format-version'='2');
+INSERT INTO ice_not_null_no_default VALUES (1);
+ALTER TABLE ice_not_null_no_default ADD COLUMNS (j INT NOT NULL);
+---- CATCH
+A new non-null column must have a default value
+====