{
  "comments": [
    "Tests covering the use of the BETWEEN function"
  ],
  "tests": [
    {
      "name": "test BETWEEN with integers",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source int) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN 2 AND 4;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": 1}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 3}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": 5}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": 2}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": 3}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": 4}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with bigint",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source bigint) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN 2 AND 4;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": 1}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 3}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": 5}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": 2}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": 3}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": 4}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with floating point",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source double) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN 2 AND 3.9;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": 1.9}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2.0}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 2.1}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 3.9}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": 4.0}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": 2.0}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": 2.1}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": 3.9}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with string values",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source string) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN 'b' AND 'c';"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": "a"}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": "b"}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": "ba"}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": "c"}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": "ca"}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": "b"}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": "ba"}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": "c"}, "timestamp": 0}
      ]
    },
    {
      "name": "test NOT BETWEEN with integers",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source int) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source NOT BETWEEN 2 AND 4;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": {"source": 1}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 3}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": 5}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 1, "value": {"THING": 1}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 5, "value": {"THING": 5}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with integers and variable values",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source int, min int, max int) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN min AND max;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null, "min":  0, "max": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": 1, "min":  0, "max": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2, "min":  null, "max": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 3, "min":  0, "max": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4, "min":  null, "max": null}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 1, "value": {"THING": 1}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with integers and expressions",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source int, avg int) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source + 2 BETWEEN avg / 2 AND avg * 2;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": {"source": null, "avg":  10}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 1, "avg":  10}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 10, "avg":  10}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4, "avg":  10}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 3, "value": {"THING": 10}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": 4}, "timestamp": 0}
      ]
    },
    {
      "name": "test NOT BETWEEN with integers",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source int) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source NOT BETWEEN 2 AND 4;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": {"source": 1}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": 2}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": 3}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": 4}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": 5}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 1, "value": {"THING": 1}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 5, "value": {"THING": 5}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with array dereference",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source array<int>) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source[1] AS THING FROM TEST WHERE source[1] BETWEEN 2 AND 4;"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 1, "value": {"source": [10,1]}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": [10,2]}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": [10,3]}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": [10,4]}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": [10,5]}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": 2}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": 3}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": 4}, "timestamp": 0}
      ]
    },
    {
      "name": "test BETWEEN with string values",
      "format": ["JSON"],
      "statements": [
        "CREATE STREAM TEST (source string) WITH (kafka_topic='test_topic', value_format='JSON');",
        "CREATE STREAM OUTPUT AS SELECT source AS THING FROM TEST WHERE source BETWEEN SUBSTRING('zb',2) AND 'c';"
      ],
      "inputs": [
        {"topic": "test_topic", "key": 0, "value": {"source": null}, "timestamp": 0},
        {"topic": "test_topic", "key": 1, "value": {"source": "a"}, "timestamp": 0},
        {"topic": "test_topic", "key": 2, "value": {"source": "b"}, "timestamp": 0},
        {"topic": "test_topic", "key": 3, "value": {"source": "ba"}, "timestamp": 0},
        {"topic": "test_topic", "key": 4, "value": {"source": "c"}, "timestamp": 0},
        {"topic": "test_topic", "key": 5, "value": {"source": "ca"}, "timestamp": 0}
      ],
      "outputs": [
        {"topic": "OUTPUT", "key": 2, "value": {"THING": "b"}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 3, "value": {"THING": "ba"}, "timestamp": 0},
        {"topic": "OUTPUT", "key": 4, "value": {"THING": "c"}, "timestamp": 0}
      ]
    }
  ]
}