Skip to content

fix(plan): accept prepared conditional EWM decay expressions - #32435

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-31952-main-bbaa2d46
Nov 9, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-31952-main-bbaa2d46

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #31952

Related to #31952

What this PR does / why we need it:

EWM window functions rejected a prepared numeric decay marker nested inside a
row-independent IFNULL/CASE expression with moerr 20203 (invalid argument function ewmmean, bad value [DOUBLE VARCHAR BOOL]) during preparation, before
any parameter could be bound, while a bare ? marker and an explicit
CAST(? AS DOUBLE) prepared fine.

Root cause: ewmTypeCheck (pkg/sql/plan/function/list_window.go)
hard-interpreted every string-typed decay as the 'halflife' tag form and
required a half-life-capable slot behind it. The prepare-time transport of a
row-independent conditional (IFNULL(?, 0.5), which lowers to CASE) publishes
VARCHAR for the decay slot, so the overload check failed and the statement
never reached the runtime-constancy admission or the per-execution
configuration parser, both of which already implement the intended semantics.

Change: a string-typed decay now declares the tag form only when the slot
behind it can be a half-life (T_any, T_text or the numeric domain); any other
shape defers the decay-kind verdict to the per-execution configuration
boundary in constructEwmConfig (pkg/sql/compile/operator.go), which parses
the resolved value as the exact 'halflife' tag or a numeric alpha. The §7
bind-time literal rejections stay in the window binder.

Guard for the deferred path (review finding): per-execution resolution also
admits a decay that resolves to the tag with a boolean in the following slot;
the shared constant evaluator collapsed TRUE to the numeric 1, which would
silently select event-time mode with HalfLife=1. ewmEvaluatedArg now keeps
the resolved value's boolean domain visible (isBool) and the tag branch
rejects it with the pinned §7 message ("ewm halflife decay requires a strictly
positive half-life constant"), matching the bind-time literal path. Booleans
remain valid adjust/ignoreNA policies, and string-typed prepared markers
keep their numeric-text half-life parse.

Result: PREPARE ew FROM 'SELECT ewmmean(CAST(result AS DOUBLE), IFNULL(?, 0.5), FALSE) OVER (ORDER BY result) FROM generate_series(1, 4) g'
now prepares for every EWM function; with the parameter bound to 0.5 over
values 1..4 it returns 1, 1.5, 2.25, 3.125. Each EXECUTE re-resolves the
decay and policy positions and rebuilds the window configuration.

Issue-to-test proof (all shown red first and green after the change):

  • TestEwmPreparedNestedConditionalDecay (pkg/sql/plan) - the reported
    prepared IFNULL/CASE decay shapes bind for all five EWM functions in
    prepared mode (mysql.Parse + plan.BuildPlan with prepare=true), with
    ORDER BY latitude, execution-dependence flag, CAST/literal-CASE controls
    and the kept rejections (column-dependent conditional, literal non-tag
    decay, tag without half-life). On the unfixed base this reproduces the
    reported 20203 rejection.
  • TestEwmStringDecayRejectsCheckLevel (pkg/sql/plan) - the overload checker
    resolves the reported tuples; tag rows keep their half-life slot;
    policy-slot strings stay rejected.
  • TestEwmDeferredTagFencesBooleanHalfLife (pkg/sql/compile) - TRUE behind a
    conditionally resolved tag rejects; a boolean-typed conditional half-life
    rejects; the identical shape with a numeric half-life constructs event-time
    mode (recovery); TRUE behind a non-tag conditional decay remains a valid
    adjust policy. Red on the unfenced code ("error is expected but got nil"),
    green with the fence.
  • BVT test/distributed/cases/window/ewm_statistics.result - the ewmmean(x, 'span') expectation is corrected from the removed misclassification message
    to the §7 declared-decay message its neighboring rows already publish.

Test commands:

  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestEwmPreparedNestedConditionalDecay$|^TestEwmStringDecayRejectsCheckLevel$' ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestEwmDeferredTagFencesBooleanHalfLife$' ./pkg/sql/compile
  • Owning packages in normal mode: mo-cgo-test -count=1 -timeout=3600s ./pkg/sql/plan ./pkg/sql/plan/function ./pkg/sql/compile - all three ok (493.009s / 78.259s / 37.290s).
  • The exact changed BVT case executed in comparison mode with mo-tester against a locally launched single-node MatrixOne built from this branch: all 377 statements compared green on the first execution and again on a second execution against the same instance, including the corrected 'span' row and the in-file teardown (no ewm_stat_test/ewm_stat_time databases remain).

Upstream-signature maintenance: upstream c99234dcf4 (#32341) added a
*PlanningInput parameter to plan.BuildPlan, so the coverage UT build of the
merged head failed with pkg/sql/plan/ewm_binder_test.go:267: not enough arguments in call to BuildPlan (run 42677821953, job 129364355585). The branch
was rebased onto current main, and the prepared-binding helper in
TestEwmPreparedNestedConditionalDecay now passes nil for the new parameter,
matching every other in-tree test caller. No production-code or behavior change.

Residual risks / limitations: the EWM functions are the repository's own
feature (docs/design/ewm_window_statistics.md §7/§9), not a pandas ewm()
clone; row-dependent decay/policy expressions, decay text other than the
'halflife' tag, boolean half-lives and explicit window frames remain
unsupported and rejected. The CI-side distributed BVT groups along with the
MOTR/big-data integration runs remain the confirming venues for the prepared
protocols at scale.

EWM window functions rejected a prepared numeric decay nested in a
row-independent IFNULL/CASE with moerr 20203: the prepared transport
publishes VARCHAR for the decay slot and the overload checker
hard-interpreted every string-typed decay as the 'halflife' tag form,
failing the check before a parameter could be bound. A string-typed
decay now declares the tag form only when the slot behind it can be a
half-life; any other shape defers the decay-kind verdict to the
per-execution configuration boundary, which already parses the
resolved value as the 'halflife' tag or a numeric alpha while the
bind-time literal rejections stay in the window binder.

The same deferral admits a decay that resolves to the tag per
execution; keep the resolved value's boolean domain visible until
constructEwmConfig's tag branch validates the half-life so a TRUE
there rejects instead of coercing to HalfLife=1, while boolean
policies at the adjust/ignoreNA slots and the numeric-text parse of
string-typed prepared half-life markers stay unchanged.

Related to matrixorigin#31952

Rebased onto main for upstream c99234d (matrixorigin#32341), which added a
*PlanningInput parameter to plan.BuildPlan; the prepared-binding test
helper now passes nil for it like every other in-tree caller.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 8933e26feb9bd2b539cf0b120ab8bedd084bd2db

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH 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.

mo-bot review · mo-bot-local · review

Commit: 8933e26feb9bd2b539cf0b120ab8bedd084bd2db

Assessment: approve

No actionable findings. Prepared conditional decays reuse the existing per-execution configuration parser, and resolved boolean half-lives are correctly rejected.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete delta, relevant owners/consumers, linked issue and all discussion. Source remains unchanged.

  • All three owning Go suites passed, including the changed regressions. Exact-base production-owner controls reproduced the intended failures.

  • Text and binary prepared-protocol probes passed for all five EWM functions, parameter changes, NULL fallback, invalid-value recovery and boolean-domain controls.

  • Exact EWM BVT passed 377/377 statements twice on the same owned single-CN instance, with teardown verified between runs.

  • Receipts and retained logs are reconciled in /home/xupeng/.local/state/mo-bot-55/jobs/2fa9730f5daa4f761cacadce/attempt-1/validation-index.json; final audit: checks/1794261359640686497-3.json.

Limitations:

  • Two existing planner subtests skipped. Reviewer setup failures are retained and excluded from passing evidence.

  • BVT used an embedded single-CN fixture with metadata comparison excluded. MOTR/big-data and standalone distributed validation were not run.

@mergify mergify Bot added the queued label Nov 9, 2026
@mergify

mergify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

10 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 9 Nov, 21:58 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • 🚫 Left the queue 22:08 · 8933e26

Reason

Pull request #32435 has been dequeued

Mergify failed to merge the pull request. GitHub can't merge the pull request after 10 minutes of retrying.

Required status check "CI Required" is expected.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — 8933e26f Deployed Nov 9, 2026 by gouhongshen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants