the-other-tim-brown commented on code in PR #17632:
URL: https://github.com/apache/hudi/pull/17632#discussion_r2646006325


##########
hudi-spark-datasource/hudi-spark/src/test/java/org/apache/hudi/io/storage/TestHoodieSparkLanceReader.java:
##########
@@ -0,0 +1,534 @@
+/*
+ * 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.HoodieKey;
+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.common.util.collection.Pair;
+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.DataType;
+import org.apache.spark.sql.types.DataTypes;
+import org.apache.spark.sql.types.StructType;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import static org.apache.hudi.io.storage.LanceTestUtils.createRow;
+import static 
org.apache.hudi.io.storage.LanceTestUtils.createRowWithMetaFields;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link HoodieSparkLanceReader}.
+ */
+public class TestHoodieSparkLanceReader {
+
+  @TempDir
+  File tempDir;
+
+  private HoodieStorage storage;
+  private SparkTaskContextSupplier taskContextSupplier;
+  private String instantTime;
+
+  @BeforeEach
+  public void setUp() throws IOException {
+    storage = HoodieTestUtils.getStorage(tempDir.getAbsolutePath());
+    taskContextSupplier = new SparkTaskContextSupplier();
+    instantTime = "20251201120000000";
+  }
+
+  @AfterEach
+  public void tearDown() throws Exception {
+    if (storage != null) {
+      storage.close();
+    }
+  }
+
+  @Test
+  public void testReadWithNulls() throws Exception {
+    StructType schema = new StructType()
+        .add("id", DataTypes.IntegerType, false)
+        .add("name", DataTypes.StringType, true)
+        .add("value", DataTypes.DoubleType, true);
+
+    List<InternalRow> expectedRows = new ArrayList<>();
+    expectedRows.add(createRow(1, "Alice", 100.0));
+    expectedRows.add(createRow(2, null, 200.0));  // null name
+    expectedRows.add(createRow(3, "Charlie", null));  // null value
+    expectedRows.add(createRow(4, null, null));  // multiple nulls
+
+    // Write and read back
+    StoragePath path = new StoragePath(tempDir.getAbsolutePath() + 
"/test_nulls.lance");
+    try (HoodieSparkLanceReader reader = writeAndCreateReader(path, schema, 
expectedRows)) {
+      List<InternalRow> actualRows = readAllRows(reader, schema);
+
+      assertEquals(expectedRows.size(), actualRows.size(), "Should read same 
number of records");
+
+      // Verify nulls are preserved
+      assertTrue(actualRows.get(1).isNullAt(1), "Second row name should be 
null");
+      assertFalse(actualRows.get(1).isNullAt(2), "Second row value should not 
be null");
+
+      assertFalse(actualRows.get(2).isNullAt(1), "Third row name should not be 
null");
+      assertTrue(actualRows.get(2).isNullAt(2), "Third row value should be 
null");
+
+      assertTrue(actualRows.get(3).isNullAt(1), "Fourth row name should be 
null");
+      assertTrue(actualRows.get(3).isNullAt(2), "Fourth row value should be 
null");
+    }
+  }
+
+  @Test
+  public void testReadAllSupportedTypes() throws Exception {
+    // Create schema with all supported primitive types
+    StructType schema = new StructType()
+        .add("int_field", DataTypes.IntegerType, false)
+        .add("long_field", DataTypes.LongType, false)
+        .add("float_field", DataTypes.FloatType, false)
+        .add("double_field", DataTypes.DoubleType, false)
+        .add("bool_field", DataTypes.BooleanType, false)
+        .add("string_field", DataTypes.StringType, false)
+        .add("binary_field", DataTypes.BinaryType, false);
+
+    // Create test data with 3 records
+    List<InternalRow> expectedRows = new ArrayList<>();
+    expectedRows.add(createRow(42, 123456789L, 3.14f, 2.71828, true, "Alice", 
new byte[]{1, 2, 3, 4}));
+    expectedRows.add(createRow(-100, 987654321L, 2.5f, 98.765, false, "Bob", 
new byte[]{10, 20, 30}));
+    expectedRows.add(createRow(0, 0L, 0.0f, 0.0, true, "Charlie", new 
byte[]{99}));
+
+    // Write and read back
+    StoragePath path = new StoragePath(tempDir.getAbsolutePath() + 
"/test_all_types.lance");
+    try (HoodieSparkLanceReader reader = writeAndCreateReader(path, schema, 
expectedRows)) {
+      assertEquals(expectedRows.size(), reader.getTotalRecords(), "Record 
count should match");
+      assertNotNull(reader.getSchema(), "Schema should not be null");
+
+      List<InternalRow> actualRows = readAllRows(reader, schema);
+      assertEquals(expectedRows.size(), actualRows.size(), "Should read same 
number of records");
+
+      // Verify each record
+      for (int i = 0; i < expectedRows.size(); i++) {
+        InternalRow expected = expectedRows.get(i);
+        InternalRow actual = actualRows.get(i);
+        assertEquals(expected, actual);
+      }

Review Comment:
   Can we assert the lists are equal to simplify this or is there some list 
implementation detail preventing this?



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