Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-32456

JSON_OBJECTAGG & JSON_ARRAYAGG cannot be used with other aggregate functions

    XMLWordPrintableJSON

Details

    Description

      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.,

      SELECT f0, count(f1), sum(f2), JSON_OBJECTAGG(f1 VALUE f0) FROM T GROUP BY f0
      

      will raise an internal AssertionError

      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]])
      

      because the implementation rule only supports single json agg function

      an example case runnning on postgresql:

      select b, json_object_agg(a, c), count(*), sum(a) from t1 group by b;
      

      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

      Attachments

        1. image-2023-06-28-11-32-49-862.png
          1008 kB
          lincoln lee

        Activity

          People

            lincoln.86xy lincoln lee
            lincoln.86xy lincoln lee
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: