This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 3a6c706dd9 [#14873] fix(catalog-glue): Allow NOT NULL on Iceberg
tables and check char/varchar lengths on Hive tables (#14874)
3a6c706dd9 is described below
commit 3a6c706dd9e3a24adfa88e5e4b732f5c01c643df
Author: Yuhui <[email protected]>
AuthorDate: Wed Nov 11 19:20:49 2026 +0800
[#14873] fix(catalog-glue): Allow NOT NULL on Iceberg tables and check
char/varchar lengths on Hive tables (#14874)
### What changes were proposed in this pull request?
- Remove the catalog-wide NOT NULL capability restriction, and refuse
NOT NULL only on Hive-format tables (create, add column and update
column nullability). Iceberg tables keep nullability in Iceberg
metadata; Iceberg itself refuses changing an optional column to
required.
- Refuse NOT NULL on nested fields (list elements, map values and struct
fields) of Hive-format tables as well.
- Check `char` and `varchar` lengths against the Hive limits when
converting types for Hive-format tables, including nested types.
- Update the Glue catalog docs.
### Why are the changes needed?
NOT NULL is refused on Iceberg tables although Iceberg supports it, and
Hive-format tables accept `char`/`varchar` lengths that Hive-based
readers cannot parse.
Fix: #14873
### Does this PR introduce _any_ user-facing change?
Yes.
- Iceberg tables in a Glue catalog can be created with NOT NULL columns.
Changing a column to NOT NULL is refused by Iceberg as an incompatible
change instead of by the catalog capability.
- Creating or altering a Hive-format table with an out-of-range
`char`/`varchar` length now fails.
### How was this patch tested?
- Added unit tests in `TestGlueTypeConverter`,
`TestGlueCatalogTableOperations`, `TestGlueIcebergTableHelper` and
`TestGlueCatalogCapability`.
- Added `testIcebergColumnNullability` and `testHiveColumnConstraints`
to `AwsGlueCatalogIT`, and ran `AwsGlueCatalogIT` against AWS Glue and
`MotoGlueCatalogIT`.
---
.../catalog/glue/GlueCatalogCapability.java | 15 +--
.../catalog/glue/GlueCatalogOperations.java | 21 +++++
.../gravitino/catalog/glue/GlueTypeConverter.java | 41 ++++++--
.../catalog/glue/TestGlueCatalogCapability.java | 8 +-
.../glue/TestGlueCatalogTableOperations.java | 102 ++++++++++++++++++++
.../catalog/glue/TestGlueIcebergTableHelper.java | 39 ++++++++
.../catalog/glue/TestGlueTypeConverter.java | 43 +++++++++
.../integration/test/AbstractGlueCatalogIT.java | 5 +-
.../glue/integration/test/AwsGlueCatalogIT.java | 104 +++++++++++++++++++++
docs/aws-glue-catalog.md | 7 +-
10 files changed, 358 insertions(+), 27 deletions(-)
diff --git
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogCapability.java
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogCapability.java
index fd87f7cb89..dd0cfd5b69 100644
---
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogCapability.java
+++
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogCapability.java
@@ -34,24 +34,17 @@ import
org.apache.gravitino.connector.capability.CapabilityResult;
* API</a> and <a
*
href="https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-catalog-tables.html">Table
* API</a>: <i>"folded to lowercase when it is stored"</i>.
- * <li><b>No NOT NULL constraints</b>: The Glue {@code Column} structure has
no nullable /
- * constraint field. See <a
- *
href="https://docs.aws.amazon.com/glue/latest/webapi/API_Column.html">Column
API</a>.
* <li><b>No DEFAULT values</b>: The Glue {@code Column} structure has no
{@code defaultValue}
* field. See <a
href="https://docs.aws.amazon.com/glue/latest/webapi/API_Column.html">Column
* API</a>.
* </ul>
+ *
+ * <p>NOT NULL depends on the table format, which a capability cannot see:
Iceberg tables keep it in
+ * their metadata, and {@link GlueCatalogOperations} rejects it on Hive-format
tables, whose Glue
+ * {@code Column} structure has no nullable field.
*/
public class GlueCatalogCapability implements Capability {
- @Override
- public CapabilityResult columnNotNull() {
- // Glue Column structure has no nullable/constraint field — NOT NULL
cannot be expressed.
- // See https://docs.aws.amazon.com/glue/latest/webapi/API_Column.html
- return CapabilityResult.unsupported(
- "AWS Glue Data Catalog does not support NOT NULL constraints on
columns.");
- }
-
@Override
public CapabilityResult columnDefaultValue() {
// Glue Column structure has no defaultValue field — DEFAULT cannot be
expressed.
diff --git
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogOperations.java
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogOperations.java
index 8460eca316..cefcd14a53 100644
---
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogOperations.java
+++
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueCatalogOperations.java
@@ -106,6 +106,12 @@ public class GlueCatalogOperations implements
CatalogOperations, SupportsSchemas
private static final Logger LOG =
LoggerFactory.getLogger(GlueCatalogOperations.class);
+ // The Glue Column structure has no nullable field, so a Hive-format column
cannot be NOT NULL.
+ // See https://docs.aws.amazon.com/glue/latest/webapi/API_Column.html
+ private static final String HIVE_NOT_NULL_UNSUPPORTED =
+ "AWS Glue Data Catalog does not support NOT NULL constraints on columns
of Hive-format"
+ + " tables. Illegal column: %s";
+
/**
* Properties that identify the format of an Iceberg table, its metadata
file and whether it was
* registered; an alter cannot change them.
@@ -535,6 +541,9 @@ public class GlueCatalogOperations implements
CatalogOperations, SupportsSchemas
validateColumns(columns);
// Iceberg tables delegate partitioning and ordering to
GlueIcebergTableHelper.
if (!isIceberg) {
+ for (Column column : columns) {
+ Preconditions.checkArgument(column.nullable(),
HIVE_NOT_NULL_UNSUPPORTED, column.name());
+ }
validateHivePartitioning(columns, partitions);
validateHiveDistribution(distribution);
validateHiveSortOrders(sortOrders);
@@ -845,6 +854,7 @@ public class GlueCatalogOperations implements
CatalogOperations, SupportsSchemas
TableChange.AddColumn add = (TableChange.AddColumn) change;
Preconditions.checkArgument(
!add.isAutoIncrement(), "Glue does not support auto-increment
columns: %s", name);
+ Preconditions.checkArgument(add.isNullable(),
HIVE_NOT_NULL_UNSUPPORTED, name);
Preconditions.checkArgument(
indexOf(dataCols, name) < 0 && indexOf(partCols, name) < 0,
"Column %s already exists",
@@ -868,6 +878,17 @@ public class GlueCatalogOperations implements
CatalogOperations, SupportsSchemas
return true;
}
+ if (change instanceof TableChange.UpdateColumnNullability) {
+ requireColumn(indexOf(dataCols, name) >= 0 ? dataCols : partCols,
name);
+ Preconditions.checkArgument(
+ ((TableChange.UpdateColumnNullability) change).nullable(),
+ HIVE_NOT_NULL_UNSUPPORTED,
+ name);
+ // Every Hive-format column, partition columns included, is nullable
already, so this is a
+ // no-op.
+ return false;
+ }
+
Preconditions.checkArgument(
indexOf(partCols, name) < 0,
"Glue does not support %s on partition column %s",
diff --git
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueTypeConverter.java
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueTypeConverter.java
index d3530dfe73..249d4c654f 100644
---
a/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueTypeConverter.java
+++
b/catalogs/catalog-glue/src/main/java/org/apache/gravitino/catalog/glue/GlueTypeConverter.java
@@ -65,6 +65,15 @@ public class GlueTypeConverter implements
DataTypeConverter<String, String> {
static final String STRUCT = "struct";
static final String UNIONTYPE = "uniontype";
+ // Hive length limits, see
+ // https://cwiki.apache.org/confluence/display/hive/languagemanual+types
+ static final int MAX_CHAR_LENGTH = 255;
+ static final int MAX_VARCHAR_LENGTH = 65535;
+
+ // Hive types carry no nullability, so a nested field cannot be NOT NULL.
+ private static final String NESTED_NOT_NULL_UNSUPPORTED =
+ "Glue/Hive does not support NOT NULL on nested fields, got %s";
+
// Matches name(body): char(10), varchar(255), decimal(10,2)
private static final Pattern PAREN_TYPE_PATTERN =
Pattern.compile("(\\w+)\\(([^)]*)\\)");
// Matches name<body>: array<string>, map<string,int>, struct<id:bigint>
@@ -221,20 +230,37 @@ public class GlueTypeConverter implements
DataTypeConverter<String, String> {
if (type instanceof Types.IntervalYearType) return INTERVAL_YEAR_MONTH;
if (type instanceof Types.IntervalDayType) return INTERVAL_DAY_TIME;
if (type instanceof Types.FixedCharType) {
- return String.format("%s(%d)", CHAR, ((Types.FixedCharType)
type).length());
+ int length = ((Types.FixedCharType) type).length();
+ Preconditions.checkArgument(
+ length >= 1 && length <= MAX_CHAR_LENGTH,
+ "Glue/Hive char length must be in [1, %s], got %s",
+ MAX_CHAR_LENGTH,
+ length);
+ return String.format("%s(%d)", CHAR, length);
}
if (type instanceof Types.VarCharType) {
- return String.format("%s(%d)", VARCHAR, ((Types.VarCharType)
type).length());
+ int length = ((Types.VarCharType) type).length();
+ Preconditions.checkArgument(
+ length >= 1 && length <= MAX_VARCHAR_LENGTH,
+ "Glue/Hive varchar length must be in [1, %s], got %s",
+ MAX_VARCHAR_LENGTH,
+ length);
+ return String.format("%s(%d)", VARCHAR, length);
}
if (type instanceof Types.DecimalType) {
Types.DecimalType d = (Types.DecimalType) type;
return String.format("%s(%d,%d)", DECIMAL, d.precision(), d.scale());
}
if (type instanceof Types.ListType) {
- return String.format("%s<%s>", ARRAY, fromGravitino(((Types.ListType)
type).elementType()));
+ Types.ListType listType = (Types.ListType) type;
+ Preconditions.checkArgument(
+ listType.elementNullable(), NESTED_NOT_NULL_UNSUPPORTED,
listType.simpleString());
+ return String.format("%s<%s>", ARRAY,
fromGravitino(listType.elementType()));
}
if (type instanceof Types.MapType) {
Types.MapType mapType = (Types.MapType) type;
+ Preconditions.checkArgument(
+ mapType.valueNullable(), NESTED_NOT_NULL_UNSUPPORTED,
mapType.simpleString());
return String.format(
"%s<%s,%s>", MAP, fromGravitino(mapType.keyType()),
fromGravitino(mapType.valueType()));
}
@@ -242,9 +268,12 @@ public class GlueTypeConverter implements
DataTypeConverter<String, String> {
String fields =
Arrays.stream(((Types.StructType) type).fields())
.map(
- f ->
- String.format(
- "%s:%s", checkStructFieldName(f.name()),
fromGravitino(f.type())))
+ f -> {
+ Preconditions.checkArgument(
+ f.nullable(), NESTED_NOT_NULL_UNSUPPORTED, "struct
field " + f.name());
+ return String.format(
+ "%s:%s", checkStructFieldName(f.name()),
fromGravitino(f.type()));
+ })
.collect(Collectors.joining(","));
return String.format("%s<%s>", STRUCT, fields);
}
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogCapability.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogCapability.java
index 265081b23b..c3a1e62b9b 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogCapability.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogCapability.java
@@ -37,11 +37,9 @@ class TestGlueCatalogCapability {
}
@Test
- void testColumnNotNullIsUnsupported() {
- CapabilityResult result = capability.columnNotNull();
- assertFalse(result.supported(), "Glue does not enforce NOT NULL
constraints");
- assertNotNull(result.unsupportedMessage());
- assertFalse(result.unsupportedMessage().isEmpty());
+ void testColumnNotNullIsLeftToTableFormat() {
+ // Iceberg tables support NOT NULL; GlueCatalogOperations rejects it on
Hive-format tables.
+ assertTrue(capability.columnNotNull().supported());
}
@Test
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogTableOperations.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogTableOperations.java
index 2acf42697b..5995d42727 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogTableOperations.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueCatalogTableOperations.java
@@ -1110,6 +1110,45 @@ class TestGlueCatalogTableOperations {
created.properties().get(GlueConstants.INPUT_FORMAT_CLASS));
}
+ @Test
+ void testCreateRefusesNotNullColumnOnHiveTable() {
+ Column notNull =
+ GlueColumn.builder()
+ .withName("id")
+ .withType(Types.LongType.get())
+ .withNullable(false)
+ .build();
+ assertCreateRefused(
+ "NOT NULL constraints on columns of Hive-format tables. Illegal
column: id",
+ new Column[] {notNull},
+ Collections.emptyMap(),
+ Transforms.EMPTY_TRANSFORM,
+ Distributions.NONE,
+ SortOrders.NONE);
+ }
+
+ @Test
+ void testCreateRefusesCharLengthOutsideHiveLimit() {
+ assertCreateRefused(
+ "Column c: Glue/Hive char length must be in [1, 255], got 256",
+ new Column[] {col("c", Types.FixedCharType.of(256))},
+ Collections.emptyMap(),
+ Transforms.EMPTY_TRANSFORM,
+ Distributions.NONE,
+ SortOrders.NONE);
+ }
+
+ @Test
+ void testCreateRefusesNestedNotNullOnHiveTable() {
+ assertCreateRefused(
+ "Column tags: Glue/Hive does not support NOT NULL on nested fields,
got list<string, NOT NULL>",
+ new Column[] {col("tags",
Types.ListType.notNull(Types.StringType.get()))},
+ Collections.emptyMap(),
+ Transforms.EMPTY_TRANSFORM,
+ Distributions.NONE,
+ SortOrders.NONE);
+ }
+
@Test
void testCreateUnsupportedTypeNamesColumn() {
assertCreateRefused(
@@ -1295,6 +1334,69 @@ class TestGlueCatalogTableOperations {
assertTrue(e.getMessage().contains("skewed"), e.getMessage());
}
+ @Test
+ void testAlterRefusesNotNullOnHiveTable() {
+ useFakeGlueTable(nativeTable());
+ for (TableChange change :
+ new TableChange[] {
+ TableChange.addColumn(new String[] {"c"}, Types.StringType.get(),
false),
+ TableChange.updateColumnNullability(new String[] {"id"}, false),
+ TableChange.updateColumnNullability(new String[] {"dt"}, false)
+ }) {
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () ->
ops.alterTable(ALTER_IDENT, change));
+ assertTrue(e.getMessage().contains("NOT NULL"), e.getMessage());
+ }
+ verify(mockClient, never()).updateTable(any(UpdateTableRequest.class));
+ }
+
+ @Test
+ void testAlterColumnToNullableIsNoOpOnHiveTable() {
+ useFakeGlueTable(nativeTable());
+ ops.alterTable(ALTER_IDENT, TableChange.updateColumnNullability(new
String[] {"id"}, true));
+ ops.alterTable(ALTER_IDENT, TableChange.updateColumnNullability(new
String[] {"dt"}, true));
+ verify(mockClient, never()).updateTable(any(UpdateTableRequest.class));
+
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ ops.alterTable(
+ ALTER_IDENT,
+ TableChange.updateColumnNullability(new String[]
{"missing"}, true)));
+ assertTrue(e.getMessage().contains("missing"), e.getMessage());
+ }
+
+ @Test
+ void testAlterColumnToNullableKeepsOtherChangesOnHiveTable() {
+ useFakeGlueTable(nativeTable());
+ ops.alterTable(
+ ALTER_IDENT,
+ TableChange.updateColumnNullability(new String[] {"id"}, true),
+ TableChange.updateColumnComment(new String[] {"id"}, "new comment"));
+
+ ArgumentCaptor<UpdateTableRequest> captor =
ArgumentCaptor.forClass(UpdateTableRequest.class);
+ verify(mockClient).updateTable(captor.capture());
+ assertEquals(
+ "new comment",
+
captor.getValue().tableInput().storageDescriptor().columns().get(0).comment());
+ }
+
+ @Test
+ void testAlterRefusesVarcharLengthOutsideHiveLimit() {
+ useFakeGlueTable(nativeTable());
+ for (TableChange change :
+ new TableChange[] {
+ TableChange.addColumn(new String[] {"c"},
Types.VarCharType.of(65536)),
+ TableChange.updateColumnType(new String[] {"k"},
Types.VarCharType.of(0))
+ }) {
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () ->
ops.alterTable(ALTER_IDENT, change));
+ assertTrue(e.getMessage().contains("varchar length must be in [1,
65535]"), e.getMessage());
+ }
+ verify(mockClient, never()).updateTable(any(UpdateTableRequest.class));
+ }
+
@Test
void testAlterRemovingStoragePropertyRemovesParameterOfSameName() {
Table table = nativeTable();
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueIcebergTableHelper.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueIcebergTableHelper.java
index b5d6fb202f..125993b66e 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueIcebergTableHelper.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueIcebergTableHelper.java
@@ -612,6 +612,45 @@ class TestGlueIcebergTableHelper {
}
}
+ @Test
+ void testAlterTableUpdatesColumnNullability() throws IOException {
+ try (InMemoryCatalog catalog = newCatalog()) {
+ catalog.createTable(
+ TableIdentifier.of("db", "t"),
+ new Schema(
+ NestedField.required(1, "id", LongType.get()),
+ NestedField.optional(2, "name", StringType.get())));
+
+ GlueIcebergTableHelper.alterTable(
+ catalog, "db", "t", TableChange.updateColumnNullability(new String[]
{"id"}, true));
+ assertTrue(
+ catalog.loadTable(TableIdentifier.of("db",
"t")).schema().findField("id").isOptional());
+
+ // Iceberg refuses optional -> required as an incompatible change.
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ GlueIcebergTableHelper.alterTable(
+ catalog,
+ "db",
+ "t",
+ TableChange.updateColumnNullability(new String[]
{"name"}, false)));
+ assertTrue(e.getMessage().contains("optional -> required"),
e.getMessage());
+
+ e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ GlueIcebergTableHelper.alterTable(
+ catalog,
+ "db",
+ "t",
+ TableChange.addColumn(new String[] {"c"},
Types.StringType.get(), false)));
+ assertTrue(e.getMessage().contains("optional -> required"),
e.getMessage());
+ }
+ }
+
private static void assertColumnsAfterAlter(List<String> expected,
TableChange... changes)
throws IOException {
try (InMemoryCatalog catalog = newCatalog()) {
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueTypeConverter.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueTypeConverter.java
index c3dbe2e50f..923808d881 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueTypeConverter.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/TestGlueTypeConverter.java
@@ -285,6 +285,49 @@ class TestGlueTypeConverter {
}
}
+ @Test
+ void testCharAndVarcharLengthsWithinHiveLimits() {
+ assertEquals("char(1)",
CONVERTER.fromGravitino(Types.FixedCharType.of(1)));
+ assertEquals("char(255)",
CONVERTER.fromGravitino(Types.FixedCharType.of(255)));
+ assertEquals("varchar(1)",
CONVERTER.fromGravitino(Types.VarCharType.of(1)));
+ assertEquals("varchar(65535)",
CONVERTER.fromGravitino(Types.VarCharType.of(65535)));
+ }
+
+ @Test
+ void testCharAndVarcharLengthsOutsideHiveLimitsAreRefused() {
+ for (Type type :
+ new Type[] {
+ Types.FixedCharType.of(0),
+ Types.FixedCharType.of(256),
+ Types.VarCharType.of(0),
+ Types.VarCharType.of(65536),
+ Types.ListType.nullable(Types.FixedCharType.of(256)),
+ Types.MapType.valueNullable(Types.StringType.get(),
Types.VarCharType.of(65536)),
+ Types.StructType.of(Types.StructType.Field.nullableField("a",
Types.VarCharType.of(0)))
+ }) {
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () ->
CONVERTER.fromGravitino(type));
+ assertTrue(e.getMessage().contains("length must be in [1, "),
e.getMessage());
+ }
+ }
+
+ @Test
+ void testNestedNotNullIsRefused() {
+ for (Type type :
+ new Type[] {
+ Types.ListType.notNull(Types.StringType.get()),
+ Types.MapType.valueNotNull(Types.StringType.get(),
Types.LongType.get()),
+ Types.StructType.of(Types.StructType.Field.notNullField("a",
Types.LongType.get())),
+ Types.ListType.nullable(
+ Types.StructType.of(Types.StructType.Field.notNullField("a",
Types.LongType.get())))
+ }) {
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () ->
CONVERTER.fromGravitino(type));
+ assertTrue(
+ e.getMessage().contains("does not support NOT NULL on nested
fields"), e.getMessage());
+ }
+ }
+
@Test
void testUnsupportedTypeMessageUsesTypeSyntax() {
IllegalArgumentException e =
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AbstractGlueCatalogIT.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AbstractGlueCatalogIT.java
index ccc5a90921..0c42b92bfa 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AbstractGlueCatalogIT.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AbstractGlueCatalogIT.java
@@ -141,7 +141,7 @@ abstract class AbstractGlueCatalogIT {
private Column[] hiveColumns() {
return new Column[] {
- Column.of("id", Types.LongType.get(), "primary key", false, false, null),
+ Column.of("id", Types.LongType.get(), "primary key"),
Column.of("name", Types.StringType.get(), null),
};
}
@@ -168,8 +168,7 @@ abstract class AbstractGlueCatalogIT {
private Column[] partitionedColumns() {
return new Column[] {
- Column.of("id", Types.LongType.get(), null, false, false, null),
- Column.of("dt", Types.DateType.get(), null),
+ Column.of("id", Types.LongType.get(), null), Column.of("dt",
Types.DateType.get(), null),
};
}
diff --git
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AwsGlueCatalogIT.java
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AwsGlueCatalogIT.java
index 0430f7b248..28cb4abb11 100644
---
a/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AwsGlueCatalogIT.java
+++
b/catalogs/catalog-glue/src/test/java/org/apache/gravitino/catalog/glue/integration/test/AwsGlueCatalogIT.java
@@ -44,6 +44,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.function.Executable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
@@ -340,6 +341,109 @@ class AwsGlueCatalogIT extends AbstractGlueCatalogIT {
}
}
+ @Test
+ void testIcebergColumnNullability() {
+ String bucket = System.getenv("AWS_S3_TEST_BUCKET");
+ String schema = "glue_it_" + System.nanoTime();
+ NameIdentifier ident = NameIdentifier.of("ml", "cat", schema,
"ice_nullability");
+ ops.createSchema(NameIdentifier.of("ml", "cat", schema), null,
Collections.emptyMap());
+ Map<String, String> props = new HashMap<>();
+ props.put(GlueConstants.TABLE_FORMAT, "ICEBERG");
+ props.put(GlueConstants.LOCATION, "s3://" + bucket + "/" + schema +
"/ice_nullability");
+ try {
+ ops.createTable(
+ ident,
+ new Column[] {
+ Column.of("id", Types.LongType.get(), null, false, false,
Column.DEFAULT_VALUE_NOT_SET),
+ Column.of("name", Types.StringType.get(), null)
+ },
+ null,
+ props,
+ new Transform[0],
+ Distributions.NONE,
+ new SortOrder[0],
+ new Index[0]);
+ assertFalse(ops.loadTable(ident).columns()[0].nullable());
+
+ ops.alterTable(ident, TableChange.updateColumnNullability(new String[]
{"id"}, true));
+ assertTrue(ops.loadTable(ident).columns()[0].nullable());
+
+ // Iceberg refuses optional -> required as an incompatible change.
+ assertIllegalArgument(
+ "optional -> required",
+ () ->
+ ops.alterTable(
+ ident, TableChange.updateColumnNullability(new String[]
{"name"}, false)));
+ } finally {
+ ops.purgeTable(ident);
+ ops.dropSchema(NameIdentifier.of("ml", "cat", schema), true);
+ }
+ }
+
+ @Test
+ void testHiveColumnConstraints() {
+ String schema = "glue_it_" + System.nanoTime();
+ NameIdentifier ident = NameIdentifier.of("ml", "cat", schema,
"hive_constraints");
+ ops.createSchema(NameIdentifier.of("ml", "cat", schema), null,
Collections.emptyMap());
+ try {
+ assertIllegalArgument(
+ "char length must be in [1, 255]",
+ () -> createHiveTable(ident, Column.of("c",
Types.FixedCharType.of(256), null)));
+ assertIllegalArgument(
+ "NOT NULL",
+ () ->
+ createHiveTable(
+ ident,
+ Column.of(
+ "c",
+ Types.LongType.get(),
+ null,
+ false,
+ false,
+ Column.DEFAULT_VALUE_NOT_SET)));
+
+ createHiveTable(
+ ident,
+ Column.of("c", Types.FixedCharType.of(255), null),
+ Column.of("v", Types.VarCharType.of(65535), null));
+ Table loaded = ops.loadTable(ident);
+ assertEquals(Types.FixedCharType.of(255),
loaded.columns()[0].dataType());
+ assertEquals(Types.VarCharType.of(65535),
loaded.columns()[1].dataType());
+
+ assertIllegalArgument(
+ "varchar length must be in [1, 65535]",
+ () ->
+ ops.alterTable(
+ ident,
+ TableChange.updateColumnType(new String[] {"v"},
Types.VarCharType.of(0))));
+ assertIllegalArgument(
+ "NOT NULL",
+ () ->
+ ops.alterTable(
+ ident, TableChange.updateColumnNullability(new String[]
{"c"}, false)));
+ } finally {
+ ops.dropTable(ident);
+ ops.dropSchema(NameIdentifier.of("ml", "cat", schema), true);
+ }
+ }
+
+ private static void assertIllegalArgument(String messagePart, Executable
executable) {
+ IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
executable);
+ assertTrue(e.getMessage().contains(messagePart), e.getMessage());
+ }
+
+ private void createHiveTable(NameIdentifier ident, Column... columns) {
+ ops.createTable(
+ ident,
+ columns,
+ null,
+ Collections.emptyMap(),
+ new Transform[0],
+ Distributions.NONE,
+ new SortOrder[0],
+ new Index[0]);
+ }
+
private void createIcebergTable(NameIdentifier ident, String location) {
Map<String, String> props = new HashMap<>();
props.put(GlueConstants.TABLE_FORMAT, "ICEBERG");
diff --git a/docs/aws-glue-catalog.md b/docs/aws-glue-catalog.md
index 232444f5b9..221465e677 100644
--- a/docs/aws-glue-catalog.md
+++ b/docs/aws-glue-catalog.md
@@ -91,7 +91,8 @@ See [Manage Catalogs and
Schemas](./manage-catalogs-and-schemas.md#schema-operat
- The Glue catalog supports creating, updating, and deleting tables in the AWS
Glue Data Catalog.
- All entries in the Glue `Table.parameters()` pass through Gravitino intact,
so downstream tools can correctly identify the table format.
- Does not support column default value.
-- Does not support NOT NULL constraints on columns.
+- Does not support NOT NULL constraints on columns of Hive-format tables.
Iceberg tables support them. For Hive-format tables, NOT NULL on nested fields
(list elements, map values and struct fields) is refused as well.
+- `char` and `varchar` columns of Hive-format tables follow the Hive length
limits: `char` length is 1 to 255 and `varchar` length is 1 to 65535.
- Does not support table indexes.
### Table Partitioning
@@ -214,7 +215,7 @@ Iceberg-format table rename is supported.
| `Change Column Comment` | `Update the column comment` |
:::note
-For Hive-format tables, changes to nested struct fields are not supported;
change the whole column instead. Partition columns only support comment
changes. Bucket and sort columns can be renamed but not deleted.
+For Hive-format tables, changes to nested struct fields are not supported;
change the whole column instead. Partition columns only support comment
changes. Making a column nullable is accepted and changes nothing, since every
column is nullable already; making a column NOT NULL is refused. Bucket and
sort columns can be renamed but not deleted.
:::
##### Alter partition
@@ -304,6 +305,8 @@ For Iceberg tables, the following alter operations are
supported:
| Set table property | `Set a table property` |
| Remove table property | `Remove a table property` |
+Iceberg only allows a column to change from required to optional; making an
optional column required, or adding a required column, is refused as an
incompatible schema change.
+
Schema and property changes of one request are committed in one Iceberg
transaction, so they are applied together or not at all. A request that reports
an error may still have been applied, for example when the commit state is
unknown or the reload after the commit fails, so check the table before
retrying. Property changes of a registered table are stored in Glue and do not
use an Iceberg transaction.
:::caution