You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "cshuo (via GitHub)" <gi...@apache.org> on 2026/06/16 01:38:36 UTC

[PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

cshuo opened a new pull request, #19013:
URL: https://github.com/apache/hudi/pull/19013

   ### Describe the issue this Pull Request addresses
   
   <!-- Either describe the issue inline here with motivation behind the changes 
        (or) link to an issue by including `Closes #<issue-number>` for context. 
        If this PR includes changes to the storage format, public APIs,
        or has breaking changes, use `!` (e.g., feat!: ...) -->
   
   ### Summary and Changelog
   
   <!-- Short, plain-English summary of what users gain or what changed in behavior.
        Followed by a detailed log of all the changes. Highlight if any code was copied. -->
   
   ### Impact
   
   <!-- Describe any public API or user-facing feature change or any performance impact. -->
   
   ### Risk Level
   
   <!-- Accepted values: none, low, medium or high. Other than `none`, explain the risk.
        If medium or high, explain what verification was done to mitigate the risks. -->
   
   ### Documentation Update
   
   <!-- Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".
   
   - The config description must be updated if new configs are added or the default value of the configs are changed.
   - Any new feature or user-facing change requires updating the Hudi website. Please follow the 
     [instruction](https://hudi.apache.org/contribute/developer-setup#website) to make changes to the website. -->
   
   ### Contributor's checklist
   
   - [ ] Read through [contributor's guide](https://hudi.apache.org/contribute/how-to-contribute)
   - [ ] Enough context is provided in the sections above
   - [ ] Adequate tests were added if applicable
   


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4730988336

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * ffa0f43d4ebd09c81dc3529d5a8ae188274c2475 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744) 
   * dd38da232b8099c22ad17e24a1850e0d4ac79573 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4969146421

   PR rebased. cc @voonhous @danny0405 


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3418463128


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.getPrunedStoragePaths
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.data.HoodieListData
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.{Option => HOption}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.{mutable, JavaConverters}
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code maxDataSkippingPartitions}
+ * (see [[DataSourceReadOptions.RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS]]) the record index filtering is skipped
+ * (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient,
+                                         maxDataSkippingPartitions: Int)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > maxDataSkippingPartitions) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $maxDataSkippingPartitions. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      val keys = HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava)
+      val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
+      for (partition <- partitions) {
+        val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(keys, HOption.of(partition))

Review Comment:
   need confirming.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4718118304

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * ffa0f43d4ebd09c81dc3529d5a8ae188274c2475 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "cshuo (via GitHub)" <gi...@apache.org>.
cshuo commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3418463128


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.getPrunedStoragePaths
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.data.HoodieListData
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.{Option => HOption}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.{mutable, JavaConverters}
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code maxDataSkippingPartitions}
+ * (see [[DataSourceReadOptions.RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS]]) the record index filtering is skipped
+ * (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient,
+                                         maxDataSkippingPartitions: Int)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > maxDataSkippingPartitions) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $maxDataSkippingPartitions. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      val keys = HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava)
+      val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
+      for (partition <- partitions) {
+        val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(keys, HOption.of(partition))

Review Comment:
   need confirming.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-agent (via GitHub)" <gi...@apache.org>.
hudi-agent commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3584039374


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DataSourceOptions.scala:
##########
@@ -190,6 +190,16 @@ object DataSourceReadOptions {
     .withDocumentation("Enables data-skipping allowing queries to leverage indexes to reduce the search space by " +
       "skipping over files")
 
+  val RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS: ConfigProperty[Integer] = ConfigProperty
+    .key("hoodie.datasource.read.record.index.max.partitions")
+    .defaultValue(Integer.valueOf(3))
+    .markAdvanced()
+    .sinceVersion("1.3.0")
+    .withDocumentation("The maximum number of candidate data table partitions that can be queried through the " +
+      "partitioned record level index for data skipping optimization. Each candidate partition requires a separate " +
+      "metadata table lookup. If the number of candidate partitions exceeds this value, the reader skips record " +

Review Comment:
   🤖 It's not per Spark task — it's the number of candidate (pruned) data-table partitions for a single query, evaluated on the driver at planning time. In `PartitionedRecordLevelIndexSupport.filterQueriesWithRecordKey`, `partitions` is derived from `prunedPartitionsAndFileSlices`, and if `partitions.size > MAX_PARTITIONS` the RLI lookup is skipped (returns None) and the reader falls back to other indexes. The threshold exists because each candidate partition needs a separate metadata-table lookup, so it bounds the number of MDT lookups per query resolution. Right now it's hard-coded to 10 in `RecordLevelIndexSupport` rather than being read from a config.



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.{getPrunedStoragePaths, MAX_PARTITIONS}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.ValidationUtils
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.core.read.BaseHoodieTableFileIndex
+import org.apache.hudi.index.PartitionedRecordIndexFileGroupLookupFunction
+import org.apache.hudi.metadata.{BucketizedMetadataTableFileGroupIndexParser, HoodieTableMetadataUtil, MetadataPartitionType}
+
+import org.apache.spark.Partitioner
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code MAX_PARTITIONS} the
+ * record index filtering is skipped (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > MAX_PARTITIONS) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $MAX_PARTITIONS. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      lookupRecordKeys(partitions, recordKeys) match {
+        case Some(fileIdToPartitionMap) =>
+          val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+          Option.apply(filterCandidateFiles(prunedStoragePaths, fileIdToPartitionMap))
+        case None =>
+          // None of the candidate partitions are indexed by the partitioned RLI (e.g. partitions
+          // not yet indexed), so we cannot determine the matching files. Fall back to other indexes
+          // rather than over-pruning to an empty candidate set.
+          Option.empty
+      }
+    }
+  }
+
+  private def lookupRecordKeys(partitions: Set[String],
+                               recordKeys: List[String]): Option[mutable.Map[String, String]] = {
+    val fileGroups = metadataTable.getBucketizedFileGroupsForPartitionedRLI(MetadataPartitionType.RECORD_INDEX)
+    val fileGroupCountPerDataPartition = fileGroups.asScala
+      .filter { case (partition, _) => partitions.contains(partition) }
+      .map { case (partition, slices) => partition -> Integer.valueOf(slices.size()) }
+      .toMap
+    if (fileGroupCountPerDataPartition.isEmpty) {
+      None
+    } else {
+      val numFileGroups = BucketizedMetadataTableFileGroupIndexParser.calculateNumberOfFileGroups(fileGroupCountPerDataPartition.asJava)
+      val partitionOffsetIndexes = BucketizedMetadataTableFileGroupIndexParser.generatePartitionToBaseIndexOffsets(fileGroupCountPerDataPartition.asJava).asScala
+      // Like SparkMetadataTableRecordLevelIndex#lookupRecords: build (partition, recordKey)
+      // pairs, key by the global partitioned-RLI shard id, and let each Spark partition look up
+      // one record-index shard through PartitionedRecordIndexFileGroupLookupFunction.
+      val partitionRecordKeys = fileGroupCountPerDataPartition.keys.toSeq.flatMap { partition =>
+        recordKeys.map { recordKey => Pair.of(partition, recordKey) }
+      }
+      val partitionedKeyRDD = spark.sparkContext.parallelize(partitionRecordKeys, numFileGroups)
+        .keyBy { partitionRecordKey =>
+          val partition = partitionRecordKey.getLeft
+          partitionOffsetIndexes(partition).intValue() +
+            HoodieTableMetadataUtil.mapRecordKeyToFileGroupIndex(partitionRecordKey.getRight, fileGroupCountPerDataPartition(partition).intValue())
+        }
+        .partitionBy(new PartitionIdPassthrough(numFileGroups))
+        .map(_._2)
+        .toJavaRDD()
+      ValidationUtils.checkState(partitionedKeyRDD.getNumPartitions <= numFileGroups)
+      val fileIdToPartitionMap = partitionedKeyRDD.mapPartitionsToPair(new PartitionedRecordIndexFileGroupLookupFunction(metadataTable))
+        .collect()
+        .asScala
+        .foldLeft(mutable.Map.empty[String, String]) { (acc, location) =>
+          acc.put(location._2.getFileId, location._2.getPartitionPath)

Review Comment:
   🤖 nit: the `foldLeft` with `acc.put(…); acc` is a bit Java-ish for Scala — `acc.put` returns `Option[V]` (the evicted value) which is silently discarded, and then `acc` must be manually returned. Have you considered `.map(loc => loc._2.getFileId -> loc._2.getPartitionPath).to(mutable.Map)` for a more idiomatic one-liner?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/RecordLevelIndexSupport.scala:
##########
@@ -56,48 +64,56 @@ class RecordLevelIndexSupport(spark: SparkSession,
                                          shouldPushDownFilesFilter: Boolean
                                         ): Option[Set[String]] = {
     lazy val (_, recordKeys) = filterQueriesWithRecordKey(queryFilters)
-    val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
     if (recordKeys.nonEmpty) {
-      Option.apply(getCandidateFilesForRecordKeys(prunedStoragePaths, recordKeys))
+      lookupCandidateFilesForRecordKeys(fileIndex, prunedPartitionsAndFileSlices, recordKeys)
     } else {
       Option.empty
     }
   }
 
+  /**
+   * Looks up the candidate files which may store the provided record keys from the record level index.
+   * Implemented differently for a global vs a partitioned RLI.
+   *
+   * @param fileIndex                     the file index of the query
+   * @param prunedPartitionsAndFileSlices already pruned partitions and file slices
+   * @param recordKeys                    the record key literals extracted from the query filters
+   * @return the set of candidate file names, or [[None]] if the index could not be used and pruning
+   *         should be skipped (falling back to other indexes).
+   */
+  protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                  prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                  recordKeys: List[String]): Option[Set[String]]
+
   override def invalidateCaches(): Unit = {
     // no caches for this index type, do nothing
   }
 
   /**
-   * Returns the list of candidate files which store the provided record keys based on Metadata Table Record Index.
-   *
-   * @param allFiles   - List of all files which needs to be considered for the query
-   * @param recordKeys - List of record keys.
-   * @return Sequence of file names which need to be queried
+   * Builds a map from fileId to data-table partition path from record index lookup results.
    */
-  private def getCandidateFilesForRecordKeys(allFiles: Seq[StoragePath], recordKeys: List[String]): Set[String] = {
-    val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(
-        HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava))
-    try {
-      val recordKeyLocationsList = HoodieDataUtils.dedupeAndCollectAsList(recordIndexData)
-      val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
-      val candidateFiles: mutable.Set[String] = mutable.Set.empty
-      for (recordKeyLocation <- recordKeyLocationsList.asScala) {
-        val location = recordKeyLocation.getValue
-        fileIdToPartitionMap.put(location.getFileId, location.getPartitionPath)
-      }
-      for (file <- allFiles) {
-        val fileId = FSUtils.getFileIdFromFilePath(file)
-        val partitionOpt = fileIdToPartitionMap.get(fileId)
-        if (partitionOpt.isDefined) {
-          candidateFiles += file.getName
-        }
+  protected def collectFileIdToPartitionMap(recordIndexData: HoodiePairData[String, HoodieRecordGlobalLocation]): mutable.Map[String, String] = {
+    val recordKeyLocationsList = HoodieDataUtils.dedupeAndCollectAsList(recordIndexData)
+    val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
+    for (recordKeyLocation <- recordKeyLocationsList.asScala) {
+      val location = recordKeyLocation.getValue
+      fileIdToPartitionMap.put(location.getFileId, location.getPartitionPath)
+    }
+    fileIdToPartitionMap
+  }
+
+  /**
+   * Filters the input files, keeping only those whose fileId is present in the record index lookup results.
+   */
+  protected def filterCandidateFiles(allFiles: Seq[StoragePath], fileIdToPartitionMap: mutable.Map[String, String]): Set[String] = {
+    val candidateFiles: mutable.Set[String] = mutable.Set.empty
+    for (file <- allFiles) {
+      val fileId = FSUtils.getFileIdFromFilePath(file)

Review Comment:
   🤖 nit: `fileIdToPartitionMap` is only read inside this method (`.contains`), so declaring the parameter as `mutable.Map` leaks an implementation detail and would prevent callers from passing an immutable `Map` in the future. Could you widen it to `Map[String, String]`?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/RecordLevelIndexSupport.scala:
##########
@@ -133,6 +149,34 @@ class RecordLevelIndexSupport(spark: SparkSession,
 object RecordLevelIndexSupport {
   val INDEX_NAME = "RECORD_LEVEL"
 
+  /**
+   * Upper bound on the number of candidate data-table partitions eligible for a partitioned RLI lookup.
+   *
+   * Unlike the global RLI (a single lookup over all keys), the partitioned variant performs one metadata-table read
+   * per candidate partition. When a query does not filter on the partition column the candidate set can span many
+   * partitions, and fanning out a lookup to each one can add latency that outweighs the skipping benefit. Once the
+   * candidate partition count exceeds this threshold, pruning is skipped.
+   */
+  private[hudi] val MAX_PARTITIONS = 10

Review Comment:
   🤖 nit: `MAX_PARTITIONS` is a bit generic when read in isolation — at the call site it appears as `RecordLevelIndexSupport.MAX_PARTITIONS`, which doesn't hint at what kind of partitions or why there's a max. Something like `MAX_CANDIDATE_PARTITIONS` (or `PARTITIONED_RLI_PARTITION_THRESHOLD`) would make it self-describing without needing to consult the Scaladoc.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4714387521

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bc06d84e8604d2917f9aa904bc827bf59d8e4b42 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722) 
   * 13100108bf512e523917f3a26c1b9f4c34eb29d3 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous closed pull request #19013: feat(spark): Support data skipping based on partitioned RLI
URL: https://github.com/apache/hudi/pull/19013


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4969186809

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823",
       "triggerID" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "triggerType" : "PUSH"
     }, {
       "hash" : "1b812f46f81981ea27cdd184f5d2747c65fe44ac",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "1b812f46f81981ea27cdd184f5d2747c65fe44ac",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c5efb1847172a07c4983fd50eff5e411d37b07bb Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823) 
   * 1b812f46f81981ea27cdd184f5d2747c65fe44ac UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4716655343

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 13100108bf512e523917f3a26c1b9f4c34eb29d3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724) 
   * ffa0f43d4ebd09c81dc3529d5a8ae188274c2475 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4714133814

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bc06d84e8604d2917f9aa904bc827bf59d8e4b42 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722) 
   * 13100108bf512e523917f3a26c1b9f4c34eb29d3 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4740173696

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823",
       "triggerID" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dd38da232b8099c22ad17e24a1850e0d4ac79573 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798) 
   * c5efb1847172a07c4983fd50eff5e411d37b07bb Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4732441579

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dd38da232b8099c22ad17e24a1850e0d4ac79573 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4967806841

   @cshuo Can you please help to rebase this branch? Thank you.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4714095079

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bc06d84e8604d2917f9aa904bc827bf59d8e4b42 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-agent (via GitHub)" <gi...@apache.org>.
hudi-agent commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3417963666


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.getPrunedStoragePaths
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.data.HoodieListData
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.{Option => HOption}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.{mutable, JavaConverters}
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code maxDataSkippingPartitions}
+ * (see [[DataSourceReadOptions.RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS]]) the record index filtering is skipped
+ * (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient,
+                                         maxDataSkippingPartitions: Int)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > maxDataSkippingPartitions) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $maxDataSkippingPartitions. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      val keys = HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava)
+      val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
+      for (partition <- partitions) {
+        val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(keys, HOption.of(partition))

Review Comment:
   🤖 I'd like to double-check correctness when a data partition has more than one file group in the partitioned RLI. Looking at `HoodieBackedTableMetadata.lookupIndexRecords` for the `dataTablePartition.isPresent()` branch, it computes a single `fileGroupIndex` from only the first key (`distinctSortedKeys.stream().findFirst().get()`) and reads from `fileSlicesForDataPartition.get(fileGroupIndex)` — i.e. only one shard. Its comment says "all keys will be from the same shard index", which is true for the write path (`SparkMetadataTableRecordLevelIndex.lookupRecords` pre-partitions by file-group index before calling), but here we forward all `recordKeys` to that API per partition. If an `IN (...)` query has multiple keys that hash to different file groups inside a partition (which can happen once `estimateFileGroupCount` allocates more than 1 file group for a partition, bounded by `record.level.index.max.filegroup.count` = 10 by default), the lookup would only see the first key's s
 hard, miss the others, and over-prune the candidate files → incorrect query results. The current tests use small data (≤5 records/partition) so each partition has just 1 file group and don't exercise this path. Could you confirm this, and either pre-bucket the keys by file group inside the loop (mirroring the write path) or add a test with `RECORD_LEVEL_INDEX_MIN_FILE_GROUP_COUNT_PROP = 2+` and a multi-key `IN` filter to verify? @nsivabalan @yihua would appreciate your eyes on the assumption in `lookupIndexRecords` too.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DataSourceOptions.scala:
##########
@@ -190,6 +190,16 @@ object DataSourceReadOptions {
     .withDocumentation("Enables data-skipping allowing queries to leverage indexes to reduce the search space by " +
       "skipping over files")
 
+  val RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS: ConfigProperty[Integer] = ConfigProperty
+    .key("hoodie.datasource.read.record.index.max.partitions")

Review Comment:
   🤖 nit: could you make the key name self-documenting by including the data-skipping context? `hoodie.datasource.read.record.index.max.partitions` reads like a property of the index itself (its max partition count) rather than a fallback threshold for data skipping. Something like `hoodie.datasource.read.record.index.data.skipping.max.partitions` would match the field name `RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS` and be unambiguous in a config file without the Javadoc nearby.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestGlobalRecordLevelIndexWithSQL.scala:
##########
@@ -46,6 +46,30 @@ import scala.util.Using
 class TestGlobalRecordLevelIndexWithSQL extends RecordLevelIndexTestBase {
   val sqlTempTable = "tbl"
 
+  /**
+   * Whether the record level index exercised by the tests is partitioned. Overridden by
+   * [[TestRecordLevelIndexWithSQL]] to run the same coverage against a partitioned RLI.
+   */
+  protected def isPartitionedRli: Boolean = false
+
+  /** Write options selecting a global vs partitioned record level index. */
+  protected def rliEnableOpts: Map[String, String] =
+    if (isPartitionedRli) {
+      Map(HoodieMetadataConfig.GLOBAL_RECORD_LEVEL_INDEX_ENABLE_PROP.key -> "false",
+        HoodieMetadataConfig.RECORD_LEVEL_INDEX_ENABLE_PROP.key -> "true")
+    } else {
+      Map(HoodieMetadataConfig.GLOBAL_RECORD_LEVEL_INDEX_ENABLE_PROP.key -> "true",
+        HoodieMetadataConfig.RECORD_LEVEL_INDEX_ENABLE_PROP.key -> "false")
+    }
+
+  /** The create-table DDL option that enables a global vs partitioned record level index. */
+  protected def rliEnableDDLOpts: String =
+    if (isPartitionedRli) {
+      s"${HoodieMetadataConfig.RECORD_LEVEL_INDEX_ENABLE_PROP.key} = 'true'"
+    } else {
+      "hoodie.metadata.record.index.enable = 'true'"

Review Comment:
   🤖 nit: this branch uses the legacy/alternative key `"hoodie.metadata.record.index.enable"` as a bare string literal, while the if-branch above uses `HoodieMetadataConfig.RECORD_LEVEL_INDEX_ENABLE_PROP.key`. It's worth at least a brief comment explaining that this is the backward-compatible alternative key for `GLOBAL_RECORD_LEVEL_INDEX_ENABLE_PROP` — otherwise it looks like an accidental inconsistency with the key used in `rliEnableOpts`.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "voonhous (via GitHub)" <gi...@apache.org>.
voonhous merged PR #19013:
URL: https://github.com/apache/hudi/pull/19013


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-agent (via GitHub)" <gi...@apache.org>.
hudi-agent commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3579562069


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.{getPrunedStoragePaths, MAX_PARTITIONS}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.ValidationUtils
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.core.read.BaseHoodieTableFileIndex
+import org.apache.hudi.index.PartitionedRecordIndexFileGroupLookupFunction
+import org.apache.hudi.metadata.{BucketizedMetadataTableFileGroupIndexParser, HoodieTableMetadataUtil, MetadataPartitionType}
+
+import org.apache.spark.Partitioner
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code MAX_PARTITIONS} the
+ * record index filtering is skipped (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > MAX_PARTITIONS) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $MAX_PARTITIONS. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      lookupRecordKeys(partitions, recordKeys) match {
+        case Some(fileIdToPartitionMap) =>
+          val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+          Option.apply(filterCandidateFiles(prunedStoragePaths, fileIdToPartitionMap))
+        case None =>
+          // None of the candidate partitions are indexed by the partitioned RLI (e.g. partitions
+          // not yet indexed), so we cannot determine the matching files. Fall back to other indexes
+          // rather than over-pruning to an empty candidate set.
+          Option.empty
+      }
+    }
+  }
+
+  private def lookupRecordKeys(partitions: Set[String],
+                               recordKeys: List[String]): Option[mutable.Map[String, String]] = {
+    val fileGroups = metadataTable.getBucketizedFileGroupsForPartitionedRLI(MetadataPartitionType.RECORD_INDEX)
+    val fileGroupCountPerDataPartition = fileGroups.asScala
+      .filter { case (partition, _) => partitions.contains(partition) }
+      .map { case (partition, slices) => partition -> Integer.valueOf(slices.size()) }
+      .toMap
+    if (fileGroupCountPerDataPartition.isEmpty) {
+      None
+    } else {
+      val numFileGroups = BucketizedMetadataTableFileGroupIndexParser.calculateNumberOfFileGroups(fileGroupCountPerDataPartition.asJava)
+      val partitionOffsetIndexes = BucketizedMetadataTableFileGroupIndexParser.generatePartitionToBaseIndexOffsets(fileGroupCountPerDataPartition.asJava).asScala
+      // Like SparkMetadataTableRecordLevelIndex#lookupRecords: build (partition, recordKey)
+      // pairs, key by the global partitioned-RLI shard id, and let each Spark partition look up
+      // one record-index shard through PartitionedRecordIndexFileGroupLookupFunction.
+      val partitionRecordKeys = fileGroupCountPerDataPartition.keys.toSeq.flatMap { partition =>
+        recordKeys.map { recordKey => Pair.of(partition, recordKey) }
+      }
+      val partitionedKeyRDD = spark.sparkContext.parallelize(partitionRecordKeys, numFileGroups)
+        .keyBy { partitionRecordKey =>
+          val partition = partitionRecordKey.getLeft
+          partitionOffsetIndexes(partition).intValue() +
+            HoodieTableMetadataUtil.mapRecordKeyToFileGroupIndex(partitionRecordKey.getRight, fileGroupCountPerDataPartition(partition).intValue())
+        }
+        .partitionBy(new PartitionIdPassthrough(numFileGroups))
+        .map(_._2)
+        .toJavaRDD()
+      ValidationUtils.checkState(partitionedKeyRDD.getNumPartitions <= numFileGroups)
+      val fileIdToPartitionMap = partitionedKeyRDD.mapPartitionsToPair(new PartitionedRecordIndexFileGroupLookupFunction(metadataTable))
+        .collect()
+        .asScala
+        .foldLeft(mutable.Map.empty[String, String]) { (fileIdToPartitionMap, location) =>

Review Comment:
   🤖 nit: the `foldLeft` accumulator parameter is also named `fileIdToPartitionMap`, the same as the `val` being assigned on line 106. Could you rename the accumulator to `acc` (or `map`) to make it obvious which `fileIdToPartitionMap.put(...)` on the next line refers to the accumulator and not the outer binding?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/GlobalRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,54 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.getPrunedStoragePaths
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.data.HoodieListData
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.core.read.BaseHoodieTableFileIndex
+
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters
+
+/**
+ * Data skipping based on a global Record Level Index (RLI), where a single set of file groups indexes
+ * the record keys across the whole table. All record keys are resolved with one metadata table lookup.
+ */
+class GlobalRecordLevelIndexSupport(spark: SparkSession,
+                                    metadataConfig: HoodieMetadataConfig,
+                                    metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+    val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(
+      HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava))

Review Comment:
   🤖 nit: `JavaConverters.seqAsJavaListConverter(recordKeys).asJava` is the verbose form — sibling files (`RecordLevelIndexSupport.scala`, `PartitionedRecordLevelIndexSupport.scala`) use `import scala.collection.JavaConverters._` and just write `recordKeys.asJava`. Could you align the import style here?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.getPrunedStoragePaths
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.data.HoodieListData
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.{Option => HOption}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.{mutable, JavaConverters}
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code maxDataSkippingPartitions}
+ * (see [[DataSourceReadOptions.RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS]]) the record index filtering is skipped
+ * (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient,
+                                         maxDataSkippingPartitions: Int)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > maxDataSkippingPartitions) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $maxDataSkippingPartitions. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      val keys = HoodieListData.eager(JavaConverters.seqAsJavaListConverter(recordKeys).asJava)
+      val fileIdToPartitionMap: mutable.Map[String, String] = mutable.Map.empty
+      for (partition <- partitions) {
+        val recordIndexData = metadataTable.readRecordIndexLocationsWithKeys(keys, HOption.of(partition))

Review Comment:
   🤖 I think the current `lookupRecordKeys` actually handles the multi-file-group case: it builds `(partition, recordKey)` pairs, keys them by the global shard id (`partitionOffsetIndexes(partition) + mapRecordKeyToFileGroupIndex(recordKey, fileGroupCount)`), `partitionBy`s on that, and each Spark partition then calls `PartitionedRecordIndexFileGroupLookupFunction` with a single partitionName. Since the offsets are disjoint per partition, every shard maps to exactly one `(partition, fileGroupIndex)`, so keys that hash to different file groups within a partition land in different lookups — the `findFirst` shard assumption in the MDT read holds. So this mirrors the write path rather than forwarding all keys to one shard. A test with `RECORD_LEVEL_INDEX_MIN_FILE_GROUP_COUNT_PROP = 2+` and a multi-key `IN` would still be valuable to lock the behavior in.



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DataSourceOptions.scala:
##########
@@ -190,6 +190,16 @@ object DataSourceReadOptions {
     .withDocumentation("Enables data-skipping allowing queries to leverage indexes to reduce the search space by " +
       "skipping over files")
 
+  val RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS: ConfigProperty[Integer] = ConfigProperty
+    .key("hoodie.datasource.read.record.index.max.partitions")
+    .defaultValue(Integer.valueOf(3))
+    .markAdvanced()
+    .sinceVersion("1.3.0")
+    .withDocumentation("The maximum number of candidate data table partitions that can be queried through the " +
+      "partitioned record level index for data skipping optimization. Each candidate partition requires a separate " +
+      "metadata table lookup. If the number of candidate partitions exceeds this value, the reader skips record " +

Review Comment:
   🤖 It's per-query rather than per-task — it caps the number of candidate data-table partitions for a single query (`partitions.size > MAX_PARTITIONS` in `PartitionedRecordLevelIndexSupport`), above which RLI pruning is skipped because each candidate partition needs its own metadata-table lookup. One thing worth noting: it's currently hard-coded to 10 in `RecordLevelIndexSupport.MAX_PARTITIONS` and not read from any config in the current revision, even though the PR description mentions a `hoodie.datasource.read.record.index.max.partitions` option.



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.{getPrunedStoragePaths, MAX_PARTITIONS}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.ValidationUtils
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.index.PartitionedRecordIndexFileGroupLookupFunction
+import org.apache.hudi.metadata.{BucketizedMetadataTableFileGroupIndexParser, HoodieTableMetadataUtil, MetadataPartitionType}
+
+import org.apache.spark.Partitioner
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code MAX_PARTITIONS} the
+ * record index filtering is skipped (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > MAX_PARTITIONS) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $MAX_PARTITIONS. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      lookupRecordKeys(partitions, recordKeys) match {
+        case Some(fileIdToPartitionMap) =>
+          val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+          Option.apply(filterCandidateFiles(prunedStoragePaths, fileIdToPartitionMap))
+        case None =>
+          // None of the candidate partitions are indexed by the partitioned RLI (e.g. partitions
+          // not yet indexed), so we cannot determine the matching files. Fall back to other indexes
+          // rather than over-pruning to an empty candidate set.
+          Option.empty
+      }
+    }
+  }
+
+  private def lookupRecordKeys(partitions: Set[String],
+                               recordKeys: List[String]): Option[mutable.Map[String, String]] = {
+    val fileGroups = metadataTable.getBucketizedFileGroupsForPartitionedRLI(MetadataPartitionType.RECORD_INDEX)
+    val fileGroupCountPerDataPartition = fileGroups.asScala
+      .filter { case (partition, _) => partitions.contains(partition) }

Review Comment:
   🤖 Agree this looks like real over-pruning risk, and one detail sharpens it: the `Option.empty` fallback only fires when `fileGroupCountPerDataPartition.isEmpty` — i.e. when *none* of the candidate partitions are indexed. In the mixed case (some partitions indexed, some not yet), line 82's filter silently drops the un-indexed ones, the lookup never queries them, and `filterCandidateFiles` then prunes all their files. Matching Flink's behavior — bailing to `Option.empty` if *any* candidate partition is absent from the bucketized map — would avoid dropping records during a backfill/skew window.



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/RecordLevelIndexSupport.scala:
##########
@@ -132,6 +148,34 @@ class RecordLevelIndexSupport(spark: SparkSession,
 object RecordLevelIndexSupport {
   val INDEX_NAME = "RECORD_LEVEL"
 
+  /**
+   * Upper bound on the number of candidate data-table partitions eligible for a partitioned RLI lookup.
+   *
+   * Unlike the global RLI (a single lookup over all keys), the partitioned variant performs one metadata-table read
+   * per candidate partition. When a query does not filter on the partition column the candidate set can span many
+   * partitions, and fanning out a lookup to each one can add latency that outweighs the skipping benefit. Once the
+   * candidate partition count exceeds this threshold, pruning is skipped.
+   */
+  private[hudi] val MAX_PARTITIONS = 10

Review Comment:
   🤖 Confirmed the wiring is missing in the current revision — `MAX_PARTITIONS` is hard-coded to 10 in `RecordLevelIndexSupport`, and a grep for `record.index.max.partitions` / `RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS` turns up no `ConfigProperty` definition in `DataSourceOptions` at all, so nothing reads it. Given Flink hard-codes its analogue to 3 and Spark to 10, exposing this as a tunable seems worthwhile for wide-partition tables.



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4741127491

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823",
       "triggerID" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c5efb1847172a07c4983fd50eff5e411d37b07bb Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14823) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "danny0405 (via GitHub)" <gi...@apache.org>.
danny0405 commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3418012478


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DataSourceOptions.scala:
##########
@@ -190,6 +190,16 @@ object DataSourceReadOptions {
     .withDocumentation("Enables data-skipping allowing queries to leverage indexes to reduce the search space by " +
       "skipping over files")
 
+  val RECORD_INDEX_MAX_DATA_SKIPPING_PARTITIONS: ConfigProperty[Integer] = ConfigProperty
+    .key("hoodie.datasource.read.record.index.max.partitions")
+    .defaultValue(Integer.valueOf(3))
+    .markAdvanced()
+    .sinceVersion("1.3.0")
+    .withDocumentation("The maximum number of candidate data table partitions that can be queried through the " +
+      "partitioned record level index for data skipping optimization. Each candidate partition requires a separate " +
+      "metadata table lookup. If the number of candidate partitions exceeds this value, the reader skips record " +

Review Comment:
   is this the num for per query task?



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4716695694

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 13100108bf512e523917f3a26c1b9f4c34eb29d3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724) 
   * ffa0f43d4ebd09c81dc3529d5a8ae188274c2475 Azure: [PENDING](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4714076392

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * bc06d84e8604d2917f9aa904bc827bf59d8e4b42 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4714899059

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 13100108bf512e523917f3a26c1b9f4c34eb29d3 Azure: [SUCCESS](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724) 
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4730912215

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * ffa0f43d4ebd09c81dc3529d5a8ae188274c2475 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744) 
   * dd38da232b8099c22ad17e24a1850e0d4ac79573 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-bot (via GitHub)" <gi...@apache.org>.
hudi-bot commented on PR #19013:
URL: https://github.com/apache/hudi/pull/19013#issuecomment-4740126976

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14722",
       "triggerID" : "bc06d84e8604d2917f9aa904bc827bf59d8e4b42",
       "triggerType" : "PUSH"
     }, {
       "hash" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14724",
       "triggerID" : "13100108bf512e523917f3a26c1b9f4c34eb29d3",
       "triggerType" : "PUSH"
     }, {
       "hash" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14744",
       "triggerID" : "ffa0f43d4ebd09c81dc3529d5a8ae188274c2475",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798",
       "triggerID" : "dd38da232b8099c22ad17e24a1850e0d4ac79573",
       "triggerType" : "PUSH"
     }, {
       "hash" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c5efb1847172a07c4983fd50eff5e411d37b07bb",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dd38da232b8099c22ad17e24a1850e0d4ac79573 Azure: [FAILURE](https://dev.azure.com/apachehudi/a1a51da7-8592-47d4-88dc-fd67bed336bb/_build/results?buildId=14798) 
   * c5efb1847172a07c4983fd50eff5e411d37b07bb UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     @hudi-bot supports the following commands:
   
    - `@hudi-bot run azure` re-run the last Azure build
   </details>


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(spark): Support data skipping based on partitioned RLI [hudi]

Posted by "hudi-agent (via GitHub)" <gi...@apache.org>.
hudi-agent commented on code in PR #19013:
URL: https://github.com/apache/hudi/pull/19013#discussion_r3434727238


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.{getPrunedStoragePaths, MAX_PARTITIONS}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.ValidationUtils
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.index.PartitionedRecordIndexFileGroupLookupFunction
+import org.apache.hudi.metadata.{BucketizedMetadataTableFileGroupIndexParser, HoodieTableMetadataUtil, MetadataPartitionType}
+
+import org.apache.spark.Partitioner
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code MAX_PARTITIONS} the
+ * record index filtering is skipped (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > MAX_PARTITIONS) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $MAX_PARTITIONS. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      lookupRecordKeys(partitions, recordKeys) match {
+        case Some(fileIdToPartitionMap) =>
+          val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+          Option.apply(filterCandidateFiles(prunedStoragePaths, fileIdToPartitionMap))
+        case None =>
+          // None of the candidate partitions are indexed by the partitioned RLI (e.g. partitions
+          // not yet indexed), so we cannot determine the matching files. Fall back to other indexes
+          // rather than over-pruning to an empty candidate set.
+          Option.empty
+      }
+    }
+  }
+
+  private def lookupRecordKeys(partitions: Set[String],
+                               recordKeys: List[String]): Option[mutable.Map[String, String]] = {
+    val fileGroups = metadataTable.getBucketizedFileGroupsForPartitionedRLI(MetadataPartitionType.RECORD_INDEX)
+    val fileGroupCountPerDataPartition = fileGroups.asScala
+      .filter { case (partition, _) => partitions.contains(partition) }

Review Comment:
   🤖 Could you double-check what happens if a candidate partition exists in the data table but isn't yet present in `getBucketizedFileGroupsForPartitionedRLI` (e.g. during an RLI backfill, or any transient skew)? The `.filter { partitions.contains(partition) }` silently drops such partitions; the lookup then never queries them, and `filterCandidateFiles` ends up filtering all their files out of the candidate set — so a matching record there would be skipped at read time. The Flink path (`hudi-flink/.../RecordLevelIndex.java#groupKeysByPartitionAndShard`) explicitly checks-state here and refuses to prune; should the Spark path behave the same (fall back to `Option.empty` if any candidate partition is missing from the indexed map) instead of silently over-pruning? @yihua
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/RecordLevelIndexSupport.scala:
##########
@@ -132,6 +148,34 @@ class RecordLevelIndexSupport(spark: SparkSession,
 object RecordLevelIndexSupport {
   val INDEX_NAME = "RECORD_LEVEL"
 
+  /**
+   * Upper bound on the number of candidate data-table partitions eligible for a partitioned RLI lookup.
+   *
+   * Unlike the global RLI (a single lookup over all keys), the partitioned variant performs one metadata-table read
+   * per candidate partition. When a query does not filter on the partition column the candidate set can span many
+   * partitions, and fanning out a lookup to each one can add latency that outweighs the skipping benefit. Once the
+   * candidate partition count exceeds this threshold, pruning is skipped.
+   */
+  private[hudi] val MAX_PARTITIONS = 10

Review Comment:
   🤖 The PR description says: 'Wire HoodieFileIndex to instantiate record-index support through the new factory and read the new `hoodie.datasource.read.record.index.max.partitions` threshold option.' — but in the current revision this is a hard-coded `private[hudi] val MAX_PARTITIONS = 10`, and I can't find any read of that option anywhere in the source tree. Was the config dropped intentionally, or did the wiring get lost in a rebase? With Flink's analogous threshold set to 3 and Spark to 10 hard-coded, making this user-tunable seems valuable for tables with many partitions that still want RLI pruning.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/PartitionedRecordIndexFileGroupLookupFunction.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.index;
+
+import org.apache.hudi.common.data.HoodieListData;
+import org.apache.hudi.common.data.HoodiePairData;
+import org.apache.hudi.common.model.HoodieRecordGlobalLocation;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.metadata.HoodieTableMetadata;
+
+import org.apache.spark.api.java.function.PairFlatMapFunction;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import scala.Tuple2;
+
+/**
+ * Looks up record-index keys that have already been grouped into one shard of a partitioned record index.
+ */
+public class PartitionedRecordIndexFileGroupLookupFunction
+    implements PairFlatMapFunction<Iterator<Pair<String, String>>, String, HoodieRecordGlobalLocation> {
+
+  private final HoodieTableMetadata metadataTable;
+
+  public PartitionedRecordIndexFileGroupLookupFunction(HoodieTableMetadata metadataTable) {
+    this.metadataTable = metadataTable;
+  }
+
+  @Override
+  public Iterator<Tuple2<String, HoodieRecordGlobalLocation>> call(Iterator<Pair<String, String>> partitionPathRecordKeyIterator) {
+    String partitionName = null;
+    List<String> keysToLookup = new ArrayList<>();
+    while (partitionPathRecordKeyIterator.hasNext()) {
+      Pair<String, String> partitionPathRecordKey = partitionPathRecordKeyIterator.next();
+      keysToLookup.add(partitionPathRecordKey.getRight());
+      if (partitionName == null) {
+        partitionName = partitionPathRecordKey.getLeft();
+      }
+    }
+
+    if (keysToLookup.isEmpty()) {
+      return Collections.emptyIterator();
+    }
+
+    HoodiePairData<String, HoodieRecordGlobalLocation> recordIndexData =
+        metadataTable.readRecordIndexLocationsWithKeys(HoodieListData.eager(keysToLookup), Option.of(partitionName));
+    try {
+      Map<String, HoodieRecordGlobalLocation> recordIndexInfo = recordIndexData.collectAsList().stream()
+          .collect(HashMap::new, (map, pair) -> map.put(pair.getKey(), pair.getValue()), HashMap::putAll);

Review Comment:
   🤖 nit: the three-arg `Stream.collect()` mutable-reduction form is a bit surprising here — could you use `collect(Collectors.toMap(Pair::getKey, Pair::getValue))` instead? It makes the intent immediately obvious.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/PartitionedRecordLevelIndexSupport.scala:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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
+
+import org.apache.hudi.RecordLevelIndexSupport.{getPrunedStoragePaths, MAX_PARTITIONS}
+import org.apache.hudi.common.config.HoodieMetadataConfig
+import org.apache.hudi.common.model.FileSlice
+import org.apache.hudi.common.table.HoodieTableMetaClient
+import org.apache.hudi.common.util.ValidationUtils
+import org.apache.hudi.common.util.collection.Pair
+import org.apache.hudi.index.PartitionedRecordIndexFileGroupLookupFunction
+import org.apache.hudi.metadata.{BucketizedMetadataTableFileGroupIndexParser, HoodieTableMetadataUtil, MetadataPartitionType}
+
+import org.apache.spark.Partitioner
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+/**
+ * Data skipping based on a partitioned Record Level Index (RLI), where the file groups indexing the
+ * record keys are sharded per data-table partition. The metadata lookup must therefore be scoped to each
+ * candidate partition.
+ *
+ * The candidate partitions are derived from the already pruned partitions. Because each partition requires a
+ * separate metadata table lookup, if the number of candidate partitions exceeds {@code MAX_PARTITIONS} the
+ * record index filtering is skipped (returns [[None]]) and the reader falls back to other indexes.
+ */
+class PartitionedRecordLevelIndexSupport(spark: SparkSession,
+                                         metadataConfig: HoodieMetadataConfig,
+                                         metaClient: HoodieTableMetaClient)
+  extends RecordLevelIndexSupport(spark, metadataConfig, metaClient) with Logging {
+
+  override protected def lookupCandidateFilesForRecordKeys(fileIndex: HoodieFileIndex,
+                                                           prunedPartitionsAndFileSlices: Seq[(Option[BaseHoodieTableFileIndex.PartitionPath], Seq[FileSlice])],
+                                                           recordKeys: List[String]): Option[Set[String]] = {
+    val partitions = prunedPartitionsAndFileSlices.flatMap { case (partitionPathOpt, _) =>
+      partitionPathOpt.map(_.getPath)
+    }.toSet
+    if (partitions.isEmpty) {
+      // Cannot resolve candidate partitions, fall back to other indexes rather than over-pruning
+      Option.empty
+    } else if (partitions.size > MAX_PARTITIONS) {
+      logInfo(s"The number of candidate partitions ${partitions.size} exceeds the partitioned record level index " +
+        s"lookup threshold $MAX_PARTITIONS. Skipping record level index pruning.")
+      Option.empty
+    } else {
+      lookupRecordKeys(partitions, recordKeys) match {
+        case Some(fileIdToPartitionMap) =>
+          val prunedStoragePaths = getPrunedStoragePaths(prunedPartitionsAndFileSlices, fileIndex)
+          Option.apply(filterCandidateFiles(prunedStoragePaths, fileIdToPartitionMap))
+        case None =>
+          // None of the candidate partitions are indexed by the partitioned RLI (e.g. partitions
+          // not yet indexed), so we cannot determine the matching files. Fall back to other indexes
+          // rather than over-pruning to an empty candidate set.
+          Option.empty
+      }
+    }
+  }
+
+  private def lookupRecordKeys(partitions: Set[String],
+                               recordKeys: List[String]): Option[mutable.Map[String, String]] = {
+    val fileGroups = metadataTable.getBucketizedFileGroupsForPartitionedRLI(MetadataPartitionType.RECORD_INDEX)
+    val fileGroupCountPerDataPartition = fileGroups.asScala
+      .filter { case (partition, _) => partitions.contains(partition) }
+      .map { case (partition, slices) => partition -> Integer.valueOf(slices.size()) }
+      .toMap
+    if (fileGroupCountPerDataPartition.isEmpty) {
+      None
+    } else {
+      val numFileGroups = BucketizedMetadataTableFileGroupIndexParser.calculateNumberOfFileGroups(fileGroupCountPerDataPartition.asJava)
+      val partitionOffsetIndexes = BucketizedMetadataTableFileGroupIndexParser.generatePartitionToBaseIndexOffsets(fileGroupCountPerDataPartition.asJava).asScala
+      // Like SparkMetadataTableRecordLevelIndex#lookupRecords: build (partition, recordKey)
+      // pairs, key by the global partitioned-RLI shard id, and let each Spark partition look up
+      // one record-index shard through PartitionedRecordIndexFileGroupLookupFunction.
+      val partitionRecordKeys = fileGroupCountPerDataPartition.keys.toSeq.flatMap { partition =>
+        recordKeys.map { recordKey => Pair.of(partition, recordKey) }
+      }
+      val partitionedKeyRDD = spark.sparkContext.parallelize(partitionRecordKeys, numFileGroups)
+        .keyBy { partitionRecordKey =>
+          val partition = partitionRecordKey.getLeft
+          partitionOffsetIndexes(partition).intValue() +
+            HoodieTableMetadataUtil.mapRecordKeyToFileGroupIndex(partitionRecordKey.getRight, fileGroupCountPerDataPartition(partition).intValue())
+        }
+        .partitionBy(new PartitionIdPassthrough(numFileGroups))
+        .map(_._2)
+        .toJavaRDD()
+      ValidationUtils.checkState(partitionedKeyRDD.getNumPartitions <= numFileGroups)
+      val fileIdToPartitionMap = partitionedKeyRDD.mapPartitionsToPair(new PartitionedRecordIndexFileGroupLookupFunction(metadataTable))
+        .collect()
+        .asScala
+        .foldLeft(mutable.Map.empty[String, String]) { (fileIdToPartitionMap, location) =>

Review Comment:
   🤖 nit: using `foldLeft` to build a mutable `Map` mixes functional and imperative styles in a way that can trip up readers — have you considered simplifying to `.map(t => t._2.getFileId -> t._2.getPartitionPath).toMap`? That also lets `lookupRecordKeys` return `Option[Map[String, String]]` (immutable) since the map is never mutated after construction.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub>



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org