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


##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/HoodieFlinkLanceArrowUtils.java:
##########
@@ -0,0 +1,283 @@
+/*
+ * 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;
+
+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.TimeStampMicroVector;
+import org.apache.arrow.vector.TinyIntVector;
+import org.apache.arrow.vector.ValueVector;
+import org.apache.arrow.vector.VarBinaryVector;
+import org.apache.arrow.vector.VarCharVector;
+import org.apache.arrow.vector.types.DateUnit;
+import org.apache.arrow.vector.types.FloatingPointPrecision;
+import org.apache.arrow.vector.types.TimeUnit;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
+import org.apache.arrow.vector.types.pojo.FieldType;
+import org.apache.arrow.vector.types.pojo.Schema;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.data.TimestampData;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LocalZonedTimestampType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.TimestampType;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static 
org.apache.flink.table.types.logical.utils.LogicalTypeChecks.getPrecision;
+
+/**
+ * Primitive RowData/Arrow conversion helpers for Flink Lance base files.
+ */
+public final class HoodieFlinkLanceArrowUtils {
+
+  private HoodieFlinkLanceArrowUtils() {
+  }
+
+  public static Schema toArrowSchema(RowType rowType) {
+    List<Field> fields = new ArrayList<>(rowType.getFieldCount());
+    for (RowType.RowField field : rowType.getFields()) {
+      fields.add(toArrowField(field.getName(), field.getType()));
+    }
+    return new Schema(fields);
+  }
+
+  public static RowType toRowType(Schema schema) {
+    List<RowType.RowField> fields = new ArrayList<>(schema.getFields().size());
+    for (Field field : schema.getFields()) {
+      fields.add(new RowType.RowField(field.getName(), 
toLogicalType(field.getType())));
+    }
+    return new RowType(fields);
+  }
+
+  public static RowData toRowData(RowType rowType, List<FieldVector> vectors, 
int rowId) {
+    GenericRowData rowData = new GenericRowData(vectors.size());
+    for (int i = 0; i < vectors.size(); i++) {
+      FieldVector vector = vectors.get(i);
+      if (vector.isNull(rowId)) {
+        rowData.setField(i, null);
+      } else {
+        rowData.setField(i, readValue(rowType.getTypeAt(i), vector, rowId));
+      }
+    }
+    return rowData;
+  }
+
+  public static void writeValue(LogicalType type, FieldVector vector, int 
rowId, RowData rowData, int ordinal) {
+    if (rowData.isNullAt(ordinal)) {
+      vector.setNull(rowId);
+      return;
+    }
+    switch (type.getTypeRoot()) {
+      case BOOLEAN:
+        ((BitVector) vector).setSafe(rowId, rowData.getBoolean(ordinal) ? 1 : 
0);
+        return;
+      case TINYINT:
+        ((TinyIntVector) vector).setSafe(rowId, rowData.getByte(ordinal));
+        return;
+      case SMALLINT:
+        ((SmallIntVector) vector).setSafe(rowId, rowData.getShort(ordinal));
+        return;
+      case INTEGER:
+        ((IntVector) vector).setSafe(rowId, rowData.getInt(ordinal));
+        return;
+      case DATE:
+        ((DateDayVector) vector).setSafe(rowId, rowData.getInt(ordinal));
+        return;
+      case TIME_WITHOUT_TIME_ZONE:
+        ((TimeMilliVector) vector).setSafe(rowId, rowData.getInt(ordinal));
+        return;
+      case BIGINT:
+        ((BigIntVector) vector).setSafe(rowId, rowData.getLong(ordinal));
+        return;
+      case FLOAT:
+        ((Float4Vector) vector).setSafe(rowId, rowData.getFloat(ordinal));
+        return;
+      case DOUBLE:
+        ((Float8Vector) vector).setSafe(rowId, rowData.getDouble(ordinal));
+        return;
+      case CHAR:
+      case VARCHAR:
+        ((VarCharVector) vector).setSafe(rowId, 
rowData.getString(ordinal).toBytes());
+        return;
+      case BINARY:
+      case VARBINARY:
+        ((VarBinaryVector) vector).setSafe(rowId, rowData.getBinary(ordinal));
+        return;
+      case DECIMAL:
+        DecimalType decimalType = (DecimalType) type;
+        DecimalData decimal = rowData.getDecimal(ordinal, 
decimalType.getPrecision(), decimalType.getScale());
+        ((DecimalVector) vector).setSafe(rowId, decimal.toBigDecimal());
+        return;
+      case TIMESTAMP_WITHOUT_TIME_ZONE:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+        TimestampData timestamp = rowData.getTimestamp(ordinal, 
getPrecision(type));

Review Comment:
   Addressed. The Lance writer now passes 
`HoodieStorageConfig.WRITE_UTC_TIMEZONE` into 
`HoodieFlinkLanceArrowUtils.writeValue`, and timestamp conversion follows the 
UTC/non-UTC branch. I also added test coverage in 
`TestHoodieFlinkLanceArrowUtils`.



-- 
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