{
  "comments": [
    "You can specify multiple statements per test case, i.e., to set up the various streams needed",
    "for joins etc, but currently only the final topology will be verified. This should be enough",
    "for most tests as we can simulate the outputs from previous stages into the final stage. If we",
    "take a modular approach to testing we can still verify that it all works correctly, i.e, if we",
    "verify the output of a select or aggregate is correct, we can use simulated output to feed into",
    "a join or another aggregate."
  ],
  "tests": [
    {
      "name": "collect_list int",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE STREAM TEST (ID bigint, VALUE integer) WITH (kafka_topic='test_topic',value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 0}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 100}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [0]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [0,100]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500,100]}}
      ]
    },
    {
      "name": "collect_list long",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE STREAM TEST (ID bigint, VALUE bigint) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 2147483648}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 100}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [2147483648]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [2147483648,100]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500,100]}}
      ]
    },
    {
      "name": "collect_list double",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE STREAM TEST (ID bigint, VALUE double) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 5.4}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100.1}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500.9}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 300.8}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [5.4]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [5.4,100.1]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500.9]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500.9,300.8]}}
      ]
    },
    {
      "name": "collect_list string",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE STREAM TEST (ID bigint, VALUE varchar) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": "foo"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "baz"}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": "bar"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "baz"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "foo"}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": ["foo"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["baz"]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": ["foo","bar"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["baz","baz"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["baz","baz","foo"]}}
      ]
    },
    {
      "name": "collect_list bool map",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (ID bigint, NAME varchar, VALUE map<varchar, boolean>) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value['key1']) AS collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":true, "key2":false}}},
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":false, "key2":true}}},
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":true, "key2":true}}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[true]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[true,false]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[true,false,true]}}
      ]
    },
    {
      "name": "collect_list int table",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE TABLE TEST (ID bigint, VALUE integer) WITH (kafka_topic='test_topic',value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 0}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 100}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [0]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": []}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [100]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": []}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [100]}}
      ]
    },
    {
      "name": "collect_list long table",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE TABLE TEST (ID bigint, VALUE bigint) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 2147483648}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 100}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [2147483648]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": []}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [100]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": []}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [100]}}
      ]
    },
    {
      "name": "collect_list double table",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE TABLE TEST (ID bigint, VALUE double) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 5.4}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": 100.1}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 500.9}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": 300.8}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [5.4]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": []}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": [100.1]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [500.9]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": []}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": [300.8]}}
      ]
    },
    {
      "name": "collect_list string table",
      "format": ["AVRO", "JSON"],
      "statements": [
        "CREATE TABLE TEST (ID bigint, VALUE varchar) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value) as collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": "foo"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "baz"}},
        {"topic": "test_topic", "key": 0, "value": {"ID": 0, "VALUE": "bar"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "baz"}},
        {"topic": "test_topic", "key": 100, "value": {"ID": 100, "VALUE": "foo"}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": ["foo"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["baz"]}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": []}},
        {"topic": "S2", "key": 0, "value": {"ID": 0, "COLLECTED": ["bar"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": []}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["baz"]}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": []}},
        {"topic": "S2", "key": 100, "value": {"ID": 100, "COLLECTED": ["foo"]}}
      ]
    },
    {
      "name": "collect_list bool map table",
      "format": ["JSON"],
      "statements": [
        "CREATE TABLE TEST (ID bigint, NAME varchar, VALUE map<varchar, boolean>) WITH (kafka_topic='test_topic', value_format='{FORMAT}', key='ID');",
        "CREATE TABLE S2 as SELECT id, collect_list(value['key1']) AS collected FROM test group by id;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":true, "key2":false}}},
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":false, "key2":true}}},
        {"topic": "test_topic", "key": 0, "value": {"id": 0, "name": "zero", "value": {"key1":true, "key2":true}}}
      ],
      "outputs": [
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[true]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[false]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[]}},
        {"topic": "S2", "key": 0, "value": {"ID":0,"COLLECTED":[true]}}
      ]
    }
  ]
}