tinybird-toolset 2.7.3__tar.gz → 2.8.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {tinybird_toolset-2.7.3/src/tinybird_toolset.egg-info → tinybird_toolset-2.8.0}/PKG-INFO +1 -1
  2. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/conf.py +0 -3
  3. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/setup.py +1 -1
  4. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0/src/tinybird_toolset.egg-info}/PKG-INFO +1 -1
  5. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_check_write_query.py +81 -0
  6. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_replace_tables.py +63 -13
  7. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_rewrite_aggregation_states.py +7 -1
  8. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_tables.py +10 -13
  9. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/LICENSE +0 -0
  10. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/MANIFEST.in +0 -0
  11. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/README.md +0 -0
  12. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/setup.cfg +0 -0
  13. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/chtoolset/__init__.py +0 -0
  14. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/chtoolset/query.py +0 -0
  15. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/tinybird_toolset.egg-info/SOURCES.txt +0 -0
  16. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/tinybird_toolset.egg-info/dependency_links.txt +0 -0
  17. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/tinybird_toolset.egg-info/requires.txt +0 -0
  18. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/src/tinybird_toolset.egg-info/top_level.txt +0 -0
  19. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_check_compatible_types.py +0 -0
  20. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_check_ttl_partition_compatibility.py +0 -0
  21. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_chquery.py +0 -0
  22. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_convert_to_row_binary.py +0 -0
  23. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_explain_ast.py +0 -0
  24. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_get_columns_from_create_query.py +0 -0
  25. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_get_left_table.py +0 -0
  26. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_internal_cache.py +0 -0
  27. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_normalize_query_keep_names.py +0 -0
  28. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_normalize_table_column.py +0 -0
  29. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_parse_create_materialized_view_target_table.py +0 -0
  30. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_replace_tables_backward_compat.py +0 -0
  31. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_validate_partition_key.py +0 -0
  32. {tinybird_toolset-2.7.3 → tinybird_toolset-2.8.0}/tests/test_validate_ttl.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinybird-toolset
3
- Version: 2.7.3
3
+ Version: 2.8.0
4
4
  Home-page: https://gitlab.com/tinybird/clickhouse-toolset
5
5
  Author: Tinybird.co
6
6
  Author-email: support@tinybird.co
@@ -95,9 +95,6 @@ def apply_patches():
95
95
  # Unwind with external code leads to crashes
96
96
  apply_patch("patches/unwind.patch")
97
97
 
98
- # Sets timezone to UTC manually and avoids reading system files
99
- apply_patch("patches/timezone.patch")
100
-
101
98
  # This patch is used to make it possible to use valgrind with the module
102
99
  # see https://jira.mongodb.org/browse/SERVER-25771
103
100
  apply_patch("patches/boost_flags.patch")
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup, Extension
2
2
 
3
3
  NAME = 'tinybird-toolset'
4
- VERSION = '2.7.3'
4
+ VERSION = '2.8.0'
5
5
 
6
6
  # Shared metadata for both the full (extension) build and the metadata-only
7
7
  # fallback below, so the two setup() calls can't drift apart.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tinybird-toolset
3
- Version: 2.7.3
3
+ Version: 2.8.0
4
4
  Home-page: https://gitlab.com/tinybird/clickhouse-toolset
5
5
  Author: Tinybird.co
6
6
  Author-email: support@tinybird.co
@@ -154,6 +154,37 @@ class TestCreateTable(unittest.TestCase):
154
154
  """
155
155
  self.assertEqual(query.format(query.check_valid_write_query(q)), query.format(q))
156
156
 
157
+ def test_create_table_column_list_functions(self):
158
+ restricted = [
159
+ "CREATE TABLE t (a Int32, b String DEFAULT hostName()) ENGINE = MergeTree ORDER BY a",
160
+ "CREATE TABLE t (a Int32, b UInt8 MATERIALIZED sleep(1)) ENGINE = MergeTree ORDER BY a",
161
+ "CREATE TABLE t (a Int32, b String ALIAS hostName()) ENGINE = MergeTree ORDER BY a",
162
+ "CREATE TABLE t (a Int32, b String DEFAULT a IN (SELECT hostName())) ENGINE = MergeTree ORDER BY a",
163
+ "CREATE TABLE t (a Int32, d Date, b Int32 TTL d + toIntervalDay(toUInt8(sleep(1)))) ENGINE = MergeTree ORDER BY a",
164
+ "CREATE TABLE t (a Int32 CODEC(ZSTD(toUInt64(hostName())))) ENGINE = MergeTree ORDER BY a",
165
+ "CREATE TABLE t (a Int32, INDEX i hostName() TYPE minmax) ENGINE = MergeTree ORDER BY a",
166
+ ]
167
+ for q in restricted:
168
+ with self.subTest(q=q), self.assertRaisesRegex(ValueError, "Usage of function .* is restricted"):
169
+ query.check_valid_write_query(q)
170
+
171
+ with self.assertRaisesRegex(ValueError, "CREATE TABLE: Unsupported subquery: in INDEX declaration"):
172
+ query.check_valid_write_query(
173
+ "CREATE TABLE t (a Int32, INDEX i a IN (SELECT 1 FROM system.tables) TYPE minmax) ENGINE = MergeTree ORDER BY a"
174
+ )
175
+ with self.assertRaisesRegex(ValueError, "CREATE TABLE: Unsupported function dictGetUInt8: in column TTL declaration"):
176
+ query.check_valid_write_query(
177
+ "CREATE TABLE t (a Int32, d Date, b Int32 TTL d + toIntervalDay(dictGetUInt8('d', 'x', a))) ENGINE = MergeTree ORDER BY a"
178
+ )
179
+
180
+ for q in [
181
+ "CREATE TABLE t (a Int32, b String DEFAULT dictGetString('d', 'x', a)) ENGINE = MergeTree ORDER BY a",
182
+ "CREATE TABLE t (a Nullable(Int32) CODEC(Delta, ZSTD(3)), b LowCardinality(String) DEFAULT toString(a)) ENGINE = MergeTree ORDER BY tuple()",
183
+ "CREATE TABLE t (a Int32, d Date, b Int32 TTL d + INTERVAL 1 DAY, INDEX i a * 2 TYPE bloom_filter(0.01) GRANULARITY 1) ENGINE = MergeTree ORDER BY a",
184
+ ]:
185
+ with self.subTest(q=q):
186
+ query.check_valid_write_query(q)
187
+
157
188
  def test_create_table_with_subqueries_in_alias_definition__is_ok(self):
158
189
  q = """
159
190
  CREATE TABLE visits4
@@ -263,6 +294,56 @@ class TestCreateTable(unittest.TestCase):
263
294
  ORDER BY id
264
295
  """)
265
296
 
297
+ def test_create_table_with_apply(self):
298
+ restricted = [
299
+ "CREATE TABLE t (a Int8, PROJECTION p (SELECT * APPLY(x -> hostName()))) ENGINE = MergeTree ORDER BY a",
300
+ "CREATE TABLE t (a Int8, PROJECTION p (SELECT * APPLY(sleepEachRow))) ENGINE = MergeTree ORDER BY a",
301
+ "CREATE TABLE t (a Int8) ENGINE = MergeTree ORDER BY tuple(* APPLY(x -> hostName()))",
302
+ ]
303
+ for q in restricted:
304
+ with self.subTest(q=q), self.assertRaisesRegex(ValueError, "Usage of function .* is restricted"):
305
+ query.check_valid_write_query(q)
306
+
307
+ subqueries = [
308
+ "CREATE TABLE t (a Int8) ENGINE = MergeTree ORDER BY tuple(* APPLY(x -> (SELECT 1 FROM system.tables)))",
309
+ "CREATE TABLE t (a Int8) ENGINE = MergeTree ORDER BY tuple(* APPLY(x -> x IN (SELECT 1 FROM system.tables)))",
310
+ ]
311
+ for q in subqueries:
312
+ with self.subTest(q=q), self.assertRaisesRegex(ValueError, "CREATE TABLE: Unsupported subquery: in ORDER BY declaration"):
313
+ query.check_valid_write_query(q)
314
+
315
+ with self.assertRaisesRegex(ValueError, "CREATE TABLE: Unsupported function dictGetString: in ORDER BY declaration"):
316
+ query.check_valid_write_query("CREATE TABLE t (a Int8) ENGINE = MergeTree ORDER BY tuple(COLUMNS('a') APPLY(dictGetString))")
317
+
318
+ def test_create_table_with_ttl_group_by(self):
319
+ restricted = [
320
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d GROUP BY a SET a = toInt32OrZero(hostName())",
321
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d GROUP BY a SET a = toInt32(sleep(3))",
322
+ ]
323
+ for q in restricted:
324
+ with self.subTest(q=q), self.assertRaisesRegex(ValueError, "Usage of function .* is restricted"):
325
+ query.check_valid_write_query(q)
326
+
327
+ query.check_valid_write_query(
328
+ "CREATE TABLE t (a Int32, b Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d GROUP BY a SET b = max(b)"
329
+ )
330
+ query.check_valid_write_query(
331
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d RECOMPRESS CODEC(ZSTD(12))"
332
+ )
333
+ query.check_valid_write_query(
334
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d RECOMPRESS CODEC(Delta, LZ4)"
335
+ )
336
+
337
+ def test_create_table_with_ttl_recompress_codec_arguments(self):
338
+ with self.assertRaisesRegex(ValueError, "Usage of function .* is restricted"):
339
+ query.check_valid_write_query(
340
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d RECOMPRESS CODEC(ZSTD(toUInt64(hostName())))"
341
+ )
342
+ with self.assertRaisesRegex(ValueError, "CREATE TABLE: Unsupported subquery: in TTL declaration"):
343
+ query.check_valid_write_query(
344
+ "CREATE TABLE t (a Int32, d Date) ENGINE = MergeTree ORDER BY a TTL d RECOMPRESS CODEC(ZSTD((SELECT 1 FROM system.tables)))"
345
+ )
346
+
266
347
  def test_create_table_with_join_engine_is_forbidden(self):
267
348
  with self.assertRaisesRegex(ValueError, "Creation of tables with ENGINE Join is not supported"):
268
349
  query.check_valid_write_query("""
@@ -100,6 +100,31 @@ class TestReplaceTables(unittest.TestCase):
100
100
  },
101
101
  "SELECT * FROM database.t_01010101 AS t WHERE (c1, c2) IN database.t_02020202",
102
102
  ),
103
+ (
104
+ "SELECT * APPLY(x -> (SELECT count() FROM tt)) FROM (SELECT 1 AS a)",
105
+ {("", "tt"): ("", "(select a from table2 where a > 1)")},
106
+ "SELECT * APPLY(x -> (SELECT count() FROM (select a from table2 where a > 1) AS tt)) FROM (SELECT 1 AS a)",
107
+ ),
108
+ (
109
+ "SELECT * APPLY(x -> x IN (SELECT a FROM tt)) FROM (SELECT 1 AS a)",
110
+ {("", "tt"): ("database", "t_01010101")},
111
+ "SELECT * APPLY(x -> x IN (SELECT a FROM database.t_01010101 AS tt)) FROM (SELECT 1 AS a)",
112
+ ),
113
+ (
114
+ "SELECT * APPLY(x -> x IN tt) FROM (SELECT 1 AS a)",
115
+ {("", "tt"): ("database", "t_01010101")},
116
+ "SELECT * APPLY(x -> x IN database.t_01010101) FROM (SELECT 1 AS a)",
117
+ ),
118
+ (
119
+ "SELECT sum(a) OVER (PARTITION BY (SELECT count() FROM tt)) FROM (SELECT 1 AS a)",
120
+ {("", "tt"): ("database", "t_01010101")},
121
+ "SELECT sum(a) OVER (PARTITION BY (SELECT count() FROM database.t_01010101 AS tt)) FROM (SELECT 1 AS a)",
122
+ ),
123
+ (
124
+ "SELECT sum(a) OVER w FROM (SELECT 1 AS a) WINDOW w AS (PARTITION BY a IN (SELECT a FROM tt))",
125
+ {("", "tt"): ("database", "t_01010101")},
126
+ "SELECT sum(a) OVER w FROM (SELECT 1 AS a) WINDOW w AS (PARTITION BY a IN (SELECT a FROM database.t_01010101 AS tt))",
127
+ ),
103
128
  ]
104
129
 
105
130
  def test_asterisks_no_database(self):
@@ -698,6 +723,11 @@ class TestReplaceTables(unittest.TestCase):
698
723
  replacements = {("default", "table"): ("d_012345", "t_wadus")}
699
724
  for sql in [
700
725
  "EXPLAIN PLAN actions=1 SELECT table.col FROM table",
726
+ "EXPLAIN PIPELINE header=1 SELECT table.col FROM table",
727
+ "EXPLAIN QUERY TREE passes=1 SELECT table.col FROM table",
728
+ "EXPLAIN SYNTAX oneline=1 SELECT table.col FROM table",
729
+ "EXPLAIN AST SELECT table.col FROM table",
730
+ "EXPLAIN ESTIMATE SELECT table.col FROM table",
701
731
  ]:
702
732
  expected_query = sql.replace("FROM table", "FROM d_012345.t_wadus as table").replace("table.col", "t_wadus.col")
703
733
  replaced = chquery.replace_tables(sql, replacements, default_database="default")
@@ -709,7 +739,7 @@ class TestReplaceTables(unittest.TestCase):
709
739
  "SELECT * FROM file('/etc/passwd', 'CSV', 'a String')",
710
740
  "SELECT * FROM view(SELECT 1)",
711
741
  ]
712
- for explain in ["EXPLAIN", "EXPLAIN PLAN actions=1"]:
742
+ for explain in ["EXPLAIN", "EXPLAIN PLAN actions=1", "EXPLAIN PIPELINE header=1", "EXPLAIN QUERY TREE passes=1", "EXPLAIN SYNTAX oneline=1", "EXPLAIN AST", "EXPLAIN ESTIMATE"]:
713
743
  for query in explained:
714
744
  with self.assertRaisesRegex(ValueError, "is restricted"):
715
745
  chquery.replace_tables(f"{explain} {query}", {("default", "t"): ("d_1", "t_1")})
@@ -723,29 +753,18 @@ class TestReplaceTables(unittest.TestCase):
723
753
  self.assertIn("db_b.events_b", replaced_b)
724
754
  self.assertNotIn("db_a", replaced_b)
725
755
 
726
- def test_explain_query_throws_with_unsupported_kinds(self):
727
- for kind in ["AST", "SYNTAX", "QUERY TREE", "PIPELINE", "ESTIMATE"]:
728
- with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
729
- chquery.replace_tables(f"EXPLAIN {kind} SELECT col FROM table", {("default", "table"): ("d_012345", "t_wadus")})
730
-
731
756
  def test_explain_query_throws_with_unsupported_explained_query(self):
732
757
  queries = [
733
758
  "EXPLAIN INSERT INTO test.table VALUES (1,2,3)",
734
759
  "EXPLAIN INSERT INTO test.table SELECT * FROM other",
735
760
  "EXPLAIN CREATE TABLE table_test (`index` String) ENGINE = MergeTree ORDER BY index",
736
- ]
737
- for q in queries:
738
- with self.assertRaisesRegex(ValueError, 'EXPLAIN is only supported for SELECT queries'):
739
- chquery.replace_tables(q, {("default", "table"): ("d_012345", "t_wadus")})
740
-
741
- queries = [
742
761
  "EXPLAIN TABLE OVERRIDE mysql('127.0.0.1:3306', 'db', 't', 'u', 'p') PARTITION BY toYYYYMM(d)",
743
762
  "EXPLAIN CURRENT TRANSACTION",
744
763
  "EXPLAIN AST DROP TABLE test",
745
764
  "EXPLAIN AST INSERT INTO test.table VALUES (1,2,3)",
746
765
  ]
747
766
  for q in queries:
748
- with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
767
+ with self.assertRaisesRegex(ValueError, 'EXPLAIN is only supported for SELECT queries'):
749
768
  chquery.replace_tables(q, {("default", "table"): ("d_012345", "t_wadus")})
750
769
 
751
770
  def test_replace_of_table_function_throws(self):
@@ -1023,6 +1042,37 @@ class TestDisabledFunctions(unittest.TestCase):
1023
1042
  ):
1024
1043
  chquery.replace_tables(q, replacements)
1025
1044
 
1045
+ def test_blocked_function_in_apply(self):
1046
+ queries = [
1047
+ "SELECT * APPLY(sleep) FROM (SELECT 2 AS a)",
1048
+ "SELECT * APPLY(x -> hostName()) FROM (SELECT 1 AS a)",
1049
+ "SELECT * APPLY(filesystemCapacity) FROM (SELECT 'default' AS a)",
1050
+ "SELECT COLUMNS('a') APPLY(x -> sleep(x)) FROM (SELECT 1 AS a)",
1051
+ "SELECT t.* APPLY(x -> toInt64(currentUser())) FROM (SELECT 1 AS a) AS t",
1052
+ ]
1053
+ for q in queries:
1054
+ with self.assertRaisesRegex(ValueError, "DB::Exception: Usage of function .* is restricted"):
1055
+ chquery.replace_tables(q, {})
1056
+
1057
+ def test_allowed_function_in_apply(self):
1058
+ for q in [
1059
+ "SELECT * APPLY(sum) FROM (SELECT 2 AS a)",
1060
+ "SELECT * APPLY(quantile(0.9)) FROM (SELECT 2 AS a)",
1061
+ "SELECT * APPLY(x -> toString(x)) FROM (SELECT 2 AS a)",
1062
+ ]:
1063
+ chquery.replace_tables(q, {})
1064
+
1065
+ def test_blocked_function_in_window(self):
1066
+ queries = [
1067
+ "SELECT sum(a) OVER (PARTITION BY sleep(1)) FROM (SELECT 1 AS a)",
1068
+ "SELECT sum(a) OVER (ORDER BY hostName()) FROM (SELECT 1 AS a)",
1069
+ "SELECT sum(a) OVER (ORDER BY a ROWS BETWEEN toUInt64(sleep(1)) PRECEDING AND CURRENT ROW) FROM (SELECT 1 AS a)",
1070
+ "SELECT sum(a) OVER w FROM (SELECT 1 AS a) WINDOW w AS (PARTITION BY sleep(1))",
1071
+ ]
1072
+ for q in queries:
1073
+ with self.subTest(q=q), self.assertRaisesRegex(ValueError, "DB::Exception: Usage of function .* is restricted"):
1074
+ chquery.replace_tables(q, {})
1075
+
1026
1076
  def test_sleep_in_replacements(self):
1027
1077
  sql = "SELECT * FROM a, a"
1028
1078
  replacement = {
@@ -150,6 +150,12 @@ class TestGetLeftTable(unittest.TestCase):
150
150
  self.assertEqual(chquery.format(chquery.rewrite_aggregation_states(sql)), chquery.format(expected))
151
151
 
152
152
  def test_throws_with_explain_and_describe(self):
153
- for sql in ["EXPLAIN SELECT avg(value) FROM table", "DESCRIBE TABLE table"]:
153
+ for sql in [
154
+ "EXPLAIN SELECT avg(value) FROM table",
155
+ "EXPLAIN AST SELECT avg(value) FROM table",
156
+ "EXPLAIN PIPELINE SELECT avg(value) FROM table",
157
+ "EXPLAIN ESTIMATE SELECT avg(value) FROM table",
158
+ "DESCRIBE TABLE table",
159
+ ]:
154
160
  with self.assertRaisesRegex(ValueError, "Only SELECT queries are supported"):
155
161
  chquery.rewrite_aggregation_states(sql)
@@ -27,6 +27,14 @@ class TestTables(unittest.TestCase):
27
27
  ('SELECT * FROM t WHERE event_date IN system.query_log', [('', 't', ''), ('system', 'query_log', '')]),
28
28
  ('SELECT * FROM t WHERE event_date GLOBAL NOT IN system.query_log', [('', 't', ''), ('system', 'query_log', '')]),
29
29
  ('SELECT * FROM t WHERE event_date IN (Select * FROM system.query_log)', [('', 't', ''), ('system', 'query_log', '')]),
30
+ ('SELECT * APPLY(x -> (SELECT count() FROM system.trace_log)) FROM (SELECT 1 AS a)', [('system', 'trace_log', '')]),
31
+ ('SELECT * APPLY(x -> x IN (SELECT count() FROM system.tables)) FROM (SELECT 1 AS a)', [('system', 'tables', '')]),
32
+ ('SELECT * APPLY(x -> x IN system.tables) FROM (SELECT 1 AS a)', [('system', 'tables', '')]),
33
+ ('SELECT COLUMNS(\'a\') APPLY(x -> (SELECT max(b) FROM t2)) FROM t', [('', 't', ''), ('', 't2', '')]),
34
+ ('SELECT * APPLY(x -> (WITH c AS (SELECT b FROM t) SELECT count() FROM c)) FROM (SELECT 1 AS a)', [('', 't', '')]),
35
+ ('SELECT sum(a) OVER (PARTITION BY (SELECT count() FROM system.trace_log)) FROM (SELECT 1 AS a)', [('system', 'trace_log', '')]),
36
+ ('SELECT sum(a) OVER (ORDER BY a IN system.tables) FROM (SELECT 1 AS a)', [('system', 'tables', '')]),
37
+ ('SELECT sum(a) OVER w FROM (SELECT 1 AS a) WINDOW w AS (PARTITION BY (SELECT count() FROM system.trace_log))', [('system', 'trace_log', '')]),
30
38
  ]
31
39
 
32
40
  def test_json_all_paths_is_allowed(self):
@@ -255,16 +263,11 @@ SELECT *
255
263
  self.assertEqual(chquery.tables(sql), [('', 'table', '')])
256
264
 
257
265
  def test_explain_query(self):
258
- for kind in ["", "PLAN", "PLAN indexes=1", "actions=1"]:
266
+ for kind in ["", "PLAN", "PLAN indexes=1", "actions=1", "AST", "SYNTAX", "QUERY TREE", "PIPELINE", "ESTIMATE"]:
259
267
  sql = f"EXPLAIN {kind} SELECT table.col FROM db.table JOIN other ON table.id = other.id"
260
268
  self.assertEqual(sorted(chquery.tables(sql)),
261
269
  [('', 'other', ''), ('db', 'table', '')], sql)
262
270
 
263
- def test_explain_query_throws_with_unsupported_kinds(self):
264
- for kind in ["AST", "SYNTAX", "QUERY TREE", "PIPELINE", "ESTIMATE"]:
265
- with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
266
- chquery.tables(f"EXPLAIN {kind} SELECT col FROM db.table")
267
-
268
271
  def test_explain_query_throws_with_invalid_inner_function(self):
269
272
  with self.assertRaisesRegex(ValueError, 'DB::Exception: Unknown function doesNotExist'):
270
273
  chquery.tables("EXPLAIN SELECT doesNotExist(number) FROM numbers(100)")
@@ -274,19 +277,13 @@ SELECT *
274
277
  "EXPLAIN INSERT INTO test.table VALUES (1,2,3)",
275
278
  "EXPLAIN INSERT INTO test.table SELECT * FROM other",
276
279
  "EXPLAIN CREATE TABLE table_test (`index` String) ENGINE = MergeTree ORDER BY index",
277
- ]
278
- for q in queries:
279
- with self.assertRaisesRegex(ValueError, 'EXPLAIN is only supported for SELECT queries'):
280
- chquery.tables(q)
281
-
282
- queries = [
283
280
  "EXPLAIN TABLE OVERRIDE mysql('127.0.0.1:3306', 'db', 't', 'u', 'p') PARTITION BY toYYYYMM(d)",
284
281
  "EXPLAIN CURRENT TRANSACTION",
285
282
  "EXPLAIN AST DROP TABLE test",
286
283
  "EXPLAIN AST INSERT INTO test.table VALUES (1,2,3)",
287
284
  ]
288
285
  for q in queries:
289
- with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
286
+ with self.assertRaisesRegex(ValueError, 'EXPLAIN is only supported for SELECT queries'):
290
287
  chquery.tables(q)
291
288
 
292
289
  def test_throws_with_invalid_query_types(self):