Skip to content

Commit 72ab38f

Browse files
authored
[Improve][Iceberg] Support table comment for catalog (#7936)
1 parent a2590e8 commit 72ab38f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/catalog/IcebergCatalog.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363

6464
@Slf4j
6565
public class IcebergCatalog implements Catalog {
66+
public static final String PROPS_TABLE_COMMENT = "comment";
67+
6668
private final String catalogName;
6769
private final ReadonlyConfig readonlyConfig;
6870
private final IcebergCatalogLoader icebergCatalogLoader;
@@ -257,14 +259,17 @@ public CatalogTable toCatalogTable(Table icebergTable, TablePath tablePath) {
257259
icebergTable.spec().fields().stream()
258260
.map(PartitionField::name)
259261
.collect(Collectors.toList());
260-
262+
String comment =
263+
Optional.ofNullable(icebergTable.properties())
264+
.map(e -> e.get(PROPS_TABLE_COMMENT))
265+
.orElse(null);
261266
return CatalogTable.of(
262267
org.apache.seatunnel.api.table.catalog.TableIdentifier.of(
263268
catalogName, tablePath.getDatabaseName(), tablePath.getTableName()),
264269
builder.build(),
265270
icebergTable.properties(),
266271
partitionKeys,
267-
null,
272+
comment,
268273
catalogName);
269274
}
270275

seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/utils/SchemaUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
2929
import org.apache.seatunnel.api.table.catalog.exception.TableAlreadyExistException;
3030
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
31+
import org.apache.seatunnel.connectors.seatunnel.iceberg.catalog.IcebergCatalog;
3132
import org.apache.seatunnel.connectors.seatunnel.iceberg.config.SinkConfig;
3233
import org.apache.seatunnel.connectors.seatunnel.iceberg.data.IcebergTypeMapper;
3334
import org.apache.seatunnel.connectors.seatunnel.iceberg.sink.schema.SchemaAddColumn;
@@ -105,6 +106,8 @@ public static Table autoCreateTable(
105106
SinkConfig config = new SinkConfig(readonlyConfig);
106107
// build auto create table
107108
Map<String, String> options = new HashMap<>(table.getOptions());
109+
Optional.ofNullable(table.getComment())
110+
.map(e -> options.put(IcebergCatalog.PROPS_TABLE_COMMENT, e));
108111
// override
109112
options.putAll(config.getAutoCreateProps());
110113
return createTable(catalog, toIcebergTableIdentifier(tablePath), config, schema, options);

seatunnel-connectors-v2/connector-iceberg/src/test/java/org/apache/seatunnel/connectors/seatunnel/iceberg/catalog/IcebergCatalogTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ CatalogTable buildAllTypesTable(TableIdentifier tableIdentifier) {
194194
TableSchema schema = builder.build();
195195
HashMap<String, String> options = new HashMap<>();
196196
options.put("write.parquet.compression-codec", "zstd");
197+
options.put("comment", "test");
197198
return CatalogTable.of(
198-
tableIdentifier, schema, options, Collections.singletonList("dt_col"), "null");
199+
tableIdentifier, schema, options, Collections.singletonList("dt_col"), "test");
199200
}
200201
}

0 commit comments

Comments
 (0)