{
  "comments": [
    "Tests covering the use of the EXTRACTJSONFIELD function"
  ],
  "tests": [
    {
      "name": "concat two extracted fields",
      "statements": [
        "CREATE STREAM TEST (source VARCHAR) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT EXTRACTJSONFIELD(source, '$.name') AS SOURCE, EXTRACTJSONFIELD(source, '$.version') AS VERSION, CONCAT(EXTRACTJSONFIELD(source, '$.name'), EXTRACTJSONFIELD(source, '$.version')) AS BOTH FROM TEST;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": {"source": "{\"name\": \"cdc\", \"version\": \"1\"}"}},
        {"topic": "test_topic", "value": {"source": "{\"name\": \"cdd\", \"version\": \"2\"}"}}
      ],
      "outputs": [
        {"topic": "OUTPUT", "value": {"SOURCE":"cdc","VERSION":"1","BOTH":"cdc1"}},
        {"topic": "OUTPUT", "value": {"SOURCE":"cdd","VERSION":"2","BOTH":"cdd2"}}
      ]
    },
    {
      "name": "extract JSON array field",
      "statements": [
        "CREATE STREAM TEST (array_field ARRAY<VARCHAR>) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT EXTRACTJSONFIELD(array_field[0], '$.nested') AS Col1, EXTRACTJSONFIELD(array_field[1], '$.nested') AS Col2 FROM TEST;"
      ],
      "inputs": [
        {"topic": "test_topic", "value": {"array_field": ["{\"nested\": \"nest0\"}","{\"nested\": \"nest1\"}"]}},
        {"topic": "test_topic", "value": {"array_field": ["{\"nested\": \"nest0\"}"]}},
        {"topic": "test_topic", "value": {"no": "match"}}
      ],
      "outputs": [
        {"topic": "OUTPUT", "value": {"COL1":"nest0","COL2":"nest1"}},
        {"topic": "OUTPUT", "value": {"COL1":"nest0","COL2":null}},
        {"topic": "OUTPUT", "value": {"COL1":null,"COL2":null}}
      ]
    }
  ]
}