Repository navigation
Description
Description
MatrixOne rejects JSON operands for MySQL numeric aggregate functions. MySQL converts non-NULL JSON values to numeric form for aggregation; MatrixOne rejects the expression during binding even when every JSON value is a numeric scalar.
Environment
- MatrixOne: latest official
main, commit07fdd4ae0f80f287b93fc4b525fd296d5617abc7 - Deployment: local standalone launch (isolated Log/TN/CN ports and data directory)
- MySQL JSON aggregation contract: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-aggregation
Reproduction
create table t(id int, j json);
insert into t values (1,'1'),(2,'2.5'),(3,'3'),(4,null);
select sum(j), avg(j), var_pop(j), var_samp(j),
stddev_pop(j), stddev_samp(j)
from t;MatrixOne behavior
invalid argument aggregate function sum, bad value [JSON]
Executing each function separately produces its corresponding binding error. Ordinary and window forms reproduce in 3/3 fresh runs.
Control
The equivalent explicit numeric conversion succeeds in MatrixOne:
select sum(cast(j as double)), avg(cast(j as double)),
var_pop(cast(j as double)), stddev_pop(cast(j as double))
from t;6.5, 2.1666666666666665, 0.7222222222222223, 0.8498365855987975
Expected behavior
For MySQL compatibility, numeric JSON scalars should enter the same numeric-conversion path as other numeric-context operands. Ordinary, DISTINCT, grouped/window, prepared-statement, View, and CTAS forms should resolve consistently, including documented NULL and nonnumeric JSON behavior.
Code-path analysis
sumAvgTypeCheck accepts only SumSupportedTypes; mysqlNumericAggTypeCheck used by variance/stddev adds string and temporal coercion but still excludes T_json. MatrixOne already has JSON-to-number CAST execution, as demonstrated by the explicit-cast control, so the missing piece is aggregate overload/type resolution.
Suggested regression coverage
- integer, decimal, exponent, JSON null, SQL NULL, boolean/string/composite JSON;
- SUM/AVG/VAR/STDDEV and aliases, DISTINCT, grouped/window, prepared statements, View/CTAS;
- strict-mode warnings/errors and explicit-cast controls.
Duplicate search
Open and closed issues were searched for JSON numeric aggregation, SUM/AVG/VAR/STDDEV JSON operands, and the binding error. Existing JSON aggregate reports concern JSON_ARRAYAGG/OBJECTAGG, not standard numeric aggregation.
Activity
[Compatibility]: accept JSON operands in numeric aggregates (#28946)
Ariznawlll commentedon Oct 14, 2026
Additional comparison: nonnumeric JSON values and aggregate warnings (2026-10-14)
On the local MatrixOne runtime at
2ce4e58af6f03b943ee288ffad81012766cf830a,SUM(JSON)andAVG(JSON)now bind and execute. For numeric JSON scalars, numeric JSON strings, booleans, JSON null, SQL NULL, and nonnumeric string/object/array values, the returned aggregate values match MySQL 8.0.46 in the compared cases.Under
STRICT_TRANS_TABLES, the nonnumeric JSON string/object/JSON-null rows still produce a result plus six warnings in both engines; neither side escalates these conversions to an error. The diagnostics differ: MySQL reports code 3156 (Invalid JSON value for CAST to DOUBLE from column j), while MO reports codes 1292/1265 (Truncated incorrect DOUBLE value). This appears to be a warning-diagnostic compatibility difference within the existing nonnumeric/strict-mode scope, not a separate aggregate-value mismatch.The aggregate binder source is unchanged in current
origin/maina53390c57de48ac280249ff0e88831e502e20fb0relative to the tested runtime commit; the runtime itself was not rebuilt at that newer SHA.Ariznawlll commentedon Oct 14, 2026
Statistical aggregate follow-up (2026-10-14)
On the same local MatrixOne runtime,
VAR_POP,VAR_SAMP,STDDEV_POP, andSTDDEV_SAMPnow accept numeric JSON scalars and return the same values and DOUBLE protocol metadata as MySQL 8.0.46. For JSON values1,2.5, and3plus SQL NULL, both sides return0.7222222222222223, 1.0833333333333335, 0.8498365855987975, 1.0408329997330665.Under
STRICT_TRANS_TABLES, numeric JSON mixed with JSON string"abc", object, JSON null, and SQL NULL also produces matching statistical values and 12 warnings in both engines. Warning diagnostics differ: MySQL reports code 3156 (Invalid JSON value for CAST to DOUBLE), while MO reports generic numeric-conversion warnings 1292/1265.[-][Compatibility]: numeric aggregate functions reject JSON operands accepted by MySQL[/-][+][Compatibility]: standard aggregates reject JSON operands accepted by MySQL[/+]XuPeng-SH commentedon Oct 23, 2026
Scope consolidation: #28869 is now included here as the MIN/MAX part of standard aggregate JSON-operand compatibility. The existing numeric aggregates (SUM/AVG/VAR/STDDEV) need numeric-context conversion, while MIN/MAX need typed JSON ordering; keep these as separate acceptance suites and do not assume a shared immediate root cause.
Additional repro from #28869:
Expected: MIN/MAX accept JSON and use the engine's typed JSON ordering contract, consistent with ORDER BY/GROUP BY. Preserve separate checks for JSON null, booleans, numbers, strings, SQL NULL, arrays and objects, plus ordinary, grouped and window forms.