{
  "comments": [
    "Tests covering use of the GROUP BY clause"
  ],
  "tests": [
    {
      "name": "field (stream->table)",
      "statements": [
        "CREATE STREAM TEST (data VARCHAR) WITH (kafka_topic='test_topic', KEY='data', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT data, COUNT(*) FROM TEST GROUP BY DATA;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "d1", "value": "d1"},
        {"topic": "test_topic", "key": "d2", "value": "d2"},
        {"topic": "test_topic", "key": "d1", "value": "d1"},
        {"topic": "test_topic", "key": "d2", "value": "d2"},
        {"topic": "test_topic", "key": "d1", "value": "d1"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "d1", "value": "d1,1"},
        {"topic": "OUTPUT", "key": "d2", "value": "d2,1"},
        {"topic": "OUTPUT", "key": "d1", "value": "d1,2"},
        {"topic": "OUTPUT", "key": "d2", "value": "d2,2"},
        {"topic": "OUTPUT", "key": "d1", "value": "d1,3"}
      ]
    },
    {
      "name": "fields (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, f2, COUNT(*) FROM TEST GROUP BY f2, f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "1,a"},
        {"topic": "test_topic", "key": 2, "value": "2,b"},
        {"topic": "test_topic", "key": 1, "value": "1,a"},
        {"topic": "test_topic", "key": 2, "value": "2,b"},
        {"topic": "test_topic", "key": 3, "value": "3,a"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a|+|1", "value": "1,a,1"},
        {"topic": "OUTPUT", "key": "b|+|2", "value": "2,b,1"},
        {"topic": "OUTPUT", "key": "a|+|1", "value": "1,a,2"},
        {"topic": "OUTPUT", "key": "b|+|2", "value": "2,b,2"},
        {"topic": "OUTPUT", "key": "a|+|3", "value": "3,a,1"}
      ]
    },
    {
      "name": "with groupings (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 VARCHAR, f3 INT) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, f2, COUNT(*) FROM TEST GROUP BY f3, (f2, f1);"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "1,a,-1"},
        {"topic": "test_topic", "key": 2, "value": "2,b,-2"},
        {"topic": "test_topic", "key": 1, "value": "1,a,-1"},
        {"topic": "test_topic", "key": 2, "value": "2,b,-2"},
        {"topic": "test_topic", "key": 3, "value": "3,a,-3"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "-1|+|a|+|1", "value": "1,a,1"},
        {"topic": "OUTPUT", "key": "-2|+|b|+|2", "value": "2,b,1"},
        {"topic": "OUTPUT", "key": "-1|+|a|+|1", "value": "1,a,2"},
        {"topic": "OUTPUT", "key": "-2|+|b|+|2", "value": "2,b,2"},
        {"topic": "OUTPUT", "key": "-3|+|a|+|3", "value": "3,a,1"}
      ]
    },
    {
      "name": "fields (table->table)",
      "statements": [
        "CREATE TABLE TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, f2, COUNT(*) FROM TEST GROUP BY f2, f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "1,a"},
        {"topic": "test_topic", "key": 2, "value": "2,b"},
        {"topic": "test_topic", "key": 1, "value": "1,b"},
        {"topic": "test_topic", "key": 2, "value": null},
        {"topic": "test_topic", "key": 1, "value": "1,a"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a|+|1", "value": "1,a,1"},
        {"topic": "OUTPUT", "key": "b|+|2", "value": "2,b,1"},
        {"topic": "OUTPUT", "key": "a|+|1", "value": "1,a,0"},
        {"topic": "OUTPUT", "key": "b|+|1", "value": "1,b,1"},
        {"topic": "OUTPUT", "key": "b|+|2", "value": "2,b,0"},
        {"topic": "OUTPUT", "key": "b|+|1", "value": "1,b,0"},
        {"topic": "OUTPUT", "key": "a|+|1", "value": "1,a,1"}
      ]
    },
    {
      "name": "field with re-key (stream->table)",
      "statements": [
        "CREATE STREAM TEST (data VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT data, COUNT(*) FROM TEST GROUP BY DATA;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "d1"},
        {"topic": "test_topic", "value": "d2"},
        {"topic": "test_topic", "value": "d1"},
        {"topic": "test_topic", "value": "d2"},
        {"topic": "test_topic", "value": "d1"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "d1", "value": "d1,1"},
        {"topic": "OUTPUT", "key": "d2", "value": "d2,1"},
        {"topic": "OUTPUT", "key": "d1", "value": "d1,2"},
        {"topic": "OUTPUT", "key": "d2", "value": "d2,2"},
        {"topic": "OUTPUT", "key": "d1", "value": "d1,3"}
      ]
    },
    {
      "name": "field with re-key (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY region;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,r1"},
        {"topic": "test_topic", "key": "3", "value": "3,r0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,r0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "r0", "value": "1"},
        {"topic": "OUTPUT", "key": "r1", "value": "1"},
        {"topic": "OUTPUT", "key": "r0", "value": "2"},
        {"topic": "OUTPUT", "key": "r0", "value": "1"},
        {"topic": "OUTPUT", "key": "r1", "value": "0"},
        {"topic": "OUTPUT", "key": "r0", "value": "2"}
      ]
    },
    {
      "name": "with aggregate arithmetic (stream->table)",
      "statements": [
        "CREATE STREAM TEST (data VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT data, COUNT(*)*2 FROM TEST GROUP BY DATA;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "d1"},
        {"topic": "test_topic", "value": "d2"},
        {"topic": "test_topic", "value": "d1"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "d1", "value": "d1,2"},
        {"topic": "OUTPUT", "key": "d2", "value": "d2,2"},
        {"topic": "OUTPUT", "key": "d1", "value": "d1,4"}
      ]
    },
    {
      "name": "with aggregate arithmetic (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) * 2 FROM TEST GROUP BY region;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,r1"},
        {"topic": "test_topic", "key": "3", "value": "3,r0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,r0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "r0", "value": "2"},
        {"topic": "OUTPUT", "key": "r1", "value": "2"},
        {"topic": "OUTPUT", "key": "r0", "value": "4"},
        {"topic": "OUTPUT", "key": "r0", "value": "2"},
        {"topic": "OUTPUT", "key": "r1", "value": "0"},
        {"topic": "OUTPUT", "key": "r0", "value": "4"}
      ]
    },
    {
      "name": "with aggregate arithmetic involving source field (stream->table)",
      "statements": [
        "CREATE STREAM TEST (ITEM INT, COST INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT ITEM, COST, COST * COUNT() FROM TEST GROUP BY ITEM, COST;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "1,10"},
        {"topic": "test_topic", "value": "1,20"},
        {"topic": "test_topic", "value": "2,30"},
        {"topic": "test_topic", "value": "1,10"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1|+|10", "value": "1,10,10"},
        {"topic": "OUTPUT", "key": "1|+|20", "value": "1,20,20"},
        {"topic": "OUTPUT", "key": "2|+|30", "value": "2,30,30"},
        {"topic": "OUTPUT", "key": "1|+|10", "value": "1,10,20"}
      ]
    },
    {
      "name": "with aggregate arithmetic involving source field (table->table)",
      "statements": [
        "CREATE TABLE TEST (f0 INT, f1 INT) WITH (kafka_topic='test_topic', key='f0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f0 * SUM(f1) FROM TEST GROUP BY f0;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "2", "value": "2,10"},
        {"topic": "test_topic", "key": "2", "value": "2,20"},
        {"topic": "test_topic", "key": "2", "value": "2,30"},
        {"topic": "test_topic", "key": "2", "value": null}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "2", "value": "20"},
        {"topic": "OUTPUT", "key": "2", "value": "0"},
        {"topic": "OUTPUT", "key": "2", "value": "40"},
        {"topic": "OUTPUT", "key": "2", "value": "0"},
        {"topic": "OUTPUT", "key": "2", "value": "60"},
        {"topic": "OUTPUT", "key": "2", "value": "0"}
      ]
    },
    {
      "name": "with aggregate arithmetic involving source field not in group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (f0 INT, f1 INT, f2 INT) WITH (kafka_topic='test_topic', key='f0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1 * SUM(f2) FROM TEST GROUP BY f0;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Field used in aggregate SELECT expression(s) outside of aggregate functions not part of GROUP BY: [TEST.F1]"
      }
    },
    {
      "name": "function (stream->table)",
      "statements": [
        "CREATE STREAM TEST (source VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(source, 0, 2), COUNT(*) FROM TEST GROUP BY SUBSTRING(source, 0, 2);"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "some string"},
        {"topic": "test_topic", "value": "another string"},
        {"topic": "test_topic", "value": "some string again"},
        {"topic": "test_topic", "value": "another string again"},
        {"topic": "test_topic", "value": "some other string"},
        {"topic": "test_topic", "value": "the final string"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "so", "value": "so,1"},
        {"topic": "OUTPUT", "key": "an", "value": "an,1"},
        {"topic": "OUTPUT", "key": "so", "value": "so,2"},
        {"topic": "OUTPUT", "key": "an", "value": "an,2"},
        {"topic": "OUTPUT", "key": "so", "value": "so,3"},
        {"topic": "OUTPUT", "key": "th", "value": "th,1"}
      ]
    },
    {
      "name": "function (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(region, 7, 2), COUNT(*) FROM TEST GROUP BY SUBSTRING(region, 7, 2);"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,prefixr0"},
        {"topic": "test_topic", "key": "2", "value": "2,prefixr1"},
        {"topic": "test_topic", "key": "3", "value": "3,prefixr0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,prefixr0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "r0", "value": "r0,1"},
        {"topic": "OUTPUT", "key": "r1", "value": "r1,1"},
        {"topic": "OUTPUT", "key": "r0", "value": "r0,2"},
        {"topic": "OUTPUT", "key": "r0", "value": "r0,1"},
        {"topic": "OUTPUT", "key": "r1", "value": "r1,0"},
        {"topic": "OUTPUT", "key": "r0", "value": "r0,2"}
      ]
    },
    {
      "name": "function with select field that is a subset of group by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (source VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(source, 0, 1) AS Thing, COUNT(*) FROM TEST GROUP BY SUBSTRING(source, 0, 2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [SUBSTRING(TEST.SOURCE, 0, 1)]"
      }
    },
    {
      "name": "function with select field that is a subset of group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(region, 7, 1), COUNT(*) FROM TEST GROUP BY SUBSTRING(region, 7, 2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [SUBSTRING(TEST.REGION, 7, 1)]"
      }
    },
    {
      "name": "function with select field that is a superset of group by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (source VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(source, 0, 3), COUNT(*) FROM TEST GROUP BY SUBSTRING(source, 0, 2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [SUBSTRING(TEST.SOURCE, 0, 3)]"
      }
    },
    {
      "name": "function with select field that is a superset of group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(region, 7, 3), COUNT(*) FROM TEST GROUP BY SUBSTRING(region, 7, 2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [SUBSTRING(TEST.REGION, 7, 3)]"
      }
    },
    {
      "name": "json field (stream->table)",
      "statements": [
        "CREATE STREAM TEST (data STRUCT<field VARCHAR>) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE TABLE OUTPUT AS SELECT data->field AS FIELD, COUNT(*) AS COUNT FROM TEST GROUP BY data->field;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": {"data": {"field": "Something"}}},
        {"topic": "test_topic", "value": {"data": {"field": "Something Else"}}},
        {"topic": "test_topic", "value": {"data": {}}},
        {"topic": "test_topic", "value": {"data": {"field": "Something"}}},
        {"topic": "test_topic", "value": {"data": {}}}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "Something", "value": {"FIELD": "Something", "COUNT": 1}},
        {"topic": "OUTPUT", "key": "Something Else", "value": {"FIELD": "Something Else", "COUNT": 1}},
        {"topic": "OUTPUT", "key": "null", "value": {"FIELD": null, "COUNT": 1}},
        {"topic": "OUTPUT", "key": "Something", "value": {"FIELD": "Something", "COUNT": 2}},
        {"topic": "OUTPUT", "key": "null", "value": {"FIELD": null, "COUNT": 2}}
      ]
    },
    {
      "name": "ROWKEY (stream->table)",
      "statements": [
        "CREATE STREAM TEST (ignored VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT ROWKEY, COUNT(*) FROM TEST GROUP BY ROWKEY;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "-"},
        {"topic": "test_topic", "key": 2, "value": "-"},
        {"topic": "test_topic", "key": 1, "value": "-"},
        {"topic": "test_topic", "key": 2, "value": "-"},
        {"topic": "test_topic", "key": 1, "value": "-"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1"},
        {"topic": "OUTPUT", "key": "2", "value": "1"},
        {"topic": "OUTPUT", "key": "1", "value": "2"},
        {"topic": "OUTPUT", "key": "2", "value": "2"},
        {"topic": "OUTPUT", "key": "1", "value": "3"}
      ]
    },
    {
      "name": "ROWKEY without ROWKEY in projection (stream->table)",
      "statements": [
        "CREATE STREAM TEST (ignored VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY ROWKEY;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "-"},
        {"topic": "test_topic", "key": 2, "value": "-"},
        {"topic": "test_topic", "key": 1, "value": "-"},
        {"topic": "test_topic", "key": 2, "value": "-"},
        {"topic": "test_topic", "key": 1, "value": "-"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1"},
        {"topic": "OUTPUT", "key": "2", "value": "1"},
        {"topic": "OUTPUT", "key": "1", "value": "2"},
        {"topic": "OUTPUT", "key": "2", "value": "2"},
        {"topic": "OUTPUT", "key": "1", "value": "3"}
      ]
    },
    {
      "name": "constant (stream->table)",
      "statements": [
        "CREATE STREAM TEST (ignored VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY 1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "-"},
        {"topic": "test_topic", "value": "-"},
        {"topic": "test_topic", "value": "-"},
        {"topic": "test_topic", "value": "-"},
        {"topic": "test_topic", "value": "-"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1"},
        {"topic": "OUTPUT", "key": "1", "value": "2"},
        {"topic": "OUTPUT", "key": "1", "value": "3"},
        {"topic": "OUTPUT", "key": "1", "value": "4"},
        {"topic": "OUTPUT", "key": "1", "value": "5"}
      ]
    },
    {
      "name": "constant (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY 1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,r1"},
        {"topic": "test_topic", "key": "3", "value": "3,r0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,r0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1"},
        {"topic": "OUTPUT", "key": "1", "value": "2"},
        {"topic": "OUTPUT", "key": "1", "value": "3"},
        {"topic": "OUTPUT", "key": "1", "value": "2"},
        {"topic": "OUTPUT", "key": "1", "value": "1"},
        {"topic": "OUTPUT", "key": "1", "value": "2"}
      ]
    },
    {
      "name": "field with field used in function in projection (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(f1, 0, 1), COUNT(*) FROM TEST GROUP BY f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "one"},
        {"topic": "test_topic", "value": "two"},
        {"topic": "test_topic", "value": "three"},
        {"topic": "test_topic", "value": "one"},
        {"topic": "test_topic", "value": "five"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "one", "value": "o,1"},
        {"topic": "OUTPUT", "key": "two", "value": "t,1"},
        {"topic": "OUTPUT", "key": "three", "value": "t,1"},
        {"topic": "OUTPUT", "key": "one", "value": "o,2"},
        {"topic": "OUTPUT", "key": "five", "value": "f,1"}
      ]
    },
    {
      "name": "field with field used in function in projection (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(region, 2, 1), COUNT(*) FROM TEST GROUP BY region;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,r1"},
        {"topic": "test_topic", "key": "3", "value": "3,r0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,r0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "r0", "value": "0,1"},
        {"topic": "OUTPUT", "key": "r1", "value": "1,1"},
        {"topic": "OUTPUT", "key": "r0", "value": "0,2"},
        {"topic": "OUTPUT", "key": "r0", "value": "0,1"},
        {"topic": "OUTPUT", "key": "r1", "value": "1,0"},
        {"topic": "OUTPUT", "key": "r0", "value": "0,2"}
      ]
    },
    {
      "name": "string concat using + op (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 VARCHAR, f2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f2 + f1, COUNT(*) FROM TEST GROUP BY f2 + f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "1,a"},
        {"topic": "test_topic", "value": "2,b"},
        {"topic": "test_topic", "value": "1,a"},
        {"topic": "test_topic", "value": "2,b"},
        {"topic": "test_topic", "value": "3,a"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a1", "value": "a1,1"},
        {"topic": "OUTPUT", "key": "b2", "value": "b2,1"},
        {"topic": "OUTPUT", "key": "a1", "value": "a1,2"},
        {"topic": "OUTPUT", "key": "b2", "value": "b2,2"},
        {"topic": "OUTPUT", "key": "a3", "value": "a3,1"}
      ]
    },
    {
      "name": "string concat using + op (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, subregion VARCHAR, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY region + subregion;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,a,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,a,r1"},
        {"topic": "test_topic", "key": "3", "value": "3,a,r0"},
        {"topic": "test_topic", "key": "4", "value": "4,b,r0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,a,r0"},
        {"topic": "test_topic", "key": "2", "value": "2,b,r1"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "r0a", "value": "1"},
        {"topic": "OUTPUT", "key": "r1a", "value": "1"},
        {"topic": "OUTPUT", "key": "r0a", "value": "2"},
        {"topic": "OUTPUT", "key": "r0b", "value": "1"},
        {"topic": "OUTPUT", "key": "r0a", "value": "1"},
        {"topic": "OUTPUT", "key": "r1a", "value": "0"},
        {"topic": "OUTPUT", "key": "r0a", "value": "2"},
        {"topic": "OUTPUT", "key": "r0a", "value": "1"},
        {"topic": "OUTPUT", "key": "r1b", "value": "1"}
      ]
    },
    {
      "name": "string concat using + op with projection field in wrong order (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 VARCHAR, f2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1 + f2, COUNT(*) FROM TEST GROUP BY f2 + f1;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [(TEST.F1 + TEST.F2)]"
      }
    },
    {
      "name": "string concat using + op with projection field in wrong order (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, subregion VARCHAR, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT subregion + region, COUNT(*) FROM TEST GROUP BY region + subregion;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [(TEST.SUBREGION + TEST.REGION)]"
      }
    },
    {
      "name": "string concat with separate fields in projection (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 VARCHAR, f2 VARCHAR) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, f2, COUNT(*) FROM TEST GROUP BY f2 + f1;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [TEST.F1, TEST.F2]"
      }
    },
    {
      "name": "string concat with separate fields in projection (table->table)",
      "statements": [
        "CREATE TABLE TEST (user INT, subregion VARCHAR, region VARCHAR) WITH (kafka_topic='test_topic', KEY='user', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT subregion, region, COUNT(*) FROM TEST GROUP BY region + subregion;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [TEST.SUBREGION, TEST.REGION]"
      }
    },
    {
      "name": "arithmetic binary expression with projection in-order & non-commutative group by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f2 - f1, COUNT(*) FROM TEST GROUP BY f2 - f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "1,2"},
        {"topic": "test_topic", "value": "2,3"},
        {"topic": "test_topic", "value": "2,4"},
        {"topic": "test_topic", "value": "6,8"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,2"},
        {"topic": "OUTPUT", "key": "2", "value": "2,1"},
        {"topic": "OUTPUT", "key": "2", "value": "2,2"}
      ]
    },
    {
      "name": "arithmetic binary expression with projection in-order & non-commutative group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (f0 INT, f1 INT) WITH (kafka_topic='test_topic', KEY='f0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f0 - f1, COUNT(*) FROM TEST GROUP BY f0 - f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,0"},
        {"topic": "test_topic", "key": "2", "value": "2,1"},
        {"topic": "test_topic", "key": "3", "value": "3,1"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "4,2"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,2"},
        {"topic": "OUTPUT", "key": "2", "value": "2,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,0"},
        {"topic": "OUTPUT", "key": "2", "value": "2,2"}
      ]
    },
    {
      "name": "arithmetic binary expression with projection out-of-order & non-commutative group by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1 - f2, COUNT(*) FROM TEST GROUP BY f2 - f1;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [(TEST.F1 - TEST.F2)]"
      }
    },
    {
      "name": "arithmetic binary expression with projection out-of-order & non-commutative group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (f0 INT, f1 INT) WITH (kafka_topic='test_topic', KEY='f0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1 - f0, COUNT(*) FROM TEST GROUP BY f0 - f1;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [(TEST.F1 - TEST.F0)]"
      }
    },
    {
      "name": "with having expression (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, COUNT(*) FROM TEST GROUP BY f1 HAVING SUM(f1) > 1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1"},
        {"topic": "test_topic", "key": "2", "value": "2"},
        {"topic": "test_topic", "key": "1", "value": "1"},
        {"topic": "test_topic", "key": "2", "value": "2"},
        {"topic": "test_topic", "key": "3", "value": "3"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": null},
        {"topic": "OUTPUT", "key": "2", "value": "2,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,2"},
        {"topic": "OUTPUT", "key": "2", "value": "2,2"},
        {"topic": "OUTPUT", "key": "3", "value": "3,1"}
      ]
    },
    {
      "name": "with having expression (table->table)",
      "statements": [
        "CREATE TABLE TEST (f0 INT, f1 INT) WITH (kafka_topic='test_topic', KEY='f0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, SUM(f0) FROM TEST GROUP BY f1 HAVING COUNT(f1) > 0;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "1", "value": "1,0"},
        {"topic": "test_topic", "key": "2", "value": "2,1"},
        {"topic": "test_topic", "key": "3", "value": "3,0"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,0"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "0", "value": "0,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,2"},
        {"topic": "OUTPUT", "key": "0", "value": "0,4"},
        {"topic": "OUTPUT", "key": "0", "value": "0,3"},
        {"topic": "OUTPUT", "key": "1", "value": null},
        {"topic": "OUTPUT", "key": "0", "value": "0,5"}
      ]
    },
    {
      "name": "with multiple having expressions (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, COUNT(f1) FROM TEST GROUP BY f1 HAVING COUNT(f1) > 1 AND f1=1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": "1,a"},
        {"topic": "test_topic", "key": 0, "value": "2,b"},
        {"topic": "test_topic", "key": 0, "value": "1,test"},
        {"topic": "test_topic", "key": 0, "value": "2,test"},
        {"topic": "test_topic", "key": 0, "value": "2,test"},
        {"topic": "test_topic", "key": 0, "value": "1,test"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": null},
        {"topic": "OUTPUT", "key": "2", "value": null},
        {"topic": "OUTPUT", "key": "1", "value": "1,2"},
        {"topic": "OUTPUT", "key": "2", "value": null},
        {"topic": "OUTPUT", "key": "2", "value": null},
        {"topic": "OUTPUT", "key": "1", "value": "1,3"}
      ]
    },
    {
      "name": "with having expression on non-group-by field (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f2, COUNT(*) FROM TEST GROUP BY f2 HAVING SUM(f1) > 10;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "-", "value": "5,a"},
        {"topic": "test_topic", "key": "-", "value": "10,b"},
        {"topic": "test_topic", "key": "-", "value": "6,a"},
        {"topic": "test_topic", "key": "-", "value": "1,b"},
        {"topic": "test_topic", "key": "-", "value": "-1,a"},
        {"topic": "test_topic", "key": "-", "value": "1,a"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a", "value": null},
        {"topic": "OUTPUT", "key": "b", "value": null},
        {"topic": "OUTPUT", "key": "a", "value": "a,2"},
        {"topic": "OUTPUT", "key": "b", "value": "b,2"},
        {"topic": "OUTPUT", "key": "a", "value": null},
        {"topic": "OUTPUT", "key": "a", "value": "a,4"}
      ]
    },
    {
      "name": "with constant having (stream-table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f2, SUM(f1) FROM TEST GROUP BY f2 HAVING f2='test';"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": "1,a"},
        {"topic": "test_topic", "key": 0, "value": "2,b"},
        {"topic": "test_topic", "key": 0, "value": "2,test"},
        {"topic": "test_topic", "key": 0, "value": "2,b"},
        {"topic": "test_topic", "key": 0, "value": "3,test"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a", "value": null},
        {"topic": "OUTPUT", "key": "b", "value": null},
        {"topic": "OUTPUT", "key": "test", "value": "test,2"},
        {"topic": "OUTPUT", "key": "b", "value": null},
        {"topic": "OUTPUT", "key": "test", "value": "test,5"}
      ]
    },
    {
      "name": "with constants in the projection (stream->table)",
      "statements": [
        "CREATE STREAM TEST (f1 INT) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT f1, 'some constant' as f3, COUNT(f1) FROM TEST GROUP BY f1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "1"},
        {"topic": "test_topic", "key": 2, "value": "2"},
        {"topic": "test_topic", "key": 1, "value": "1"},
        {"topic": "test_topic", "key": 2, "value": "2"},
        {"topic": "test_topic", "key": 3, "value": "3"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "1", "value": "1,some constant,1"},
        {"topic": "OUTPUT", "key": "2", "value": "2,some constant,1"},
        {"topic": "OUTPUT", "key": "1", "value": "1,some constant,2"},
        {"topic": "OUTPUT", "key": "2", "value": "2,some constant,2"},
        {"topic": "OUTPUT", "key": "3", "value": "3,some constant,1"}
      ]
    },
    {
      "name": "missing matching projection field (stream->table)",
      "statements": [
        "CREATE STREAM TEST (data VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY data;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "d1"},
        {"topic": "test_topic", "value": "d2"},
        {"topic": "test_topic", "value": "d1"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "d1", "value": "1"},
        {"topic": "OUTPUT", "key": "d2", "value": "1"},
        {"topic": "OUTPUT", "key": "d1", "value": "2"}
      ]
    },
    {
      "name": "missing matching projection field (table->table)",
      "statements": [
        "CREATE TABLE TEST (f1 INT, f2 VARCHAR) WITH (kafka_topic='test_topic', KEY='f1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY f2;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": "1,a"},
        {"topic": "test_topic", "key": 2, "value": "2,b"},
        {"topic": "test_topic", "key": 1, "value": "1,b"},
        {"topic": "test_topic", "key": 2, "value": null},
        {"topic": "test_topic", "key": 1, "value": "1,a"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "a", "value": "1"},
        {"topic": "OUTPUT", "key": "b", "value": "1"},
        {"topic": "OUTPUT", "key": "a", "value": "0"},
        {"topic": "OUTPUT", "key": "b", "value": "2"},
        {"topic": "OUTPUT", "key": "b", "value": "1"},
        {"topic": "OUTPUT", "key": "b", "value": "0"},
        {"topic": "OUTPUT", "key": "a", "value": "1"}
      ]
    },
    {
      "name": "with non-aggregate projection field not in group by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT d1, COUNT(*) FROM TEST GROUP BY d2;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [TEST.D1]"
      }
    },
    {
      "name": "with non-aggregate projection field not in group by (table->table)",
      "statements": [
        "CREATE TABLE TEST (d1 VARCHAR, d2 VARCHAR) WITH (kafka_topic='test_topic', key='d1', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT d1, COUNT(*) FROM TEST GROUP BY d2;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Non-aggregate SELECT expression(s) not part of GROUP BY: [TEST.D1]"
      }
    },
    {
      "name": "aggregate function (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY SUM(d2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "GROUP BY does not support aggregate functions: SUM is an aggregate function."
      }
    },
    {
      "name": "aggregate function nested in arithmetic (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY 1 + SUM(d2);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "GROUP BY does not support aggregate functions: SUM is an aggregate function."
      }
    },
    {
      "name": "aggregate function nested in UDF (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT COUNT(*) FROM TEST GROUP BY SUBSTRING(d1, SUM(d2), 1);"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "GROUP BY does not support aggregate functions: SUM is an aggregate function."
      }
    },
    {
      "name": "with projection without aggregate functions (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING(d2, 1, 2) FROM TEST GROUP BY d2;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "GROUP BY requires columns using aggregate functions in SELECT clause."
      }
    },
    {
      "name": "without group-by (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR, d2 INT) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT d1, COUNT() FROM TEST;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Use of aggregate functions requires a GROUP BY clause. Aggregate function(s): COUNT"
      }
    },
    {
      "name": "UDAF nested in UDF in select expression (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING('Mr Bugalicious', CAST(COUNT(*) AS INT), 1) FROM TEST GROUP BY d1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "x"},
        {"topic": "test_topic", "value": "xxx"},
        {"topic": "test_topic", "value": "y"},
        {"topic": "test_topic", "value": "x"},
        {"topic": "test_topic", "value": "xxx"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "x", "value": "M"},
        {"topic": "OUTPUT", "key": "xxx", "value": "M"},
        {"topic": "OUTPUT", "key": "y", "value": "M"},
        {"topic": "OUTPUT", "key": "x", "value": "r"},
        {"topic": "OUTPUT", "key": "xxx", "value": "r"}
      ]
    },
    {
      "name": "UDAF nested in UDF in select expression (table->table)",
      "statements": [
        "CREATE TABLE TEST (d0 INT, d1 VARCHAR) WITH (kafka_topic='test_topic', key='d0', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUBSTRING('Mr Bugalicious', CAST(COUNT(*) AS INT), 1) FROM TEST GROUP BY d1;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": "0", "value": "0,x"},
        {"topic": "test_topic", "key": "1", "value": "1,x"},
        {"topic": "test_topic", "key": "2", "value": "2,xxx"},
        {"topic": "test_topic", "key": "3", "value": "3,xxx"},
        {"topic": "test_topic", "key": "1", "value": null},
        {"topic": "test_topic", "key": "2", "value": "2,yy"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "x", "value": "M"},
        {"topic": "OUTPUT", "key": "x", "value": "r"},
        {"topic": "OUTPUT", "key": "xxx", "value": "M"},
        {"topic": "OUTPUT", "key": "xxx", "value": "r"},
        {"topic": "OUTPUT", "key": "x", "value": "M"},
        {"topic": "OUTPUT", "key": "xxx", "value": "M"},
        {"topic": "OUTPUT", "key": "yy", "value": "M"}
      ]
    },
    {
      "name": "UDF nested in UDAF in select expression (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUM(LEN(d1)) FROM TEST GROUP BY d1;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": "x"},
        {"topic": "test_topic", "value": "xxx"},
        {"topic": "test_topic", "value": "y"},
        {"topic": "test_topic", "value": "x"},
        {"topic": "test_topic", "value": "xxx"}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": "x", "value": "1"},
        {"topic": "OUTPUT", "key": "xxx", "value": "3"},
        {"topic": "OUTPUT", "key": "y", "value": "1"},
        {"topic": "OUTPUT", "key": "x", "value": "2"},
        {"topic": "OUTPUT", "key": "xxx", "value": "6"}
      ]
    },
    {
      "name": "UDAF nested in UDAF in select expression (stream->table)",
      "statements": [
        "CREATE STREAM TEST (d1 VARCHAR) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
        "CREATE TABLE OUTPUT AS SELECT SUM(COUNT()) FROM TEST GROUP BY d1;"
      ],
      "expectedException": {
        "type": "io.confluent.ksql.util.KsqlStatementException",
        "message": "Aggregate functions can not be nested: SUM(COUNT())"
      }
    }
  ]
}