hudi-agent commented on code in PR #19242:
URL: https://github.com/apache/hudi/pull/19242#discussion_r3572805230


##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/lance/LanceRowDataWriter.java:
##########
@@ -0,0 +1,482 @@
+/*
+ * 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.io.storage.row.lance;
+
+import org.apache.hudi.exception.HoodieNotSupportedException;
+
+import org.apache.arrow.vector.BigIntVector;
+import org.apache.arrow.vector.BitVector;
+import org.apache.arrow.vector.DateDayVector;
+import org.apache.arrow.vector.DecimalVector;
+import org.apache.arrow.vector.FieldVector;
+import org.apache.arrow.vector.Float4Vector;
+import org.apache.arrow.vector.Float8Vector;
+import org.apache.arrow.vector.IntVector;
+import org.apache.arrow.vector.SmallIntVector;
+import org.apache.arrow.vector.TimeMilliVector;
+import org.apache.arrow.vector.TimeStampVector;
+import org.apache.arrow.vector.TinyIntVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.complex.ListVector;
+import org.apache.arrow.vector.complex.StructVector;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.util.List;
+
+import static 
org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getPrecision;
+
+/**
+ * Writes Flink {@link RowData} values into Arrow vectors used by Lance base 
files.
+ *
+ * <p>The type-specific writer tree is created once for the supplied Arrow 
vectors. Record writes
+ * then use direct {@link RowData} and {@link ArrayData} accessors without 
creating field or element
+ * getters on the record-level path.
+ *
+ * <p>Supports primitive types, {@code ROW}, and {@code ARRAY}. {@code MAP} is 
not supported by the
+ * current Lance Java writer. Enable it once Lance adds Java writer support 
for {@code MAP}.
+ *
+ * @see <a href="https://github.com/lance-format/lance/issues/3620";>Lance 
issue #3620</a>
+ */
+public class LanceRowDataWriter {
+
+  private final FieldWriter[] fieldWriters;
+
+  public LanceRowDataWriter(RowType rowType, List<FieldVector> vectors, 
boolean utcTimestamp) {
+    this.fieldWriters = new FieldWriter[rowType.getFieldCount()];
+    for (int i = 0; i < fieldWriters.length; i++) {
+      fieldWriters[i] = createWriter(rowType.getTypeAt(i), vectors.get(i), 
utcTimestamp);
+    }
+  }
+
+  public void write(RowData row, int rowId) {
+    for (int i = 0; i < fieldWriters.length; i++) {
+      fieldWriters[i].write(row, i, rowId);
+    }
+  }
+
+  private static FieldWriter createWriter(LogicalType type, FieldVector 
vector, boolean utcTimestamp) {
+    switch (type.getTypeRoot()) {
+      case BOOLEAN:
+        return new BooleanWriter((BitVector) vector);
+      case TINYINT:
+        return new TinyIntWriter((TinyIntVector) vector);
+      case SMALLINT:
+        return new SmallIntWriter((SmallIntVector) vector);
+      case INTEGER:
+        return new IntWriter((IntVector) vector);
+      case DATE:
+        return new DateWriter((DateDayVector) vector);
+      case TIME_WITHOUT_TIME_ZONE:
+        return new TimeWriter((TimeMilliVector) vector);
+      case BIGINT:
+        return new BigIntWriter((BigIntVector) vector);
+      case FLOAT:
+        return new FloatWriter((Float4Vector) vector);
+      case DOUBLE:
+        return new DoubleWriter((Float8Vector) vector);
+      case CHAR:
+      case VARCHAR:
+        return new StringWriter((VarCharVector) vector);
+      case BINARY:
+      case VARBINARY:
+        return new BinaryWriter((VarBinaryVector) vector);
+      case DECIMAL:
+        return new DecimalWriter((DecimalVector) vector, (DecimalType) type);
+      case TIMESTAMP_WITHOUT_TIME_ZONE:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+        return new TimestampWriter((TimeStampVector) vector, 
getPrecision(type), utcTimestamp);
+      case ROW:
+        RowType rowType = (RowType) type;
+        StructVector structVector = (StructVector) vector;
+        FieldWriter[] fieldWriters = new FieldWriter[rowType.getFieldCount()];
+        for (int i = 0; i < fieldWriters.length; i++) {

Review Comment:
   🤖 nit: could you rename this local variable to `childWriters` (or 
`nestedWriters`)? It shares the exact name of the outer instance field 
`fieldWriters`, and even though `createWriter` is static, a reader scanning the 
method will do a double-take to confirm these are unrelated.
   
   <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]

Reply via email to