924060929 commented on code in PR #70885:
URL: https://github.com/apache/doris/pull/70885#discussion_r4676470860


##########
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:
   Fixed in 1cd665c3834: `filterPartitionPathsByRequiredPartitions` now runs a 
two-pass match. Standard hive-style, positional, and percent-encoded paths 
match directly in Pass 1 with zero HMS RPCs; when 
`use_hive_sync_partition=true` on a latest (unpinned) read and any 
`requiredPartitions` remain unmatched (e.g. 
`SlashEncodedDayPartitionValueExtractor` mapping physical `2024/01/02` to HMS 
`dt=2024-01-02`), Pass 2 resolves only those unmatched names via 
`HmsClient.getExistingPartitionsWithStats` and intersects their relative 
storage locations against `candidatePaths`. Added unit coverage in 
`HudiPartitionPruningTest`.



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