← Back to Pull requests

[fix](mtmv) Reanalyze partition expressions using MV output columns #70289

Closed
unknown closed this pull request without merging on Dec 03, 2026 09:48 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 10:37 UTC
Author

Background

A partitioned asynchronous materialized view persists both its MV output partition column name (partitionCol) and the inferred base-table partition expression (expr, e.g., date_trunc(base_col, 'day')). When a base table undergoes a schema change, MV refresh reanalyzes the saved query and validates column and partition compatibility against the stored metadata.

What problem does this PR solve?

Issue Number: None
Related PR: #56423 (introduced refresh-time partition reanalysis)
PR Type: Bugfix

Problem Summary:

After a compatible base-table schema change (such as widening a non-partition VARCHAR column), an asynchronous materialized view created with an aliased date partition column (for example PARTITION BY (trx_date) AS SELECT date_trunc(dt, 'day') AS trx_date, v FROM src, or a UNION ALL over multiple base tables unified as trx_date) fails refresh with partition column can not find from sql select column. Reanalysis now uses the stored MV output partition column and truncation unit directly instead of parsing the stored base-table lineage expression back as a query output reference.

Details

  • Change map: 2 production files changed (MTMVPlanUtil.java and MTMVPartitionDefinition.java, +70/-16 lines) and 1 FE unit test file (MTMVPartitionReanalysisTest.java, 234 lines).

  • Frequency: Always when schema-change reanalysis runs on an EXPR-partitioned MV whose base-table partition column name differs from the MV output partition column alias.

  • Root cause: MTMVPlanUtil.analyzeQueryWithSql() converted mvPartitionInfo.getExpr() (which references the base-table column name) to SQL and re-parsed it as MTMVPartitionDefinition.functionCallExpression. MTMVPartitionDefinition then looked up that base-table column name in the MV query's top-level output slots, which only expose the MV alias (trx_date).

  • Why existing tests missed it: Existing MTMVPlanUtilTest cases did not cover EXPR-partitioned MVs with aliased date_trunc output columns undergoing schema-change reanalysis.

  • Fix:

  • - Add MTMVPartitionDefinition.forReanalysis(MTMVPartitionInfo) and call it from MTMVPlanUtil.analyzeQueryWithSql(), passing the stored MV output partitionCol and date_trunc timeUnit directly without SQL round-tripping.
    - During EXPR reanalysis in MTMVPartitionDefinition.getRelatedTableInfos(), first trace partitionCol without adding a redundant outer date_trunc and reuse that lineage when every traced base partition column already matches the stored date_trunc unit (handling PARTITION BY (trx_date) queries including WEEK/QUARTER, unit-first date_trunc(unit, col), and disabled MERGE_DATE_TRUNC). Otherwise fall back to getRelatedTableInfos(partitionCol, timeUnit, ...) to handle bare-column or coarser-rollup PARTITION BY (date_trunc(trx_date, unit)) declarations.
    - Keep all existing partition lineage and compatibility checks in PartitionIncrementChecker and MTMVPlanUtil.checkMTMVPartitionInfoLike().
  • Other paths and branches: Applies to MTMVPlanUtil.analyzeQueryWithSql() and ensureMTMVQueryUsable() on master. SELF_MANAGE, FOLLOW_BASE_TABLE, and CREATE MATERIALIZED VIEW paths remain unchanged.

  • Behavior change: Compatible base-table schema changes no longer cause spurious partition-column lookup failures during MV refresh reanalysis when the partition output column is aliased.
  • Testing

  • MTMVPartitionReanalysisTest: 18 tests passed (covering single-table and UNION ALL aliases with both implicit and explicit date_trunc partition declarations, bare-column explicit rollup, finer-to-coarser explicit rollup, JOIN queries, WEEK/QUARTER units, reversed DATE_TRUNC argument order with MERGE_DATE_TRUNC disabled, quoted/dotted aliases, and rejection of incompatible source or unit changes).

  • MTMVPlanUtilTest: 25 tests passed.

  • FE Checkstyle (mvn -f fe/pom.xml -pl fe-core -am validate -DskipTests): passed.
  • Release note

    Fix refresh failures for asynchronous materialized views with aliased date partition outputs after compatible base-table schema changes.

    Check List (For Author)

  • Behavior changed: Yes (see Details)

  • Does this need documentation: No

  • Pre-submission status: Locally verified with focused FE unit tests and Checkstyle; full CI pending.
  • Diff: 545 lines (+408 / -137) across 6 files Reviewer: morrySnow Review duration: 40270m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 545 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.377
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #70289"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48% (MEDIUM) · Higher = larger blast radius
    48%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.0% · Safe to merge
    19.0%
    Repository