hudi-agent commented on code in PR #18723:
URL: https://github.com/apache/hudi/pull/18723#discussion_r3370496283
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/util/DataTypeUtils.java:
##########
@@ -120,6 +124,48 @@ public static int[] projectOrdinals(RowType rowType,
RowType producedRowType) {
return
producedRowType.getFieldNames().stream().mapToInt(fieldNames::indexOf).toArray();
}
+ /**
+ * Creates a hoodie schema from a Flink row type with logical metadata from
the table schema.
+ *
+ * <p>When a field is a hoodie specific logical type in {@code tableSchema},
this method
+ * reuses the table schema field to preserve logical metadata that cannot be
recovered from Flink
+ * {@link RowType}, for example VECTOR element type and dimension. Other
fields are taken from the
+ * schema converted from {@code rowType}, so the returned schema follows the
row type's field order
+ * while retaining hoodie-specific logical metadata where needed.
+ *
+ * @param rowType Flink row type to convert
+ * @param tableSchema source table schema with hoodie logical type metadata
+ * @return hoodie schema matching the row type field order
+ */
+ public static HoodieSchema toHoodieSchema(RowType rowType, HoodieSchema
tableSchema) {
+ HoodieSchema convertedSchema =
HoodieSchemaConverter.convertToSchema(rowType);
+ List<HoodieSchemaField> schemaFields = new
ArrayList<>(rowType.getFieldCount());
+
+ for (String fieldName : rowType.getFieldNames()) {
+ HoodieSchemaField tableField =
tableSchema.getField(fieldName).orElse(null);
+ HoodieSchemaField field = tableField != null &&
useTableSchemaField(tableField)
+ ? tableField : convertedSchema.getField(fieldName).get();
+ schemaFields.add(HoodieSchemaUtils.createNewSchemaField(field));
+ }
+
+ return HoodieSchema.createRecord(
+ tableSchema.getName(),
+ tableSchema.getNamespace().orElse(null),
+ tableSchema.getDoc().orElse(null),
+ schemaFields);
+ }
+
+ /**
+ * Returns whether the converted schema should reuse the field from the
table schema.
+ *
+ * <p>Only types whose logical metadata cannot be fully reconstructed from
Flink
Review Comment:
🤖 nit: `useTableSchemaField` reads as an imperative verb rather than a
predicate — could you rename it to something like `isHoodieSpecificLogicalType`
or `hasHoodieSpecificMetadata` so it reads naturally as a boolean query?
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
##########
hudi-common/src/main/java/org/apache/hudi/common/util/HoodieVectorUtils.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.util;
+
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.schema.HoodieSchemaField;
+import org.apache.hudi.common.schema.HoodieSchemaType;
+
+import java.nio.ByteBuffer;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Utilities for decoding Hudi VECTOR fixed-bytes payloads.
+ */
Review Comment:
🤖 nit: the class Javadoc says "Hudi" — could you change it to "Hoodie" to
match the codebase's historical convention? e.g. "Utilities for decoding Hoodie
VECTOR fixed-bytes payloads."
<sub><i>- AI-generated; verify before applying. React 👍/👎 to flag
quality.</i></sub>
--
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]