kaori-seasons commented on code in PR #6768:
URL: https://github.com/apache/paimon/pull/6768#discussion_r2601300085


##########
paimon-arrow/src/test/java/org/apache/paimon/arrow/vector/ArrowFormatWriterTest.java:
##########
@@ -433,6 +438,55 @@ public void testWriteRowArrayTwice() {
         }
     }
 
+    @Test
+    public void testTimeFieldWriterWithOffset() {
+        RowType rowType =
+                new RowType(
+                        Collections.singletonList(
+                                new DataField(0, "time_field", 
DataTypes.TIME())));
+        try (RootAllocator allocator = new RootAllocator();
+                VectorSchemaRoot vsr = 
ArrowUtils.createVectorSchemaRoot(rowType, allocator)) {
+            ArrowFieldWriter[] fieldWriters = 
ArrowUtils.createArrowFieldWriters(vsr, rowType);
+
+            IntColumnVector timeVec =
+                    new IntColumnVector() {
+                        final int[] values = new int[] {0, 1000, 2000, 3000, 
4000};

Review Comment:
   Current situation: Similar index mixing (using `i` to read source data, or 
using `row` to check the Arrow vector) can easily occur repeatedly in multiple 
field writers, leading to hidden bugs.
   
   Recommendation:
   
   Recommendation: Define and strictly distinguish between `sourceIndex` (e.g., 
`rowIndex = startIndex + i`) and `targetIndex(i)` in the implementation.
   
   Within the loop body of each writer, use `sourceIndex` to read data from the 
`ColumnVector`, and use `targetIndex` to write data to the `ArrowVector`; use 
`sourceIndex` to check for null values.
   
   Example:
   ```
   // Assume startIndex, batchRows, columnVector, and timeMilliVector are known.
   for (int i = 0; i < batchRows; i++) {
       int sourceIndex = startIndex + i; // 从 columnVector 读取的索引
       int targetIndex = i;              // 写到 Arrow 向量的位置
       if (columnVector.isNullAt(sourceIndex)) {
           timeMilliVector.setNull(targetIndex);
       } else {
           int value = ((IntColumnVector) columnVector).getInt(sourceIndex);
           timeMilliVector.setSafe(targetIndex, value);
       }
   }
   ```



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