lincoln lee created FLINK-32456: ----------------------------------- Summary: JSON_OBJECTAGG & JSON_ARRAYAGG cannot be used with other aggregate functions Key: FLINK-32456 URL: https://issues.apache.org/jira/browse/FLINK-32456 Project: Flink Issue Type: Bug Components: Table SQL / API Affects Versions: 1.17.1, 1.16.2, 1.15.4 Reporter: lincoln lee Assignee: lincoln lee Attachments: image-2023-06-28-11-32-49-862.png
FLINK-16205 & FLINK-16206 added the support for the new aggregate functions: JSON_OBJECTAGG & JSON_ARRAYAGG, but has a limitation (which is not documented yet) that cannot be used with other aggregate functions, e.g., {code} SELECT f0, count(f1), sum(f2), JSON_OBJECTAGG(f1 VALUE f0) FROM T GROUP BY f0 {code} will raise an internal AssertionError {code} java.lang.AssertionError: Cannot add expression of different type to set: set type is RecordType(INTEGER f0, BIGINT NOT NULL EXPR$1, INTEGER EXPR$2, VARCHAR(2000) CHARACTER SET "UTF-16LE" NOT NULL EXPR$3) NOT NULL expression type is RecordType(INTEGER f0, BIGINT NOT NULL EXPR$1) NOT NULL set is rel#25:LogicalAggregate.NONE.any.None: 0.[NONE].[NONE](input=HepRelVertex#24,group={0},EXPR$1=COUNT($1),EXPR$2=SUM($2),EXPR$3=JSON_OBJECTAGG_NULL_ON_NULL($1, $0)) expression is LogicalAggregate(group=[{0}], EXPR$1=[COUNT($3)]) LogicalProject(f0=[$0], f1=[$1], f2=[$2], $f3=[JSON_STRING($1)]) LogicalTableScan(table=[[default_catalog, default_database, T]]) {code} because the implementation rule only supports single json agg function an example case runnning on postgresql: {code} select b, json_object_agg(a, c), count(*), sum(a) from t1 group by b; {code} !image-2023-06-28-11-32-49-862.png! The following improvements include two parts: 1. update current documentation to clarify the limitation 2. expand the implementation to support mixed use with other aggregate functions -- This message was sent by Atlassian Jira (v8.20.10#820010)