CREATE TABLE ${DATABASE_ORDINARY}.dst(count UInt64, market Int32, w_end DateTime)Engine=MergeTree ORDER BY tuple();
CREATE TABLE ${DATABASE_ORDINARY}.mt(a Int32, market Int32, timestamp DateTime)ENGINE=MergeTree ORDER BY tuple();
CREATE WINDOW VIEW ${DATABASE_ORDINARY}.wv TO ${DATABASE_ORDINARY}.dst WATERMARK=ASCENDING AS SELECT count(a) AS count, market, tumbleEnd(wid) AS w_end FROM ${DATABASE_ORDINARY}.mt GROUP BY tumble(timestamp, INTERVAL '5' SECOND, 'US/Samoa') AS wid, market;
INSERT INTO ${DATABASE_ORDINARY}.mt VALUES (1, 1, toDateTime('1990/01/01 12:00:00', 'US/Samoa'));
INSERT INTO ${DATABASE_ORDINARY}.mt VALUES (1, 2, toDateTime('1990/01/01 12:00:01', 'US/Samoa'));
INSERT INTO ${DATABASE_ORDINARY}.mt VALUES (1, 3, toDateTime('1990/01/01 12:00:02', 'US/Samoa'));
INSERT INTO ${DATABASE_ORDINARY}.mt VALUES (1, 4, toDateTime('1990/01/01 12:00:05', 'US/Samoa'));
INSERT INTO ${DATABASE_ORDINARY}.mt VALUES (1, 5, toDateTime('1990/01/01 12:00:06', 'US/Samoa'));
$CLICKHOUSE_CLIENT"${opts[@]}" --query="SELECT market, wid FROM ${DATABASE_ORDINARY}.\`.inner.wv\` ORDER BY market, \`windowID(timestamp, toIntervalSecond('5'), 'US/Samoa')\` as wid";