You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2020/08/14 16:26:57 UTC

[iceberg] branch master updated: Spark: Reject add column DDL with NOT NULL (#1325)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e2d486  Spark: Reject add column DDL with NOT NULL (#1325)
8e2d486 is described below

commit 8e2d486e77a70bbc9e8b16485a113f35f711513f
Author: Sunitha Kambhampati <sk...@us.ibm.com>
AuthorDate: Fri Aug 14 09:26:44 2020 -0700

    Spark: Reject add column DDL with NOT NULL (#1325)
---
 spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java     | 2 ++
 .../test/java/org/apache/iceberg/spark/sql/TestAlterTable.java    | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java b/spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java
index 03a4ea5..0c848ab 100644
--- a/spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java
+++ b/spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java
@@ -177,6 +177,8 @@ public class Spark3Util {
   }
 
   private static void apply(UpdateSchema pendingUpdate, TableChange.AddColumn add) {
+    Preconditions.checkArgument(add.isNullable(),
+        "Incompatible change: cannot add required column: %s", leafName(add.fieldNames()));
     Type type = SparkSchemaUtil.convert(add.dataType());
     pendingUpdate.addColumn(parentName(add.fieldNames()), leafName(add.fieldNames()), type, add.comment());
 
diff --git a/spark3/src/test/java/org/apache/iceberg/spark/sql/TestAlterTable.java b/spark3/src/test/java/org/apache/iceberg/spark/sql/TestAlterTable.java
index 27ff6e1..0e60758 100644
--- a/spark3/src/test/java/org/apache/iceberg/spark/sql/TestAlterTable.java
+++ b/spark3/src/test/java/org/apache/iceberg/spark/sql/TestAlterTable.java
@@ -27,6 +27,7 @@ import org.apache.iceberg.hadoop.HadoopCatalog;
 import org.apache.iceberg.spark.SparkCatalogTestBase;
 import org.apache.iceberg.types.Types;
 import org.apache.iceberg.types.Types.NestedField;
+import org.apache.spark.SparkException;
 import org.apache.spark.sql.AnalysisException;
 import org.junit.After;
 import org.junit.Assert;
@@ -53,6 +54,13 @@ public class TestAlterTable extends SparkCatalogTestBase {
   }
 
   @Test
+  public void testAddColumnNotNull() {
+    AssertHelpers.assertThrows("Should reject adding NOT NULL column",
+        SparkException.class, "Incompatible change: cannot add required column",
+        () -> sql("ALTER TABLE %s ADD COLUMN c3 INT NOT NULL", tableName));
+  }
+
+  @Test
   public void testAddColumn() {
     sql("ALTER TABLE %s ADD COLUMN point struct<x: double NOT NULL, y: double NOT NULL> AFTER id", tableName);