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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]