hudi-agent commented on code in PR #18723: URL: https://github.com/apache/hudi/pull/18723#discussion_r3309658601
########## 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. + */ +public final class HoodieVectorUtils { + + private HoodieVectorUtils() { + } + + /** + * Detects VECTOR columns in a HoodieSchema record and returns a map of field ordinal + * to the corresponding {@link HoodieSchema.Vector} schema. + * + * @param schema a HoodieSchema of type RECORD (or null) + * @return map from field index to Vector schema; empty map if schema is null or has no vectors + */ + public static Map<Integer, HoodieSchema.Vector> detectVectorColumns(HoodieSchema schema) { + Map<Integer, HoodieSchema.Vector> vectorColumnInfo = new LinkedHashMap<>(); + if (schema == null) { + return vectorColumnInfo; + } + List<HoodieSchemaField> fields = schema.getFields(); + for (int i = 0; i < fields.size(); i++) { + HoodieSchema fieldSchema = fields.get(i).schema().getNonNullType(); + if (fieldSchema.getType() == HoodieSchemaType.VECTOR) { + vectorColumnInfo.put(i, (HoodieSchema.Vector) fieldSchema); + } + } Review Comment: 🤖 nit: the `@return` here (and on the second `decodeVectorBytes` overload below) says "an ArrayData containing the decoded float[], double[], or byte[] array," but the method returns the raw primitive array (`Object` boxing a `float[]`/`double[]`/`byte[]`), not an `ArrayData`. Could you update the doc to match — e.g. "the decoded primitive array (`float[]`, `double[]`, or `byte[]`)"? <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> ########## hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/util/AvroToRowDataConverters.java: ########## @@ -78,16 +82,55 @@ public interface AvroToRowDataConverter extends Serializable { // ------------------------------------------------------------------------------------- // Runtime Converters // ------------------------------------------------------------------------------------- + + /** + * Creates a row converter from the Flink row type using UTC timezone conversion. + * + * <p>Note that this RowType-only path cannot recover Hoodie-specific logical type metadata + * that is not represented in Flink's {@link RowType}. + */ public static AvroToRowDataConverter createRowConverter(RowType rowType) { return createRowConverter(rowType, true); } + /** + * Creates a row converter from the Flink row type. + * + * <p>Note that this RowType-only path cannot recover Hoodie-specific logical type metadata + * that is not represented in Flink's {@link RowType}. + */ public static AvroToRowDataConverter createRowConverter(RowType rowType, boolean utcTimezone) { - final AvroToRowDataConverter[] fieldConverters = - rowType.getFields().stream() - .map(RowType.RowField::getType) - .map(type -> AvroToRowDataConverters.createNullableConverter(type, utcTimezone)) - .toArray(AvroToRowDataConverter[]::new); + return createRowConverter(HoodieSchemaConverter.convertToSchema(rowType), rowType, utcTimezone); + } + + /** + * Creates a row converter using only the Flink row type. Review Comment: 🤖 nit: this javadoc says "using only the Flink row type" but the method actually takes only a `HoodieSchema` (deriving the `RowType` from it) — could you flip the wording to something like "Creates a row converter using only the Hoodie schema"? The current text is the opposite of what the method does and is easy to misread. <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]
