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


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/blob/TestBatchedBlobReader.scala:
##########
@@ -0,0 +1,420 @@
+/*
+ * 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.blob
+
+import org.apache.hudi.blob.BlobTestHelpers._
+import org.apache.hudi.common.schema.HoodieSchema
+import org.apache.hudi.testutils.HoodieClientTestBase
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.functions._
+import org.apache.spark.sql.hudi.blob.BatchedBlobReader
+import org.apache.spark.sql.types._
+import org.junit.jupiter.api.Assertions._
+import org.junit.jupiter.api.Test
+
+/**
+ * Tests for BatchedByteRangeReader.
+ *
+ * These tests verify the batching behavior and effectiveness of the
+ * BatchedByteRangeReader compared to non-batched approaches.
+ */
+class TestBatchedBlobReader extends HoodieClientTestBase {
+
+  @Test
+  def testBasicBatchedRead(): Unit = {
+    val filePath = createTestFile(tempDir, "basic.bin", 10000)
+
+    // Create input with struct column
+    val inputDF = sparkSession.createDataFrame(Seq(
+      (filePath, 0L, 100L),
+      (filePath, 100L, 100L),
+      (filePath, 200L, 100L)
+    )).toDF("external_path", "offset", "length")
+      .withColumn("data", blobStructCol("data", col("external_path"), 
col("offset"), col("length")))
+      .select("data")
+
+    // Read with batching
+    val resultDF = BatchedBlobReader.readBatched(inputDF, storageConf)
+
+    // Verify schema
+    assertTrue(resultDF.columns.contains("data"))
+    assertEquals(1, resultDF.columns.length) // data
+
+    // Verify results
+    val results = resultDF.collect()
+    assertEquals(3, results.length)
+
+    // Check data content
+    results.zipWithIndex.foreach { case (row, i) =>
+      val data = row.getAs[Array[Byte]]("data")
+      assertEquals(100, data.length)
+
+      // Verify content matches expected pattern
+      assertBytesContent(data, expectedOffset = i * 100)
+    }
+  }
+
+  @Test
+  def testNoBatchingDifferentFiles(): Unit = {
+    // Create different files
+    val file1 = createTestFile(tempDir, "file1.bin", 5000)
+    val file2 = createTestFile(tempDir, "file2.bin", 5000)
+    val file3 = createTestFile(tempDir, "file3.bin", 5000)
+
+    // Reads from different files (no batching possible)
+    val inputDF = sparkSession.createDataFrame(Seq(
+      (file1, 0L, 100L),
+      (file2, 0L, 100L),
+      (file3, 0L, 100L)
+    )).toDF("external_path", "offset", "length")
+      .withColumn("data", blobStructCol("data", col("external_path"), 
col("offset"), col("length")))
+      .select("data")
+
+    val resultDF = BatchedBlobReader.readBatched(inputDF, storageConf)
+
+    val results = resultDF.collect()
+    assertEquals(3, results.length)
+
+    // Verify all reads succeeded
+    results.foreach { row =>
+      val data = row.getAs[Array[Byte]]("data")
+      assertEquals(100, data.length)
+    }
+  }
+
+  @Test
+  def testGapThresholdSmallGaps(): Unit = {
+
+    val filePath = createTestFile(tempDir, "small-gaps.bin", 10000)
+
+    // Reads with small gaps (should batch with default threshold of 4KB)
+    val inputDF = sparkSession.createDataFrame(Seq(
+      (filePath, 0L, 100L),
+      (filePath, 120L, 100L),    // 20 byte gap
+      (filePath, 240L, 100L),    // 20 byte gap
+      (filePath, 360L, 100L)     // 20 byte gap
+    )).toDF("external_path", "offset", "length")
+      .withColumn("data", blobStructCol("data", col("external_path"), 
col("offset"), col("length")))
+      .select("data")
+
+    // Use default maxGapBytes=4096 which should batch these
+    val resultDF = BatchedBlobReader.readBatched(inputDF, storageConf, 
maxGapBytes = 4096)
+
+    val results = resultDF.collect()
+    assertEquals(4, results.length)
+
+    results.foreach { row =>
+      val data = row.getAs[Array[Byte]]("data")
+      assertEquals(100, data.length)
+    }
+  }
+
+  @Test

Review Comment:
   The overlapping ranges isn't a valid case. What do you want to test for with 
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