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


##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowDataLanceWriter.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.common.bloom.BloomFilter;
+import org.apache.hudi.common.engine.TaskContextSupplier;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.io.lance.HoodieBaseLanceWriter;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.pojo.Schema;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.io.IOException;
+
+/**
+ * Lance writer for Flink {@link RowData} append-only base files.
+ */
+public class HoodieRowDataLanceWriter extends HoodieBaseLanceWriter<RowData, 
String>
+    implements HoodieRowDataFileWriter {
+
+  private static final long MIN_RECORDS_FOR_SIZE_CHECK = 100L;
+  private static final long MAX_RECORDS_FOR_SIZE_CHECK = 10000L;
+
+  private final RowType rowType;
+  private final Schema arrowSchema;
+  private final long maxFileSize;
+  private long recordCountForNextSizeCheck = MIN_RECORDS_FOR_SIZE_CHECK;
+
+  public HoodieRowDataLanceWriter(
+      StoragePath file,
+      RowType rowType,
+      TaskContextSupplier taskContextSupplier,
+      Option<BloomFilter> bloomFilterOpt,
+      long maxFileSize,
+      long allocatorSize,
+      long flushByteWatermark) {
+    super(file, DEFAULT_BATCH_SIZE, allocatorSize, flushByteWatermark,
+        bloomFilterOpt.map(HoodieBloomFilterStringWriteSupport::new));
+    ValidationUtils.checkArgument(maxFileSize > 0, "maxFileSize must be a 
positive number");
+    ValidationUtils.checkArgument(allocatorSize > 0, "allocatorSize must be a 
positive number");
+    ValidationUtils.checkArgument(flushByteWatermark > 0, "flushByteWatermark 
must be a positive number");
+    ValidationUtils.checkArgument(flushByteWatermark < allocatorSize,
+        "flushByteWatermark (" + flushByteWatermark + ") must be less than 
allocatorSize ("
+            + allocatorSize + ")");
+    this.rowType = rowType;
+    this.arrowSchema = HoodieFlinkLanceArrowUtils.toArrowSchema(rowType);
+    this.maxFileSize = maxFileSize;
+  }
+
+  @Override
+  public boolean canWrite() {
+    long writtenCount = getWrittenRecordCount();
+    if (writtenCount >= recordCountForNextSizeCheck) {
+      long dataSize = getDataSize();
+      long avgRecordSize = Math.max(dataSize / writtenCount, 1);
+      if (dataSize > (maxFileSize - avgRecordSize * 2)) {
+        return false;
+      }
+      recordCountForNextSizeCheck = writtenCount + Math.min(
+          Math.max(MIN_RECORDS_FOR_SIZE_CHECK, (maxFileSize / avgRecordSize - 
writtenCount) / 2),
+          MAX_RECORDS_FOR_SIZE_CHECK);
+    }
+    return true;
+  }
+
+  @Override
+  public void writeRow(String key, RowData row) throws IOException {
+    bloomFilterWriteSupportOpt.ifPresent(bloomFilterWriteSupport -> 
bloomFilterWriteSupport.addKey(key));
+    super.write(row);
+  }
+
+  @Override
+  public void writeRowWithMetaData(HoodieKey key, RowData row) throws 
IOException {
+    writeRow(key.getRecordKey(), row);

Review Comment:
   **`writeRowWithMetaData` does not honor the writer contract.**
   
   `HoodieRowDataLanceWriter#writeRowWithMetaData` just delegates to 
`writeRow`, so `writeWithMetadata(...)` also writes the row as-is. This differs 
from `HoodieRowDataParquetWriter` and `HoodieSparkLanceWriter`, which populate 
`_hoodie_*` fields when metadata fields are enabled.



##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowDataLanceWriter.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.common.bloom.BloomFilter;
+import org.apache.hudi.common.engine.TaskContextSupplier;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.io.lance.HoodieBaseLanceWriter;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.pojo.Schema;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.logical.RowType;
+
+import java.io.IOException;
+
+/**
+ * Lance writer for Flink {@link RowData} append-only base files.
+ */
+public class HoodieRowDataLanceWriter extends HoodieBaseLanceWriter<RowData, 
String>
+    implements HoodieRowDataFileWriter {
+
+  private static final long MIN_RECORDS_FOR_SIZE_CHECK = 100L;
+  private static final long MAX_RECORDS_FOR_SIZE_CHECK = 10000L;
+
+  private final RowType rowType;
+  private final Schema arrowSchema;
+  private final long maxFileSize;
+  private long recordCountForNextSizeCheck = MIN_RECORDS_FOR_SIZE_CHECK;
+
+  public HoodieRowDataLanceWriter(
+      StoragePath file,
+      RowType rowType,
+      TaskContextSupplier taskContextSupplier,

Review Comment:
   `taskContextSupplier` is unused.



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/FlinkRowDataReaderContext.java:
##########
@@ -98,18 +99,27 @@ public ClosableIterator<RowData> getFileRecordIterator(
       HoodieSchema dataSchema,
       HoodieSchema requiredSchema,
       HoodieStorage storage) throws IOException {
-    if 
(filePath.toString().endsWith(HoodieFileFormat.LANCE.getFileExtension())) {
-      throw new 
UnsupportedOperationException(HoodieFileFormat.LANCE_SPARK_ONLY_ERROR_MSG);
-    }
     boolean isLogFile = FSUtils.isLogFile(filePath);
     // disable schema evolution in fileReader if it's log file, since schema 
evolution for log file is handled in `FileGroupRecordBuffer`
     InternalSchemaManager schemaManager = isLogFile ? 
InternalSchemaManager.DISABLED : internalSchemaManager.get();
 
+    if 
(filePath.getName().endsWith(HoodieFileFormat.LANCE.getFileExtension())) {

Review Comment:
   Seems we can create an issue to remove the format-specific branching from 
FlinkRowDataReaderContext#getFileRecordIterator, which should be delegated to a 
format-aware reader abstraction/factory instead.



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/HoodieTableFactory.java:
##########
@@ -220,12 +215,21 @@ private void checkIndexType(Configuration conf) {
   }
 
   /**
-   * Validate the base file format. Lance is only supported with the Spark 
engine.
+   * Validate the base file format. Flink Lance support is scoped to 
append-only COW tables.
    */
-  private void checkBaseFileFormat(Configuration conf) {
+  private void checkBaseFileFormat(Configuration conf, boolean write) {
     String baseFileFormat = 
conf.getString(HoodieTableConfig.BASE_FILE_FORMAT.key(), null);
     if (baseFileFormat != null && 
HoodieFileFormat.LANCE.name().equalsIgnoreCase(baseFileFormat)) {
-      throw new 
HoodieValidationException(HoodieFileFormat.LANCE_SPARK_ONLY_ERROR_MSG);
+      if (conf.containsKey(FlinkOptions.RECORD_KEY_FIELD.key())) {

Review Comment:
   +1



##########
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:
   Timestamp conversion ignores Flink `write.utc-timezone` semantics.
   
   `HoodieFlinkLanceArrowUtils.writeValue` always converts timestamps via 
`TimestampData#getMillisecond()`, equivalent to the UTC branch in the Parquet 
writer. The existing Flink Parquet path honors 
`HoodieStorageConfig.WRITE_UTC_TIMEZONE`.
   
   If users set `write.utc-timezone=false`, Lance can write different timestamp 
values from the existing Flink base-file path. 



##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/format/FlinkRowDataReaderContext.java:
##########
@@ -98,18 +99,27 @@ public ClosableIterator<RowData> getFileRecordIterator(
       HoodieSchema dataSchema,
       HoodieSchema requiredSchema,
       HoodieStorage storage) throws IOException {
-    if 
(filePath.toString().endsWith(HoodieFileFormat.LANCE.getFileExtension())) {
-      throw new 
UnsupportedOperationException(HoodieFileFormat.LANCE_SPARK_ONLY_ERROR_MSG);
-    }
     boolean isLogFile = FSUtils.isLogFile(filePath);
     // disable schema evolution in fileReader if it's log file, since schema 
evolution for log file is handled in `FileGroupRecordBuffer`
     InternalSchemaManager schemaManager = isLogFile ? 
InternalSchemaManager.DISABLED : internalSchemaManager.get();
 
+    if 
(filePath.getName().endsWith(HoodieFileFormat.LANCE.getFileExtension())) {
+      HoodieRowDataLanceReader rowDataLanceReader =
+          (HoodieRowDataLanceReader) HoodieIOFactory.getIOFactory(storage)
+              .getReaderFactory(HoodieRecord.HoodieRecordType.FLINK)
+              .getFileReader(tableConfig, filePath, HoodieFileFormat.LANCE, 
Option.empty());
+      try {
+        return 
rowDataLanceReader.getRowDataIterator(RowDataQueryContexts.fromSchema(requiredSchema).getRowType(),
 requiredSchema);

Review Comment:
   Schema evolution is not handled currently, can we explicitly reject/document 
schema evolution for Flink Lance and add a test.



##########
hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/HoodieBloomFilterStringWriteSupport.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.avro.HoodieBloomFilterWriteSupport;
+import org.apache.hudi.common.bloom.BloomFilter;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Bloom-filter footer support for Flink RowData Lance writers.
+ */
+class HoodieBloomFilterStringWriteSupport extends 
HoodieBloomFilterWriteSupport<String> {

Review Comment:
   There is already a `HoodieBloomFilterRowDataWriteSupport`, can we unify 
them? 
   
https://github.com/apache/hudi/blob/e299b84b10b5ccd4ee5c75e541f0109a85549d7a/hudi-client/hudi-flink-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowDataParquetWriteSupport.java#L65-L74



##########
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));
+        long micros = timestamp.getMillisecond() * 1000L + 
timestamp.getNanoOfMillisecond() / 1000L;
+        ((TimeStampMicroVector) vector).setSafe(rowId, micros);
+        return;
+      default:
+        throw unsupported(type);
+    }
+  }
+
+  private static Object readValue(LogicalType type, ValueVector vector, int 
rowId) {
+    switch (type.getTypeRoot()) {
+      case BOOLEAN:
+        return ((BitVector) vector).get(rowId) == 1;
+      case TINYINT:
+        return ((TinyIntVector) vector).get(rowId);
+      case SMALLINT:
+        return ((SmallIntVector) vector).get(rowId);
+      case INTEGER:
+        return ((IntVector) vector).get(rowId);
+      case DATE:
+        return ((DateDayVector) vector).get(rowId);
+      case TIME_WITHOUT_TIME_ZONE:
+        return ((TimeMilliVector) vector).get(rowId);
+      case BIGINT:
+        return ((BigIntVector) vector).get(rowId);
+      case FLOAT:
+        return ((Float4Vector) vector).get(rowId);
+      case DOUBLE:
+        return ((Float8Vector) vector).get(rowId);
+      case CHAR:
+      case VARCHAR:
+        return StringData.fromBytes(((VarCharVector) vector).get(rowId));
+      case BINARY:
+      case VARBINARY:
+        return ((VarBinaryVector) vector).get(rowId);
+      case DECIMAL:
+        DecimalType decimalType = (DecimalType) type;
+        BigDecimal decimal = ((DecimalVector) vector).getObject(rowId);
+        return DecimalData.fromBigDecimal(decimal, decimalType.getPrecision(), 
decimalType.getScale());
+      case TIMESTAMP_WITHOUT_TIME_ZONE:
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+        long micros = ((TimeStampMicroVector) vector).get(rowId);
+        return TimestampData.fromEpochMillis(micros / 1000L, (int) (micros % 
1000L) * 1000);
+      default:
+        throw unsupported(type);
+    }
+  }
+
+  private static Field toArrowField(String name, LogicalType type) {
+    return new Field(name, FieldType.nullable(toArrowType(type)), 
Collections.emptyList());
+  }
+
+  private static ArrowType toArrowType(LogicalType type) {
+    switch (type.getTypeRoot()) {
+      case BOOLEAN:
+        return ArrowType.Bool.INSTANCE;
+      case TINYINT:
+        return new ArrowType.Int(8, true);
+      case SMALLINT:
+        return new ArrowType.Int(16, true);
+      case INTEGER:
+        return new ArrowType.Int(32, true);
+      case BIGINT:
+        return new ArrowType.Int(64, true);
+      case FLOAT:
+        return new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE);
+      case DOUBLE:
+        return new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE);
+      case CHAR:
+      case VARCHAR:
+        return ArrowType.Utf8.INSTANCE;
+      case BINARY:
+      case VARBINARY:
+        return ArrowType.Binary.INSTANCE;
+      case DATE:
+        return new ArrowType.Date(DateUnit.DAY);
+      case TIME_WITHOUT_TIME_ZONE:
+        return new ArrowType.Time(TimeUnit.MILLISECOND, 32);
+      case DECIMAL:
+        DecimalType decimalType = (DecimalType) type;
+        return new ArrowType.Decimal(decimalType.getPrecision(), 
decimalType.getScale(), 128);
+      case TIMESTAMP_WITHOUT_TIME_ZONE:
+        return new ArrowType.Timestamp(TimeUnit.MICROSECOND, null);
+      case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
+        return new ArrowType.Timestamp(TimeUnit.MICROSECOND, "UTC");
+      default:
+        throw unsupported(type);
+    }
+  }
+
+  private static LogicalType toLogicalType(ArrowType arrowType) {

Review Comment:
   We can refer to `HoodieSchemaConverter#convertToDataType` to avoid creating 
logical type with fully Qualified Name.



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