Skip to content

Commit

Permalink
[Improve][Iceberg] Support table comment for catalog (#7936)
Browse files Browse the repository at this point in the history
  • Loading branch information
hailin0 authored Oct 29, 2024
1 parent a2590e8 commit 72ab38f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

@Slf4j
public class IcebergCatalog implements Catalog {
public static final String PROPS_TABLE_COMMENT = "comment";

private final String catalogName;
private final ReadonlyConfig readonlyConfig;
private final IcebergCatalogLoader icebergCatalogLoader;
Expand Down Expand Up @@ -257,14 +259,17 @@ public CatalogTable toCatalogTable(Table icebergTable, TablePath tablePath) {
icebergTable.spec().fields().stream()
.map(PartitionField::name)
.collect(Collectors.toList());

String comment =
Optional.ofNullable(icebergTable.properties())
.map(e -> e.get(PROPS_TABLE_COMMENT))
.orElse(null);
return CatalogTable.of(
org.apache.seatunnel.api.table.catalog.TableIdentifier.of(
catalogName, tablePath.getDatabaseName(), tablePath.getTableName()),
builder.build(),
icebergTable.properties(),
partitionKeys,
null,
comment,
catalogName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.seatunnel.api.table.catalog.exception.DatabaseNotExistException;
import org.apache.seatunnel.api.table.catalog.exception.TableAlreadyExistException;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.connectors.seatunnel.iceberg.catalog.IcebergCatalog;
import org.apache.seatunnel.connectors.seatunnel.iceberg.config.SinkConfig;
import org.apache.seatunnel.connectors.seatunnel.iceberg.data.IcebergTypeMapper;
import org.apache.seatunnel.connectors.seatunnel.iceberg.sink.schema.SchemaAddColumn;
Expand Down Expand Up @@ -105,6 +106,8 @@ public static Table autoCreateTable(
SinkConfig config = new SinkConfig(readonlyConfig);
// build auto create table
Map<String, String> options = new HashMap<>(table.getOptions());
Optional.ofNullable(table.getComment())
.map(e -> options.put(IcebergCatalog.PROPS_TABLE_COMMENT, e));
// override
options.putAll(config.getAutoCreateProps());
return createTable(catalog, toIcebergTableIdentifier(tablePath), config, schema, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ CatalogTable buildAllTypesTable(TableIdentifier tableIdentifier) {
TableSchema schema = builder.build();
HashMap<String, String> options = new HashMap<>();
options.put("write.parquet.compression-codec", "zstd");
options.put("comment", "test");
return CatalogTable.of(
tableIdentifier, schema, options, Collections.singletonList("dt_col"), "null");
tableIdentifier, schema, options, Collections.singletonList("dt_col"), "test");
}
}

0 comments on commit 72ab38f

Please sign in to comment.