Skip to content

branch-4.1: [test](nereids) Replace flaky null stats case with unit test - #65656

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
shuke987:codex/backport-65445-branch-4.1
Jul 16, 2026
Merged

branch-4.1: [test](nereids) Replace flaky null stats case with unit test#65656
yiguolei merged 1 commit into
apache:branch-4.1from
shuke987:codex/backport-65445-branch-4.1

Conversation

@shuke987

@shuke987 shuke987 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PR: #65445

Problem Summary:

Backport #65445 to branch-4.1.

The regression case test_scale_num_nulls depends on asynchronously visible physical row counts. When the physical row count is still 0, Nereids scales the selected-partition column statistics to 0 even though the injected partition/table statistics are correct, making the case flaky.

Replace the environment-dependent Groovy regression case with a deterministic FE unit test that directly constructs the partition/table statistics and verifies selected-partition scaling, including row count, NDV, min/max, count, and numNulls.

Coverage rationale

  • This is a branch backport of merged PR [test](nereids) Replace flaky null stats case with unit test #65445. The same planner-level coverage concern was raised in the upstream review thread, then explicitly resolved by a maintainer before the PR was approved and merged.
  • The independent behavior introduced with [opt](nereids) scale num_nulls in col stats when partition pruned #62265 is selected-partition statistics scaling. The replacement test invokes the real StatsCalculator.computeOlapScan() path and verifies row count, NDV, min/max, count, and numNulls. SQL predicate-to-partition selection remains covered by PruneOlapScanPartitionTest on this release branch.
  • The removed cluster case sampled the strict physical partition row count immediately after insert/analyze. In Cloud P0 that value can remain 0 for up to two minutes even when table-level column statistics are correct. Retaining the case or waiting for that report would preserve the flake or add up to two minutes to the suite.
  • SHOW COLUMN STATS was only failure diagnostics, and memo text formatting was not an independent assertion target of this case.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason

    Local validation:

    • StatsCalculatorTest#testComputeOlapScanScalesNumNullsForSelectedPartitions: passed (1 test)
    • StatsCalculatorTest: passed (17 tests)
    • mvn -pl fe-core -am checkstyle:check: passed (0 violations)
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

…65445)

Related PR: apache#62265

Problem Summary:

`test_scale_num_nulls` checks that table-level `numNulls=3` is scaled to
`1` when partition pruning selects 4 of 12 rows. The regression case
executes `EXPLAIN MEMO PLAN` immediately after insert and analyze, but
Cloud P0 reports the physical partition row count asynchronously. The
planner can therefore observe a transient selected-partition row count
of zero, while waiting for the real row count can take up to two
minutes.

This change:

- adds deterministic FE unit coverage that invokes
`StatsCalculator.computeOlapScan()` with a three-partition OLAP scan;
- fixes the table row count at 12, selected-partition row count at 4,
and cached table-level column statistics at `ndv=1`, `min=max=2`, and
`numNulls=3`;
- verifies the final scan statistics have `ndv=1`, `min=max=2`,
`count=4`, and scaled `numNulls=1`;
- removes the timing-dependent Groovy regression case.

The unit test exercises the production partition-pruning statistics path
using fixed in-memory inputs. It has no cluster, physical row-count
reporting, polling, sleep, network, or storage dependency. Production
behavior is unchanged.
@shuke987
shuke987 requested a review from yiguolei as a code owner July 15, 2026 10:18
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@shuke987

Copy link
Copy Markdown
Contributor Author

run buildall

@shuke987

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found one blocking review issue. The added unit test is useful and appears to exercise the local selected-partition null-scaling branch, but the PR also deletes the only SQL-level regression I could find for the original analyze/cache/pruning/memo-plan path.

Static validation only: per the review prompt I did not run builds or FE/regression tests. git diff --check passed for the PR range. No additional user focus was provided, and no existing inline review comments were present to deduplicate against.

"""
def colStats = sql "show column stats ptable";
def memo = sql "explain memo plan select * from ptable where d='2017-01-01'"
// check numNulls=1.0000 for column val, which is scaled from 3 to 1 according to the partition pruning result.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This removes the only SQL-level guard I could find for the original behavior. The replacement unit test stubs getSelectedPartitionIds(), table/partition row counts, and OlapTableStatistics.getColumnStatistics() before calling computeOlapScan() directly, so it proves the local numNulls scaling arithmetic but no longer exercises the path that can regress in production: analyze table ... with sync populating table stats, planner partition pruning selecting p201701, and memo-plan stats rendering count=4.0000, numNulls=1.0000. Please keep this regression, or replace it with a smaller SQL-level case that still drives analyze/cache loading, partition pruning, and memo output; the new unit test can remain as fast coverage.

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage `` 🎉
Increment coverage report
Complete coverage report

@shuke987

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Completed the review for PR 65656 at head cf4803f26eb023380c5ed88b42d673f42c50807a.

Summary:

  • I found no new distinct inline issue beyond the existing review thread on regression-test/suites/statistics/test_scale_num_nulls.groovy, which already covers the actionable concern that deleting the SQL regression removes end-to-end coverage for analyze table ... with sync, stats cache loading, partition pruning, and memo stats rendering.
  • The added StatsCalculatorTest.testComputeOlapScanScalesNumNullsForSelectedPartitions appears to exercise the intended base-index partition-pruned computeOlapScan branch: selected/table row counts are 4/12, table-level cached numNulls is 3, and the assertion expects scaled numNulls 1.
  • I did not find a separate compile/runtime/isolation problem in the new unit test. Mockito inline/static mocking is available in the FE test dependencies, the Env static mock is scoped, and ConnectContext is restored in finally.

Review checkpoints:

  • Existing inline comments were checked and duplicate findings were suppressed.
  • The changed-file list and authoritative local diff were reviewed; no extra changed paths were found.
  • Round 1 normal subagents and the risk-focused subagent all returned NO_NEW_VALUABLE_FINDINGS; no unresolved candidate findings remain.
  • No additional user-provided review focus was present.

Validation limits:

  • Static review only. I did not run builds or tests per the review prompt.
  • No repo-local code-review SKILL.md path was present in the confirmed file listing, so I followed the explicit review prompt and prepared review bundle.

@yiguolei

Copy link
Copy Markdown
Contributor

skip buildall

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR approved by at least one committer and no changes requested.

@yiguolei
yiguolei merged commit a19d0f7 into apache:branch-4.1 Jul 16, 2026
35 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants