Repository navigation
fix: support SUM/AVG over boolean expressions - #24692
Conversation
Add T_bool to SumSupportedTypes so SUM(bool_expr) and AVG(bool_expr) work correctly, matching MySQL behavior where booleans are implicitly coerced to 0/1 in numeric contexts. Introduce VarStdDevSupportedTypes (without T_bool) for the variance/stddev aggregate functions to avoid runtime panics, since their execution path does not yet handle bool inputs. Fixes matrixorigin#24547
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? |
The func_aggr_sum.test expected an error for SUM(bool_expr), but the PR correctly makes SUM and AVG accept boolean expressions. Update the expected result to match the new computed output.
aunjgr
left a comment
There was a problem hiding this comment.
Clean fix enabling SUM(bool) and AVG(bool) — a common MySQL pattern for counting matches (e.g., SUM(col > 4)).
Changes:
sumavg2.go: addT_booltoSumReturnType(maps toT_uint64) and execution dispatch (newSumAvgExec[uint64, uint8])list_agg.go: create separateVarStdDevSupportedTypeswithoutT_boolso VARIANCE/STDDEV still reject bool; change the 4 Var/Stddev overloads to use it; keepSumSupportedTypeswithT_booladded
BVT is extremely thorough: bool column, DISTINCT, comparison expressions (>, <, =, !=), AND/OR/NOT, IS NULL, BETWEEN, IN, LIKE, GROUP BY, HAVING, WHERE, subquery, all-true/all-false/NULL edge cases, and VARIANCE/STDDEV rejection. LGTM.
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM from 3 angles:
- Logic: SUM/AVG now accept BOOL with correct return semantics (
sum -> uint64,avg -> float64), and VARIANCE/STDDEV stay blocked viaVarStdDevSupportedTypes. - Compatibility: this matches the common MySQL pattern
SUM(bool_expr)/AVG(bool_expr)without widening VAR/STDDEV behavior. - Coverage: BVT covers bool columns, comparison expressions, DISTINCT, GROUP BY/HAVING/WHERE, NULL cases, nested boolean expressions, subquery usage, and negative variance/stddev cases.
Approve.
Merge Queue Status
This pull request spent 1 hour 24 minutes 6 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
Merge Queue Status
This pull request spent 14 minutes 9 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonThe merge conditions cannot be satisfied due to failing checks HintYou may have to fix your CI before adding the pull request to the queue again. |
Merge Queue Status
This pull request spent 1 hour 52 minutes 21 seconds in the queue, including 1 hour 53 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24547
What this PR does / why we need it:
MatrixOne rejects the MySQL-idiomatic pattern
SUM(<boolean expression>)withbad value [BOOL].In MySQL, booleans are implicitly coerced to 0/1 in numeric contexts, so
SUM(bool_expr)naturally counts rows matching a condition.This is an extremely common pattern in observability queries (e.g.,
SUM(status = 'ERROR')).This PR adds
T_boolsupport for the SUM and AVG aggregate functions:list_agg.go: Addedtypes.T_booltoSumSupportedTypes, allowing bool through the type check for SUM/AVG. IntroducedVarStdDevSupportedTypes(without bool) for the variance/stddev functions to avoid runtime panics, since their execution path does notyet handle bool inputs.
sumavg2.go: Addedtypes.T_booltoSumReturnType(returnsuint64). Addedcase types.T_boolinmakeSumAvgExec,dispatching to
newSumAvgExec[uint64, uint8]— bool is 1 byte (0/1), read asuint8and accumulated asuint64, matching MySQLbehavior.