github-actions[bot] commented on code in PR #70885:
URL: https://github.com/apache/doris/pull/70885#discussion_r4665048071


##########
fe/fe-connector/fe-connector-hudi/src/main/java/org/apache/doris/connector/hudi/HudiScanPlanProvider.java:
##########
@@ -851,29 +859,68 @@ private static List<String> 
partitionFieldNames(HoodieTableMetaClient metaClient
     }
 
     /**
-     * Resolve partition paths from handle or by listing all partitions.
+     * Resolve partition paths from handle or by listing all partitions, then 
intersect with Nereids'
+     * {@code requiredPartitions} so range / OR / NOT / expression partition 
pruning narrows Hudi splits too.
      */
     private List<String> resolvePartitions(
-            HudiTableHandle handle, HoodieTableMetaClient metaClient) {
-        // Check if partitions were pruned via applyFilter
-        List<String> prunedPaths = handle.getPrunedPartitionPaths();
-        if (prunedPaths != null) {
-            return prunedPaths;
-        }
-
-        // No pruning — list all partitions
+            ConnectorSession session, HudiTableHandle handle, 
HoodieTableMetaClient metaClient,
+            List<String> requiredPartitions, boolean urlEncoded) {
         List<String> partKeyNames = handle.getPartitionKeyNames();
-        if (partKeyNames == null || partKeyNames.isEmpty()) {
-            // Unpartitioned table
-            return Collections.singletonList("");
+        List<String> candidatePaths = handle.getPrunedPartitionPaths();
+        if (candidatePaths == null) {
+            if (partKeyNames == null || partKeyNames.isEmpty()) {
+                // Unpartitioned table
+                return Collections.singletonList("");
+            }
+            HudiConnectorMetadata.Listing listing = 
HudiStatementScope.sharedMetadataPartitions(
+                    session, handle, () -> {
+                        try {
+                            List<String> rawPaths = 
listAllPartitionPaths(metaClient);
+                            long lastModifiedMillis = instantToEpochMillis(
+                                    latestCompletedInstant(metaClient), 
timelineZone(metaClient));
+                            return HudiConnectorMetadata.unpinnedListing(
+                                    lastModifiedMillis, rawPaths, urlEncoded);
+                        } catch (Exception e) {
+                            throw new DorisConnectorException(
+                                    "Failed to list partitions for " + 
handle.getBasePath(), e);
+                        }
+                    });
+            candidatePaths = listing.rawPaths();
+            if (candidatePaths == null) {
+                candidatePaths = Collections.emptyList();
+            }
         }
+        return filterPartitionPathsByRequiredPartitions(
+                candidatePaths, partKeyNames, requiredPartitions, urlEncoded, 
handle.getTimestampPartitionKeys());
+    }
 
-        try {
-            return listAllPartitionPaths(metaClient);
-        } catch (Exception e) {
-            throw new DorisConnectorException(
-                    "Failed to list partitions for " + handle.getBasePath(), 
e);
+    /**
+     * Intersects relative Hudi partition paths (positional {@code "2024/01"} 
or hive-style
+     * {@code "year=2024/month=01"}) with Nereids' Hive-style {@code 
requiredPartitions} using the identical
+     * {@link #parsePartitionValues} + {@link #renderHiveStylePartitionName} 
canon that
+     * {@code HudiConnectorMetadata.buildPartitionInfos} produces. An empty 
{@code requiredPartitions} means
+     * "not pruned by Nereids — keep all {@code candidatePaths}".
+     */
+    static List<String> filterPartitionPathsByRequiredPartitions(
+            List<String> candidatePaths,
+            List<String> partKeyNames,
+            List<String> requiredPartitions,
+            boolean urlEncoded,
+            Set<String> timestampPartitionKeys) {
+        if (candidatePaths.isEmpty() || requiredPartitions == null || 
requiredPartitions.isEmpty()
+                || partKeyNames == null || partKeyNames.isEmpty()) {
+            return candidatePaths;
         }
+        Set<String> required = new HashSet<>(requiredPartitions);
+        List<String> matched = new ArrayList<>(Math.min(candidatePaths.size(), 
required.size()));
+        for (String path : candidatePaths) {
+            Map<String, String> values = parsePartitionValues(
+                    path, partKeyNames, urlEncoded, timestampPartitionKeys);
+            if (required.contains(renderHiveStylePartitionName(partKeyNames, 
values))) {

Review Comment:
   [P1] Resolve HMS selections to physical paths before intersecting
   
   With `use_hive_sync_partition=true`, Hudi's supported 
[SlashEncodedDayPartitionValueExtractor](https://github.com/apache/hudi/blob/release-1.0.2/hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/SlashEncodedDayPartitionValueExtractor.java)
 registers physical `2024/01/02` in HMS as `dt=2024-01-02`. `hmsPartitionPaths` 
leaves that percent-free name unchanged, so `Filter(dt IS NOT NULL) -> 
FileScan(t)` on a STRING partition column sends 
`requiredPartitions=["dt=2024-01-02"]`. `applyFilter` does not handle this 
predicate, and `resolvePartitions` enumerates physical `2024/01/02`; this loop 
renders it as `dt=2024%2F01%2F02` and rejects it. The query now gets zero 
splits instead of reading the matching rows. Resolve selected HMS names through 
their recorded storage locations, including names without percent escapes, 
before restricting the scan. Add a Hive-sync slash-date case: the new 
slash-path helper test supplies an already Hudi-rendered required name and 
misses this produce
 r/consumer mismatch.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to