matrixorigin / matrixorigin/matrixone

[Compatibility]: MIN and MAX reject JSON operands accepted by MySQL

Open
#28,869 0 comments 0 reactions 1 assignee Claimed by @VioletQwQ-0 View on GitHub
area/compatibility kind/bug severity/s1
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## Description

MatrixOne rejects JSON operands for `MIN` and `MAX`, while MySQL defines these aggregates for JSON values using JSON comparison/ordering semantics.

## Environment

- MatrixOne: latest official `main`, commit `07fdd4ae0f80f287b93fc4b525fd296d5617abc7`
- 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

```sql
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;
```

## MatrixOne behavior

```text
invalid argument aggregate function min, bad value [JSON]
```

`MAX` and the window forms are rejected by the same type check. The behavior reproduced in 3/3 fresh runs.

## Controls

- `ORDER BY j` and `GROUP BY j` already execute through typed JSON comparison/key paths;
- `GROUP_CONCAT(j ORDER BY id)` accepts the same JSON column;
- explicit string casting allows MIN/MAX to execute, although string order is only a control and is not a replacement for typed JSON order.

## Expected behavior

`MIN(JSON)` and `MAX(JSON)` should be accepted and use the same JSON value ordering contract as the engine's typed JSON comparison/sort implementation. Ordinary, grouped/window, View, and CTAS paths should resolve consistently.

## Code-path analysis

`MinMaxSupportedTypes` in `pkg/sql/plan/function/list_agg.go` excludes `types.T_json`, although JSON is already supported by key comparison and canonical grouping code. The failure occurs before the executor can apply an ordering rule.

## Suggested regression coverage

- JSON null, boolean, number, string, SQL NULL, arrays, and objects;
- ordinary/grouped/window MIN/MAX, DOP 1/>1, partial/final, spill, View, and CTAS;
- consistency with `ORDER BY` and documented behavior for nonscalar values.

## Duplicate search

Open and closed issues were searched for JSON MIN/MAX, JSON standard aggregates, JSON ordering, and `[JSON]` binding errors; no matching report was found.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.