voonhous commented on code in PR #19182:
URL: https://github.com/apache/hudi/pull/19182#discussion_r3543657197


##########
hudi-spark-datasource/hudi-spark/src/test/java-vortex/org/apache/hudi/io/storage/TestVortexReaderWriterRoundTrip.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.apache.hudi.HoodieSchemaConversionUtils;
+import org.apache.hudi.client.SparkTaskContextSupplier;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.unsafe.types.UTF8String;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * End-to-end round-trip test for the Vortex file writer and reader against 
the real vortex-jni
+ * API. Writes InternalRows through {@link HoodieSparkVortexWriter} and reads 
them back through
+ * {@link HoodieSparkVortexReader}, spanning multiple flushed batches.
+ */
+@DisabledIfSystemProperty(named = "vortex.skip.tests", matches = "true")
+public class TestVortexReaderWriterRoundTrip {
+
+  @TempDir
+  File tempDir;
+
+  @Test
+  public void testWriteReadRoundTrip() throws Exception {
+    HoodieStorage storage = 
HoodieTestUtils.getStorage(tempDir.getAbsolutePath());
+    SparkTaskContextSupplier taskContextSupplier = new 
SparkTaskContextSupplier();
+
+    StructType schema = new StructType()
+        .add("id", DataTypes.LongType, false)
+        .add("name", DataTypes.StringType, false)
+        .add("score", DataTypes.DoubleType, false);
+
+    StoragePath path = new StoragePath(tempDir.getAbsolutePath() + 
"/roundtrip.vortex");
+
+    int numRows = 2500; // > default batch size (1000) to force multiple 
flushed batches
+    try (HoodieSparkVortexWriter writer = HoodieSparkVortexWriter.builder()
+        .file(path)
+        .sparkSchema(schema)
+        .instantTime("20251201120000000")
+        .taskContextSupplier(taskContextSupplier)
+        .storage(storage)
+        .populateMetaFields(false)
+        .build()) {
+      for (int i = 0; i < numRows; i++) {
+        InternalRow row = new GenericInternalRow(new Object[] {
+            (long) (100 + i), UTF8String.fromString("name" + i), (double) i + 
0.5});
+        writer.writeRow(row);
+      }
+    }
+
+    assertTrue(storage.exists(path), "Vortex file should exist");
+
+    try (HoodieSparkVortexReader reader = new HoodieSparkVortexReader(path)) {
+      assertEquals(numRows, reader.getTotalRecords(), "row count");
+
+      HoodieSchema readSchema = reader.getSchema();
+      assertEquals(3, readSchema.getFields().size(), "schema field count");
+
+      int count = 0;
+      try (ClosableIterator<HoodieRecord<InternalRow>> it = 
reader.getRecordIterator(readSchema)) {
+        while (it.hasNext()) {
+          InternalRow row = it.next().getData();
+          assertEquals(100L + count, row.getLong(0), "id at row " + count);
+          assertEquals("name" + count, row.getUTF8String(1).toString(), "name 
at row " + count);
+          assertEquals((double) count + 0.5, row.getDouble(2), 1e-9, "score at 
row " + count);
+          count++;
+        }
+      }
+      assertEquals(numRows, count, "rows read back");
+    }
+
+    storage.close();
+  }
+
+  @Test
+  public void testProjectedRead() throws Exception {
+    HoodieStorage storage = 
HoodieTestUtils.getStorage(tempDir.getAbsolutePath());
+    SparkTaskContextSupplier taskContextSupplier = new 
SparkTaskContextSupplier();
+
+    StructType schema = new StructType()
+        .add("id", DataTypes.LongType, false)
+        .add("name", DataTypes.StringType, false);
+
+    StoragePath path = new StoragePath(tempDir.getAbsolutePath() + 
"/projected.vortex");
+    try (HoodieSparkVortexWriter writer = HoodieSparkVortexWriter.builder()
+        .file(path).sparkSchema(schema).instantTime("20251201120000000")
+        
.taskContextSupplier(taskContextSupplier).storage(storage).populateMetaFields(false).build())
 {
+      for (int i = 0; i < 3; i++) {
+        writer.writeRow(new GenericInternalRow(new Object[] {(long) i, 
UTF8String.fromString("n" + i)}));
+      }
+    }
+
+    // Project only the "id" column (a subset of the file's columns) via 
getRecordIterator.
+    HoodieSchema projected = 
HoodieSchemaConversionUtils.convertStructTypeToHoodieSchema(
+        new StructType().add("id", DataTypes.LongType, false), "record", "", 
false);

Review Comment:
   Nit: projecting `id` here does not actually pin the projection. `id` is 
column 0 in the file too, so `row.getLong(0)` on L133 passes whether the reader 
correctly narrows to `[id]` or wrongly returns the full `[id, name]` row -- the 
assertion cannot tell the two apart. Projecting a non-leading column (e.g. 
`name`, asserting `getUTF8String(0)`) would make this catch a projection 
regression.



##########
hudi-spark-datasource/hudi-spark/src/test/java-vortex/org/apache/hudi/io/storage/TestVortexReaderWriterRoundTrip.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+import org.apache.hudi.HoodieSchemaConversionUtils;
+import org.apache.hudi.client.SparkTaskContextSupplier;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.schema.HoodieSchema;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.common.util.collection.ClosableIterator;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.unsafe.types.UTF8String;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * End-to-end round-trip test for the Vortex file writer and reader against 
the real vortex-jni
+ * API. Writes InternalRows through {@link HoodieSparkVortexWriter} and reads 
them back through
+ * {@link HoodieSparkVortexReader}, spanning multiple flushed batches.
+ */
+@DisabledIfSystemProperty(named = "vortex.skip.tests", matches = "true")
+public class TestVortexReaderWriterRoundTrip {
+
+  @TempDir
+  File tempDir;
+
+  @Test
+  public void testWriteReadRoundTrip() throws Exception {
+    HoodieStorage storage = 
HoodieTestUtils.getStorage(tempDir.getAbsolutePath());
+    SparkTaskContextSupplier taskContextSupplier = new 
SparkTaskContextSupplier();
+
+    StructType schema = new StructType()
+        .add("id", DataTypes.LongType, false)
+        .add("name", DataTypes.StringType, false)
+        .add("score", DataTypes.DoubleType, false);
+
+    StoragePath path = new StoragePath(tempDir.getAbsolutePath() + 
"/roundtrip.vortex");
+
+    int numRows = 2500; // > default batch size (1000) to force multiple 
flushed batches
+    try (HoodieSparkVortexWriter writer = HoodieSparkVortexWriter.builder()
+        .file(path)
+        .sparkSchema(schema)
+        .instantTime("20251201120000000")
+        .taskContextSupplier(taskContextSupplier)
+        .storage(storage)
+        .populateMetaFields(false)
+        .build()) {
+      for (int i = 0; i < numRows; i++) {
+        InternalRow row = new GenericInternalRow(new Object[] {
+            (long) (100 + i), UTF8String.fromString("name" + i), (double) i + 
0.5});
+        writer.writeRow(row);
+      }
+    }
+
+    assertTrue(storage.exists(path), "Vortex file should exist");
+
+    try (HoodieSparkVortexReader reader = new HoodieSparkVortexReader(path)) {
+      assertEquals(numRows, reader.getTotalRecords(), "row count");
+
+      HoodieSchema readSchema = reader.getSchema();
+      assertEquals(3, readSchema.getFields().size(), "schema field count");
+
+      int count = 0;
+      try (ClosableIterator<HoodieRecord<InternalRow>> it = 
reader.getRecordIterator(readSchema)) {
+        while (it.hasNext()) {
+          InternalRow row = it.next().getData();
+          assertEquals(100L + count, row.getLong(0), "id at row " + count);
+          assertEquals("name" + count, row.getUTF8String(1).toString(), "name 
at row " + count);
+          assertEquals((double) count + 0.5, row.getDouble(2), 1e-9, "score at 
row " + count);
+          count++;
+        }
+      }
+      assertEquals(numRows, count, "rows read back");
+    }
+
+    storage.close();

Review Comment:
   Very minor: `storage.close()` runs only on the happy path -- if an assertion 
above throws it is skipped. Test-only so it barely matters, but moving it to a 
`finally` (or try-with-resources) would close it deterministically. Same in 
`testProjectedRead` (L138).



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