Skip to content

Commit 2b59d23

Browse files
aanejadjsstarburst
andcommitted
Support enforcement of NOT NULL column declarations
Original support was added via #2ad67dcf, but missed adding it for Iceberg tables Cherry-pick of trinodb/trino#4144 Co-authored-by: djsstarburst <[email protected]>
1 parent ff042d8 commit 2b59d23

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ protected List<ColumnMetadata> getColumnMetadata(ConnectorSession session, Table
718718
.map(column -> ColumnMetadata.builder()
719719
.setName(normalizeIdentifier(session, column.name()))
720720
.setType(toPrestoType(column.type(), typeManager))
721+
.setNullable(column.isOptional())
721722
.setComment(column.doc())
722723
.setHidden(false)
723724
.setExtraInfo(partitionFields.containsKey(column.name()) ?

presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,17 @@ private long getLatestSnapshotId()
741741
@Test
742742
public void testInsertIntoNotNullColumn()
743743
{
744-
// TODO: To support non-null column. (NOT_NULL_COLUMN_CONSTRAINT)
744+
assertUpdate("CREATE TABLE test_not_null_table (c1 INTEGER, c2 INTEGER NOT NULL)");
745+
assertUpdate("INSERT INTO test_not_null_table (c2) VALUES (2)", 1);
746+
assertQuery("SELECT * FROM test_not_null_table", "VALUES (NULL, 2)");
747+
assertQueryFails("INSERT INTO test_not_null_table (c1) VALUES (1)", "NULL value not allowed for NOT NULL column: c2");
748+
assertUpdate("DROP TABLE IF EXISTS test_not_null_table");
749+
750+
assertUpdate("CREATE TABLE test_commuted_not_null_table (a BIGINT, b BIGINT NOT NULL)");
751+
assertUpdate("INSERT INTO test_commuted_not_null_table (b) VALUES (2)", 1);
752+
assertQuery("SELECT * FROM test_commuted_not_null_table", "VALUES (NULL, 2)");
753+
assertQueryFails("INSERT INTO test_commuted_not_null_table (b, a) VALUES (NULL, 3),(4, NULL),(NULL, NULL)", "NULL value not allowed for NOT NULL column: b");
754+
assertUpdate("DROP TABLE IF EXISTS test_commuted_not_null_table");
745755
}
746756

747757
@Test

0 commit comments

Comments
 (0)