2020-10-02 16:54:07 +00:00
#!/usr/bin/env python3
2018-06-04 14:10:54 +00:00
2023-03-23 15:33:23 +00:00
2018-06-04 14:10:54 +00:00
def gen_queries():
2023-03-23 15:33:23 +00:00
create_template = "create table tab_00386 (a Int8, b String, c Tuple(Int8), d Tuple(Tuple(Int8)), e Tuple(Int8, String), f Tuple(Tuple(Int8, String))) engine = MergeTree order by ({}) partition by {}"
drop_query = "drop table if exists tab_00386"
values = ("1", "'a'", "tuple(1)", "tuple(tuple(1))", "(1, 'a')", "tuple((1, 'a'))")
2019-04-18 18:48:04 +00:00
insert_query = "insert into tab_00386 values (1, 'a', tuple(1), tuple(tuple(1)), (1, 'a'), tuple((1, 'a')))"
2023-03-23 15:33:23 +00:00
columns = tuple("a b c d".split())
order_by_columns = tuple("a b c".split())
partition_by_columns = tuple(" tuple() a".split())
2019-07-21 21:35:43 +00:00
2018-06-04 14:10:54 +00:00
for partition in partition_by_columns:
for key_mask in range(1, 1 << len(order_by_columns)):
2023-03-23 15:33:23 +00:00
key = ",".join(
order_by_columns[i]
for i in range(len(order_by_columns))
if (1 << i) & key_mask != 0
)
2018-06-04 14:10:54 +00:00
create_query = create_template.format(key, partition)
for q in (drop_query, create_query, insert_query):
yield q
2019-07-21 21:35:43 +00:00
2018-06-04 14:10:54 +00:00
for column, value in zip(columns, values):
2023-03-23 15:33:23 +00:00
yield "select {} in {} from tab_00386".format(column, value)
yield "select {} in tuple({}) from tab_00386".format(column, value)
yield "select {} in (select {} from tab_00386) from tab_00386".format(
column, column
)
2018-06-04 14:10:54 +00:00
for i in range(len(columns)):
for j in range(i, len(columns)):
2023-03-23 15:33:23 +00:00
yield "select ({}, {}) in tuple({}, {}) from tab_00386".format(
columns[i], columns[j], values[i], values[j]
)
yield "select ({}, {}) in (select {}, {} from tab_00386) from tab_00386".format(
columns[i], columns[j], columns[i], columns[j]
)
yield "select ({}, {}) in (select ({}, {}) from tab_00386) from tab_00386".format(
columns[i], columns[j], columns[i], columns[j]
)
2019-07-21 21:35:43 +00:00
2019-04-18 18:48:04 +00:00
yield "select e in (1, 'a') from tab_00386"
yield "select f in tuple((1, 'a')) from tab_00386"
yield "select f in tuple(tuple((1, 'a'))) from tab_00386"
2018-06-04 14:10:54 +00:00
2023-03-23 15:33:23 +00:00
yield "select e in (select a, b from tab_00386) from tab_00386"
yield "select e in (select (a, b) from tab_00386) from tab_00386"
yield "select f in (select tuple((a, b)) from tab_00386) from tab_00386"
yield "select tuple(f) in (select tuple(tuple((a, b))) from tab_00386) from tab_00386"
2018-06-04 14:10:54 +00:00
import requests
import os
2023-03-23 15:33:23 +00:00
2018-06-04 14:10:54 +00:00
def main():
2023-03-23 15:33:23 +00:00
url = os.environ["CLICKHOUSE_URL"]
2019-07-21 21:35:43 +00:00
2018-06-04 14:10:54 +00:00
for q in gen_queries():
resp = requests.post(url, data=q)
2023-03-23 15:33:23 +00:00
if resp.status_code != 200 or resp.text.strip() not in ("1", ""):
print("Query:", q)
print("Code:", resp.status_code)
2020-10-02 16:54:07 +00:00
print(resp.text)
2018-06-04 14:10:54 +00:00
break
2023-03-23 15:33:23 +00:00
requests.post(url, data="drop table tab_00386")
2020-11-11 15:29:36 +00:00
2018-06-04 14:10:54 +00:00
if __name__ == "__main__":
main()