924060929 opened a new pull request, #70885:
URL: https://github.com/apache/doris/pull/70885

   ### Background
   
   For partitioned Hudi tables in HMS catalogs, Nereids enumerates partitions 
through `HudiConnectorMetadata.listPartitions`, evaluates partition predicates 
in `PruneFileScanPartition`, and passes the surviving Hive-style partition 
names to `HudiScanPlanProvider.planScan` via 
`ConnectorScanRequest.getRequiredPartitions()`. Separately, 
`HudiConnectorMetadata.applyFilter` extracts simple `=` / `IN` conjuncts on 
partition columns (which also covers `FOR TIME AS OF` reads on 
`use_hive_sync_partition=true` tables where `listsPartitionsAtSnapshot` is 
`false`) and stamps matched relative storage paths onto 
`HudiTableHandle.prunedPartitionPaths`.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #67725 (connector partition pruning discussion)
   PR Type: Bugfix
   
   Problem Summary: `HudiScanPlanProvider.resolvePartitions` only checked 
`handle.getPrunedPartitionPaths()` and ignored 
`ConnectorScanRequest.getRequiredPartitions()` (and 
`isPartitionsPrunedToEmpty()`), so any partition predicate outside simple `=` / 
`IN` (such as `<`, `<=`, `>`, `>=`, `OR`, `NOT`, `IS NULL`, or functions on 
partition keys) scanned every partition in `HoodieTableFileSystemView` even 
when `EXPLAIN` reported `partition=N/M`; in addition, `HudiScanReuseKey` 
omitted `requiredPartitions` and `partitionsPrunedToEmpty`, and a single query 
listed HMS / Hudi Metadata Table partitions twice across `listPartitions`, 
`applyFilter`, and `resolvePartitions`. Intersect candidate partition paths 
with `request.getRequiredPartitions()` in `HudiScanPlanProvider`, include 
request-level partition selection in `HudiScanReuseKey`, and share 
per-statement partition listings via `HudiStatementScope`.
   
   ### Details
   
   - **Change map:** 201 lines of production code across 3 files in 
`fe-connector-hudi`, and 235 lines of unit tests across 3 test files.
     - `HudiScanPlanProvider.java` (+95/-24): short-circuits `doPlanScan` when 
`request.isPartitionsPrunedToEmpty()`, intersects candidate relative paths with 
`request.getRequiredPartitions()` in `resolvePartitions` via 
`filterPartitionPathsByRequiredPartitions`, reuses statement-scoped metadata 
partition listings, and adds `requiredPartitions` + `partitionsPrunedToEmpty` 
to `HudiScanReuseKey`.
     - `HudiConnectorMetadata.java` & `HudiStatementScope.java` (+106/-63): 
memoizes unpinned Hudi metadata partition listings (`hudi.metadata_partitions`) 
and HMS partition path listings (`hudi.hms_partitions`) per physical table 
within a statement while keeping `SHOW PARTITIONS` (`bypassCache=true`) fresh 
and keeping distinct `FOR TIME AS OF` instants isolated.
     - `HudiPartitionPruningTest.java`, `HudiScanReuseKeyTest.java`, & 
`HudiStatementMemoTest.java` (+231/-4): offline unit tests covering 
positional/hive-style/slash/timestamp/percent-encoded/SQL-NULL 
`requiredPartitions` filtering, `partitionsPrunedToEmpty` short-circuiting, 
`HudiScanReuseKey` separation across scan aliases, and statement-scope 
partition listing deduplication.
   - **Frequency:** Every partitioned Hudi query using range (`>`, `>=`, `<`, 
`<=`), `OR`, `NOT`, `IS NULL`, or function predicates on partition columns (or 
mixed `=` + range predicates across multiple partition columns), and any 
multi-alias Hudi query with distinct Nereids-pruned partition sets when 
`enable_external_scan_task_reuse=true`.
   - **Root cause:** `HudiConnectorMetadata.applyFilter` only extracts `=` and 
non-negated literal `IN` conjuncts; `HudiScanPlanProvider.resolvePartitions` 
never read `ConnectorScanRequest.getRequiredPartitions()`, and 
`HudiScanReuseKey` keyed only on `HudiTableHandle` + generation without 
`request.getRequiredPartitions()` or `request.isPartitionsPrunedToEmpty()`.
   - **Why existing tests missed it:** Existing offline tests 
(`HudiPartitionPruningTest`) tested `applyFilter` in isolation (`=` / `IN`), 
and regression cases in `test_hudi_partition_prune.groovy` asserted `EXPLAIN` 
`partition=N/M` (computed by `PluginDrivenScanNode` from Nereids' 
`SelectedPartitions`) and final query rows (filtered again by BE), masking the 
unpruned file splits in `HudiScanPlanProvider`.
   - **Fix:** Render each candidate relative path 
(`handle.getPrunedPartitionPaths()` or metadata partition paths) through the 
same `parsePartitionValues` + `renderHiveStylePartitionName` canon used by 
`HudiConnectorMetadata.buildPartitionInfos` and intersect with 
`request.getRequiredPartitions()`; short-circuit 
`request.isPartitionsPrunedToEmpty()`; add both fields to `HudiScanReuseKey`; 
and deduplicate per-statement HMS and Hudi metadata partition listings through 
`HudiStatementScope`.
   - **Other paths and branches:** Preserves 
`HudiConnectorMetadata.applyFilter` because `FOR TIME AS OF` on 
`use_hive_sync_partition=true` tables sets `listsPartitionsAtSnapshot=false` 
(`requiredPartitions` is empty) and relies on `applyFilter` to prune `=` / `IN` 
against the Hudi Metadata Table; `@incr` incremental file selection via 
`IncrementalRelation` is unchanged unless it degrades to 
`fallbackFullTableScan()`.
   
   ### Testing
   
   - Ran `./run-fe-ut.sh --run "org.apache.doris.connector.hudi.*Test"` locally 
(all 278 test cases across `fe-connector-hudi` passed).
   - Ran Checkstyle (`mvn validate -pl fe-connector/fe-connector-hudi -am`) and 
FE connector architecture gates 
(`./build-support/check-fe-connector-imports.sh` and 
`./build-support/check-fe-core-metadata-funnel.sh`) locally (0 violations).
   
   ### Release note
   
   Fixed Hudi scan planning to honor Nereids partition pruning 
(`requiredPartitions`) for range, `OR`, `NOT`, `IS NULL`, and expression 
predicates on partition columns, isolated statement-scoped scan split reuse 
across distinct pruned partition sets, and deduplicated per-statement Hudi 
partition listings.
   
   ### Check List (For Author)
   
   - Test: Unit Test (`run-fe-ut.sh`, Checkstyle, and FE connector architecture 
gates)
   - Behavior changed: No (fixes unpruned split planning and scan-reuse key 
collision so scanned partitions match Nereids partition pruning)
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Antigravity
   - Generated: Code, unit tests, and PR description
   - Human review: Design, connector invariants, and test coverage reviewed 
with the author


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