Repository navigation
fix(function): accept boolean values in math functions - #28513
Conversation
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? |
84b6774 to
fc62605
Compare
fc62605 to
e078b18
Compare
e078b18 to
374dc32
Compare
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed current head a2fca9f. I found no correctness blocker in the scoped BOOL numeric matcher or cast implementations. Non-BOOL overload behavior and CEIL/FLOOR compatibility are preserved; NULL and masked-row handling are consistent with the existing cast contract. CI is green.
One useful regression addition is the original SQL PREPARE/EXECUTE case: PREPARE 'SELECT SIN(?)', then execute with TRUE, FALSE, and NULL. The current prepared-marker unit test checks overload resolution but does not exercise the frontend parameter-binding path where the original silent mis-evaluation occurred.
## Summary Fix the distributed dispatch race behind #28313 and the `shuffle target receiver ... was removed, data loss may occur` failure seen in #28513 CI. A receiver that explicitly sends `StopSending` is a consumer-owned retirement. The previous implementation collapsed that control signal into generic receiver removal, synthesized a data-loss error, and allowed the legacy `Err` channel to compete with the immutable remote terminal. That could mask the original business error (for example, `DuplicateEntry`) and produce cleanup warnings such as `channel full`. This change: - preserves one terminal owner per receiver generation; - treats only a certified `StopSending` as normal retirement; - keeps unqualified receiver/transport termination fail-closed in strict dispatch paths; - lets shuffle dispatch continue across other matched receivers after an explicit retirement; - keeps legacy `Err` notification only for registrations without a terminal; - removes the obsolete 515-line low-value integration test and keeps focused strict, tolerant, cancellation, terminal, and shuffle oracles. ## Validation - `go test ./pkg/sql/colexec/dispatch -count=1` - `go test -race ./pkg/sql/colexec/dispatch -count=10` - `go test ./pkg/sql/compile -count=1` - `go test -race ./pkg/sql/compile -count=1` - `go test ./pkg/sql/colexec -count=1` - `go test ./pkg/tests/issues -run TestIssue28313EmptyRemoteDispatch -count=1` - `go test -race ./pkg/tests/issues -run TestIssue28313EmptyRemoteDispatch -count=1` - `go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile` The focused validation used the repository's installed CGo headers and libraries. The exact multi-CN BVT requires the CI cluster topology and was not run locally. Closes #28313 --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #28484 Follow-up to #28513: fixes the SQL PREPARE/EXECUTE Boolean acceptance failure reported after that change merged. ## What this PR does / why we need it: SQL `EXECUTE` transports user-variable values through a text-shaped vector but retains their logical prepare-time category. The planner must use that provenance for numeric consumers without changing the historical result domain of a bare SQL `?` projection. Before this fix, `TRUE` in `CAST(? AS DOUBLE)`, `SIN(?)`, or `ACOS(?)` could be parsed as an ordinary nonnumeric string and become zero in MySQL mode. Integer consumers such as `ABS(?)`, `ROUND(?)`, and `SIGN(?)` could reject the same Boolean with an invalid cast. A Boolean value can also be reused across executions, NULLs, ordinary strings, and direct-result/numeric sibling expressions. ## Design and implementation - SQL EXECUTE carries Boolean `SourceType` metadata for overload rebinding; `HasRuntimeType` remains unset for a bare SQL result marker, preserving its TEXT result metadata. Explicit COM_STMT runtime types remain authoritative. - Numeric consumers use the source type to select the existing integer/float overloads. The shared string-to-float conversion consults row-local Boolean provenance and maps canonical Boolean transport values to `0`/`1`. - NULLs and inactive selection rows are handled before conversion. Ordinary SQL strings such as `'true'` stay on the existing string-coercion and warning path; malformed values marked as Boolean fail explicitly. - The integration regression closes each query's `Rows` in a per-iteration scope, so assertion failures cannot retain server-side result resources. - The repository's `.agents/skills/mo-dev` now documents changed-package static checks and evidence-based CI/environment triage instead of requiring a whole-repository SCA in every edit loop. - No wire-format, persistence, planner-cache, synchronization, I/O, or background-work change is introduced. Runtime plan copies remain isolated from the cached prepared plan. ## Test plan Validated from a clean worktree rebased onto `origin/main` commit `44b7f90ee1695831663c55288a537c03c15c00e0`: - `pkg/sql/plan/function`: Boolean FLOAT/DOUBLE casts, inactive rows, and numeric math consumers; focused `-race` passed. - `pkg/sql/plan`: numeric overload/source-type rebinding, direct-result domain isolation, cache-plan immutability, and existing prepared parameter tests; focused `-race` passed. - `pkg/frontend`: prepared execution/metadata and related reuse tests; focused `-race` passed. - `TestIssue27088PreparedDecimalCommonType`: real embedded SQL PREPARE/EXECUTE coverage for TRUE/FALSE/NULL/string/reuse, integer targets, JSON controls, and the direct-parameter-before/after-numeric-sibling case passed in 9.5s after the SCA cleanup fix. - `prepare/numeric_context` changes add the reported CAST/SIN/ACOS and ABS/ROUND/SIGN reuse cases. - Incremental `golangci-lint` `sqlclosecheck` on `pkg/tests/issues`, with the repository CGo include paths, passed with `0 issues`. - `quick_validate.py .agents/skills/mo-dev` and `git diff --check` passed. CI was not awaited. The current PR's historical compose information-schema failure and resource-heavy UT cancellation are outside the changed paths; no unrelated test or catalog behavior was modified here. ## Review status The complete final diff was reviewed with GPT-6 medium after implementation. No remaining P0/P1/P2 semantic, metadata, NULL/mask, reuse, lifecycle, or performance blocker was identified. Final head: `cec5ce0bc645f3d4a52450312a540541cb703e18`.
…28513) ## Summary Fixes matrixorigin#28484. MatrixOne rejected or mis-evaluated Boolean expressions in mathematical functions. In MySQL numeric context, `TRUE` is `1`, `FALSE` is `0`, and `NULL` remains `NULL`, consistently for direct expressions, predicates, columns, and prepared parameters. ## Root cause The affected overload sets used `fixedTypeMatch`, while the global implicit cast table intentionally did not admit BOOL-to-numeric casts. Prepared markers could still select a floating-point target, but the runtime BOOL cast dispatcher had no FLOAT32/FLOAT64 implementation, so execution could reject or misread a bound Boolean. ## Changes - Added an opt-in numeric-context matcher that resolves BOOL as INT64 for overload selection and then emits a real cast to the selected numeric type. - Applied it to the affected integer and floating-point math functions, including ABS, SQRT, SIGN, ACOS, ASIN, ATAN/ATAN2, COS, COT, SIN/SINH, TAN, DEGREES, RADIANS, EXP, LN, LOG/LOG2/LOG10, POWER/POW, ROUND, and TRUNCATE. - Added BOOL-to-FLOAT32/FLOAT64 conversion with TRUE/FALSE and NULL preservation. BOOL-to-integer conversion now also respects expression row masks, so a short-circuited row cannot be materialized as a non-NULL value. - Kept the global implicit-cast table unchanged and left CEIL/FLOOR on their existing VARCHAR fallback because those direct Boolean forms already worked; this avoids an unrelated return-type change. ## Test plan - Added overload-resolution coverage for direct and prepared-marker paths, binary math arguments, aliases, and non-numeric fallback behavior. - Added dispatcher tests for BOOL to INT64/FLOAT32/FLOAT64, NULL propagation, masked rows, and end-to-end SIN/POWER execution after implicit casts. - Passed: ```text ./.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/sql/plan/function git diff --check ``` The branch was rebased onto the latest `main` before updating this PR. CI was not waited on after the push.
…xorigin#28539) ## Summary Fix the distributed dispatch race behind matrixorigin#28313 and the `shuffle target receiver ... was removed, data loss may occur` failure seen in matrixorigin#28513 CI. A receiver that explicitly sends `StopSending` is a consumer-owned retirement. The previous implementation collapsed that control signal into generic receiver removal, synthesized a data-loss error, and allowed the legacy `Err` channel to compete with the immutable remote terminal. That could mask the original business error (for example, `DuplicateEntry`) and produce cleanup warnings such as `channel full`. This change: - preserves one terminal owner per receiver generation; - treats only a certified `StopSending` as normal retirement; - keeps unqualified receiver/transport termination fail-closed in strict dispatch paths; - lets shuffle dispatch continue across other matched receivers after an explicit retirement; - keeps legacy `Err` notification only for registrations without a terminal; - removes the obsolete 515-line low-value integration test and keeps focused strict, tolerant, cancellation, terminal, and shuffle oracles. ## Validation - `go test ./pkg/sql/colexec/dispatch -count=1` - `go test -race ./pkg/sql/colexec/dispatch -count=10` - `go test ./pkg/sql/compile -count=1` - `go test -race ./pkg/sql/compile -count=1` - `go test ./pkg/sql/colexec -count=1` - `go test ./pkg/tests/issues -run TestIssue28313EmptyRemoteDispatch -count=1` - `go test -race ./pkg/tests/issues -run TestIssue28313EmptyRemoteDispatch -count=1` - `go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile` The focused validation used the repository's installed CGo headers and libraries. The exact multi-CN BVT requires the CI cluster topology and was not run locally. Closes matrixorigin#28313 --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#28484 Follow-up to matrixorigin#28513: fixes the SQL PREPARE/EXECUTE Boolean acceptance failure reported after that change merged. ## What this PR does / why we need it: SQL `EXECUTE` transports user-variable values through a text-shaped vector but retains their logical prepare-time category. The planner must use that provenance for numeric consumers without changing the historical result domain of a bare SQL `?` projection. Before this fix, `TRUE` in `CAST(? AS DOUBLE)`, `SIN(?)`, or `ACOS(?)` could be parsed as an ordinary nonnumeric string and become zero in MySQL mode. Integer consumers such as `ABS(?)`, `ROUND(?)`, and `SIGN(?)` could reject the same Boolean with an invalid cast. A Boolean value can also be reused across executions, NULLs, ordinary strings, and direct-result/numeric sibling expressions. ## Design and implementation - SQL EXECUTE carries Boolean `SourceType` metadata for overload rebinding; `HasRuntimeType` remains unset for a bare SQL result marker, preserving its TEXT result metadata. Explicit COM_STMT runtime types remain authoritative. - Numeric consumers use the source type to select the existing integer/float overloads. The shared string-to-float conversion consults row-local Boolean provenance and maps canonical Boolean transport values to `0`/`1`. - NULLs and inactive selection rows are handled before conversion. Ordinary SQL strings such as `'true'` stay on the existing string-coercion and warning path; malformed values marked as Boolean fail explicitly. - The integration regression closes each query's `Rows` in a per-iteration scope, so assertion failures cannot retain server-side result resources. - The repository's `.agents/skills/mo-dev` now documents changed-package static checks and evidence-based CI/environment triage instead of requiring a whole-repository SCA in every edit loop. - No wire-format, persistence, planner-cache, synchronization, I/O, or background-work change is introduced. Runtime plan copies remain isolated from the cached prepared plan. ## Test plan Validated from a clean worktree rebased onto `origin/main` commit `44b7f90ee1695831663c55288a537c03c15c00e0`: - `pkg/sql/plan/function`: Boolean FLOAT/DOUBLE casts, inactive rows, and numeric math consumers; focused `-race` passed. - `pkg/sql/plan`: numeric overload/source-type rebinding, direct-result domain isolation, cache-plan immutability, and existing prepared parameter tests; focused `-race` passed. - `pkg/frontend`: prepared execution/metadata and related reuse tests; focused `-race` passed. - `TestIssue27088PreparedDecimalCommonType`: real embedded SQL PREPARE/EXECUTE coverage for TRUE/FALSE/NULL/string/reuse, integer targets, JSON controls, and the direct-parameter-before/after-numeric-sibling case passed in 9.5s after the SCA cleanup fix. - `prepare/numeric_context` changes add the reported CAST/SIN/ACOS and ABS/ROUND/SIGN reuse cases. - Incremental `golangci-lint` `sqlclosecheck` on `pkg/tests/issues`, with the repository CGo include paths, passed with `0 issues`. - `quick_validate.py .agents/skills/mo-dev` and `git diff --check` passed. CI was not awaited. The current PR's historical compose information-schema failure and resource-heavy UT cancellation are outside the changed paths; no unrelated test or catalog behavior was modified here. ## Review status The complete final diff was reviewed with GPT-6 medium after implementation. No remaining P0/P1/P2 semantic, metadata, NULL/mask, reuse, lifecycle, or performance blocker was identified. Final head: `cec5ce0bc645f3d4a52450312a540541cb703e18`.
Summary
Fixes #28484.
MatrixOne rejected or mis-evaluated Boolean expressions in mathematical
functions. In MySQL numeric context,
TRUEis1,FALSEis0, andNULLremains
NULL, consistently for direct expressions, predicates, columns, andprepared parameters.
Root cause
The affected overload sets used
fixedTypeMatch, while the global implicitcast table intentionally did not admit BOOL-to-numeric casts. Prepared markers
could still select a floating-point target, but the runtime BOOL cast
dispatcher had no FLOAT32/FLOAT64 implementation, so execution could reject or
misread a bound Boolean.
Changes
overload selection and then emits a real cast to the selected numeric type.
including ABS, SQRT, SIGN, ACOS, ASIN, ATAN/ATAN2, COS, COT, SIN/SINH, TAN,
DEGREES, RADIANS, EXP, LN, LOG/LOG2/LOG10, POWER/POW, ROUND, and TRUNCATE.
preservation. BOOL-to-integer conversion now also respects expression row
masks, so a short-circuited row cannot be materialized as a non-NULL value.
existing VARCHAR fallback because those direct Boolean forms already worked;
this avoids an unrelated return-type change.
Test plan
Added overload-resolution coverage for direct and prepared-marker paths,
binary math arguments, aliases, and non-numeric fallback behavior.
Added dispatcher tests for BOOL to INT64/FLOAT32/FLOAT64, NULL propagation,
masked rows, and end-to-end SIN/POWER execution after implicit casts.
Passed:
The branch was rebased onto the latest
mainbefore updating this PR. CI wasnot waited on after the push.