Skip to content

[Compatibility]: standard aggregates reject JSON operands accepted by MySQL #28868

Open

Description

@Ariznawlll

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

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

  1. added this to the MO-202609 milestone on Sep 14, 2026
  2. added theissue type on Sep 14, 2026
  3. added
    severity/s1
    and removed on Sep 15, 2026
  4. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    Additional comparison: nonnumeric JSON values and aggregate warnings (2026-10-14)

    On the local MatrixOne runtime at 2ce4e58af6f03b943ee288ffad81012766cf830a, SUM(JSON) and AVG(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/main a53390c57de48ac280249ff0e88831e502e20fb0 relative to the tested runtime commit; the runtime itself was not rebuilt at that newer SHA.

  5. Ariznawlll commented on Oct 14, 2026

    @Ariznawlll
    CollaboratorAuthor

    Statistical aggregate follow-up (2026-10-14)

    On the same local MatrixOne runtime, VAR_POP, VAR_SAMP, STDDEV_POP, and STDDEV_SAMP now accept numeric JSON scalars and return the same values and DOUBLE protocol metadata as MySQL 8.0.46. For JSON values 1, 2.5, and 3 plus SQL NULL, both sides return 0.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.

  6. changed the title [-][Compatibility]: numeric aggregate functions reject JSON operands accepted by MySQL[/-] [+][Compatibility]: standard aggregates reject JSON operands accepted by MySQL[/+] on Oct 23, 2026
  7. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    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:

    create table t(id int, j json);
    insert into t values (1,'null'),(2,'false'),(3,'true'),(4,'1'),(5,'"a"'),(6,null);
    select min(j), max(j) from t;
    select id, min(j) over(order by id rows unbounded preceding) from t order by id;

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bugseverity/s1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions