Repository navigation
fix(plan): accept prepared conditional EWM decay expressions - #32435
Conversation
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.
bbd97bc to
8933e26
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
🚫 Left the queue · pull request dequeued10 min in the queue, with no time running CI. So far
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.
To get back in the queue
Tick the box to put this pull request back in the merge queue (same as
3 merge conditions met
Times in UTC · dashboard · how the merge queue works |
What type of PR is this?
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/CASEexpression with moerr 20203 (invalid argument function ewmmean, bad value [DOUBLE VARCHAR BOOL]) during preparation, beforeany parameter could be bound, while a bare
?marker and an explicitCAST(? 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 andrequired a half-life-capable slot behind it. The prepare-time transport of a
row-independent conditional (
IFNULL(?, 0.5), which lowers to CASE) publishesVARCHAR 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 parsesthe resolved value as the exact
'halflife'tag or a numeric alpha. The §7bind-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
TRUEto the numeric 1, which wouldsilently select event-time mode with
HalfLife=1.ewmEvaluatedArgnow keepsthe resolved value's boolean domain visible (
isBool) and the tag branchrejects 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/ignoreNApolicies, and string-typed prepared markerskeep 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. EachEXECUTEre-resolves thedecay 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 reportedprepared IFNULL/CASE decay shapes bind for all five EWM functions in
prepared mode (
mysql.Parse+plan.BuildPlanwith prepare=true), withORDER 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 checkerresolves the reported tuples; tag rows keep their half-life slot;
policy-slot strings stay rejected.
TestEwmDeferredTagFencesBooleanHalfLife(pkg/sql/compile) -TRUEbehind aconditionally resolved tag rejects; a boolean-typed conditional half-life
rejects; the identical shape with a numeric half-life constructs event-time
mode (recovery);
TRUEbehind a non-tag conditional decay remains a validadjust policy. Red on the unfenced code ("error is expected but got nil"),
green with the fence.
test/distributed/cases/window/ewm_statistics.result- theewmmean(x, 'span')expectation is corrected from the removed misclassification messageto 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/compilemo-cgo-test -count=1 -timeout=3600s ./pkg/sql/plan ./pkg/sql/plan/function ./pkg/sql/compile- all threeok(493.009s / 78.259s / 37.290s).'span'row and the in-file teardown (noewm_stat_test/ewm_stat_timedatabases remain).Upstream-signature maintenance: upstream
c99234dcf4(#32341) added a*PlanningInputparameter toplan.BuildPlan, so the coverage UT build of themerged head failed with
pkg/sql/plan/ewm_binder_test.go:267: not enough arguments in call to BuildPlan(run 42677821953, job 129364355585). The branchwas rebased onto current
main, and the prepared-binding helper inTestEwmPreparedNestedConditionalDecaynow passesnilfor 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 remainunsupported 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.