You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "danny0405 (via GitHub)" <gi...@apache.org> on 2023/02/27 09:05:06 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #8054: [HUDI-5854]Support flink table column comment

danny0405 commented on code in PR #8054:
URL: https://github.com/apache/hudi/pull/8054#discussion_r1118454738


##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/HiveSchemaUtils.java:
##########
@@ -251,4 +213,44 @@ public static Pair<List<FieldSchema>, List<FieldSchema>> splitSchemaByPartitionK
     }
     return Pair.of(regularColumns, partitionColumns);
   }
+
+  /**
+   * Create Hive field schemas from Flink table schema including the hoodie metadata fields.
+   */
+  public static List<FieldSchema> toHiveFieldSchemaWithResolved(ResolvedSchema schema, boolean withOperationField) {
+    List<FieldSchema> columns = new ArrayList<>();
+    Collection<String> metaFields = new ArrayList<>(HoodieRecord.HOODIE_META_COLUMNS);
+    if (withOperationField) {
+      metaFields.add(HoodieRecord.OPERATION_METADATA_FIELD);
+    }
+
+    for (String metaField : metaFields) {
+      columns.add(new FieldSchema(metaField, "string", null));
+    }
+    columns.addAll(createHiveColumnsWithResolved(schema));
+    return columns;
+  }
+
+  /**
+   * Create Hive columns from Flink table schema.
+   */
+  private static List<FieldSchema> createHiveColumnsWithResolved(ResolvedSchema schema) {
+    final DataType dataType = schema.toPhysicalRowDataType();
+    List<Column> sourceColumns = schema.getColumns();
+    final RowType rowType = (RowType) dataType.getLogicalType();
+    final String[] fieldNames = rowType.getFieldNames().toArray(new String[0]);
+    final DataType[] fieldTypes = dataType.getChildren().toArray(new DataType[0]);
+
+    List<FieldSchema> columns = new ArrayList<>(fieldNames.length);
+
+    for (int i = 0; i < fieldNames.length; i++) {
+      columns.add(

Review Comment:
   Why just move these methods around?



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org