You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "huyuanfeng2018 (via GitHub)" <gi...@apache.org> on 2024/03/01 01:53:54 UTC
Re: [PR] Flink: Supports specifying comment for iceberg fields in create table and addcolumn syntax using flinksql [iceberg]
huyuanfeng2018 commented on code in PR #9606:
URL: https://github.com/apache/iceberg/pull/9606#discussion_r1508394858
##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/FlinkSchemaUtil.java:
##########
@@ -68,6 +72,33 @@ public static Schema convert(TableSchema schema) {
return freshIdentifierFieldIds(iSchema, schema);
}
+ /** Convert the flink table schema to apache iceberg schema with column comment. */
+ public static Schema convert(ResolvedCatalogTable catalogTable) {
+ List<Column> tableColumns = catalogTable.getResolvedSchema().getColumns();
+ // copy from org.apache.flink.table.api.Schema#toRowDataType
Review Comment:
`toSourceRowDataType` cannot obtain the comment information of the columns
##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/FlinkSchemaUtil.java:
##########
@@ -68,6 +72,33 @@ public static Schema convert(TableSchema schema) {
return freshIdentifierFieldIds(iSchema, schema);
}
+ /** Convert the flink table schema to apache iceberg schema with column comment. */
+ public static Schema convert(ResolvedCatalogTable catalogTable) {
+ List<Column> tableColumns = catalogTable.getResolvedSchema().getColumns();
+ // copy from org.apache.flink.table.api.Schema#toRowDataType
+ DataTypes.Field[] fields =
+ tableColumns.stream()
+ .map(
+ column -> {
+ if (column.getComment().isPresent()) {
+ return DataTypes.FIELD(
+ column.getName(), column.getDataType(), column.getComment().get());
+ } else {
+ return DataTypes.FIELD(column.getName(), column.getDataType());
+ }
+ })
+ .toArray(DataTypes.Field[]::new);
+
+ LogicalType schemaType = DataTypes.ROW(fields).notNull().getLogicalType();
+ Preconditions.checkArgument(
+ schemaType instanceof RowType, "Schema logical type should be RowType.");
+
+ RowType root = (RowType) schemaType;
+ Type converted = root.accept(new FlinkTypeToType(root));
+ Schema iSchema = new Schema(converted.asStructType().fields());
Review Comment:
Many other places are already using `iSchema`, so I think it's better to keep it consistent here.
##########
flink/v1.18/flink/src/main/java/org/apache/iceberg/flink/FlinkSchemaUtil.java:
##########
@@ -68,6 +72,33 @@ public static Schema convert(TableSchema schema) {
return freshIdentifierFieldIds(iSchema, schema);
}
+ /** Convert the flink table schema to apache iceberg schema with column comment. */
+ public static Schema convert(ResolvedCatalogTable catalogTable) {
Review Comment:
+1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org