Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][Iceberg] Support table comment for catalog #7936

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading