Skip to content

[BugFix] Fix Delta Lake and Kudu un-partitioned materialized view query rewrite#76359

Merged
stephen-shelby merged 1 commit into
StarRocks:mainfrom
GavinMar:fix_mv_rewrite_failed
Jul 15, 2026
Merged

[BugFix] Fix Delta Lake and Kudu un-partitioned materialized view query rewrite#76359
stephen-shelby merged 1 commit into
StarRocks:mainfrom
GavinMar:fix_mv_rewrite_failed

Conversation

@GavinMar

@GavinMar GavinMar commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Why I'm doing:

Materialized views defined on a Delta Lake or Kudu external table fail query rewrite. After the MV is refreshed successfully and is active, a query that matches the MV definition is not rewritten to use the MV; instead it scans the base table directly.

Root cause: DeltaLakePartitionTraits / KuduPartitionTraits getUpdatedPartitionNames() returns null because partition-change tracking is not implemented for these connectors. The MV timeliness arbiter (MVTimelinessNonPartitionArbiter) interprets a null base-table update info as "unknown" and returns MvUpdateInfo.fullRefresh, which marks the MV stale and disables query rewrite in the default CHECKED consistency mode.

This regressed after #73644, which changed the arbiter to treat null as "needs full refresh". Before that change null fell through to noRefresh, so a fresh external-table MV was eligible for rewrite (see #57686, which originally fixed this for Delta Lake and added the test_mv_deltalake_rewrite SQL case). Reproduces on branch-4.1.

What I'm doing:

DeltaLakePartitionTraits and KuduPartitionTraits getUpdatedPartitionNames() now return an empty set instead of null (i.e. "no updated partitions detected"), matching the behavior of other connectors that do not yet implement partition-change tracking (e.g. Hudi). This keeps a fresh Delta Lake / Kudu MV eligible for query rewrite in CHECKED mode. Two unit tests assert the MV timeliness arbiter reports NO_REFRESH (not FULL) for such MVs in the default CHECKED consistency mode.

Verified on a branch-4.1.3 cluster: in the default CHECKED mode, the plan for the MV-matching query changes from a direct DeltaLakeScanNode on the base table to OlapScanNode TABLE: test_mv1 (rewrite hits the MV).

Fixes StarRocks/StarRocksTest#11409

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5

@CelerData-Reviewer

Copy link
Copy Markdown

@codex review

@github-actions

Copy link
Copy Markdown
Contributor

Module-risk briefing for Codex review

This is review focus, not a finding list. Validate against the diff.

High-confidence risks

  • Module: connector/partitiontraits
    Changed files: fe/fe-core/src/main/java/com/starrocks/connector/partitiontraits/DeltaLakePartitionTraits.java, fe/fe-core/src/test/java/com/starrocks/connector/ConnectorPartitionTraitsTest.java
    Historical failure pattern: *PartitionTraits implementations feeding incorrect or incomplete signals (null returns, unhandled edge values, flat-hierarchy assumptions) into the MV timeliness/refresh path (MVTimelinessNonPartitionArbiter, PCTTableSnapshotInfo) cause wrong staleness/rewrite decisions — previously as false-negative staleness (sub-partition updates missed) and null-partition-value mishandling in Iceberg; here as the inverse, a null sentinel being misread as "unknown" and forcing an unwanted full refresh.
    Review focus: Confirm empty-set-vs-null is now handled consistently everywhere getUpdatedPartitionNames() is consumed (not just the arbiter path this PR targets); check whether other connectors' PartitionTraits implementations have the same null-as-"unknown" trap; verify the added unit test genuinely exercises the arbiter's interpretation of the return value, not just the trait method in isolation.
    Evidence: [BugFix] Fix MV async refresh skipping sub-partition updates in multi-level partitioned base tables #65596, [BugFix] fix iceberg read null partition bug #62934 (from 2 merged bugfixes)

@github-actions github-actions Bot requested review from Youngwb and dirtysalt July 14, 2026 12:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 412388bd87

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@GavinMar GavinMar marked this pull request as draft July 14, 2026 12:11
@GavinMar GavinMar force-pushed the fix_mv_rewrite_failed branch from 412388b to 5afae0a Compare July 15, 2026 02:56
@GavinMar GavinMar marked this pull request as ready for review July 15, 2026 03:02
@GavinMar GavinMar marked this pull request as draft July 15, 2026 03:17
…ry rewrite

DeltaLakePartitionTraits/KuduPartitionTraits.getUpdatedPartitionNames returned
null because partition-change tracking is not implemented for these connectors.
The MV timeliness arbiter treats a null base-table update info as "unknown" and
forces a full refresh, which marks the materialized view stale and disables
query rewrite in the default CHECKED consistency mode.

Return an empty set instead of null (i.e. "no updated partitions detected"),
matching the behavior of other connectors that do not yet implement
partition-change tracking (e.g. Hudi), so a fresh MV over a Delta Lake or Kudu
table stays eligible for query rewrite. Add unit tests asserting the MV
timeliness arbiter reports NO_REFRESH (not FULL) for such MVs in the default
CHECKED consistency mode.

Signed-off-by: GavinMar <yangguansuo@starrocks.com>
@GavinMar GavinMar force-pushed the fix_mv_rewrite_failed branch from 5afae0a to aa1d080 Compare July 15, 2026 03:35
@GavinMar GavinMar marked this pull request as ready for review July 15, 2026 03:36
@GavinMar GavinMar changed the title [BugFix] Fix Delta Lake un-partitioned materialized view query rewrite [BugFix] Fix Delta Lake and Kudu un-partitioned materialized view query rewrite Jul 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions

Copy link
Copy Markdown
Contributor

[FE Incremental Coverage Report]

pass : 2 / 2 (100.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 com/starrocks/connector/partitiontraits/DeltaLakePartitionTraits.java 1 1 100.00% []
🔵 com/starrocks/connector/partitiontraits/KuduPartitionTraits.java 1 1 100.00% []

@github-actions

Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@sonarqubecloud

Copy link
Copy Markdown

@stephen-shelby stephen-shelby merged commit f0f6f8c into StarRocks:main Jul 15, 2026
111 of 113 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@Mergifyio backport branch-4.1

@github-actions github-actions Bot removed the 4.1 label Jul 15, 2026
@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.1

✅ Backports have been created

Details

@GavinMar

Copy link
Copy Markdown
Contributor Author

@mergify backport branch-4.0

@mergify

mergify Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

backport branch-4.0

✅ Backports have been created

Details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants