tinybird-toolset 2.7.1__tar.gz → 2.7.3__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.1/src/tinybird_toolset.egg-info → tinybird_toolset-2.7.3}/PKG-INFO +1 -1
  2. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/conf.py +49 -63
  3. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/setup.py +1 -1
  4. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3/src/tinybird_toolset.egg-info}/PKG-INFO +1 -1
  5. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_replace_tables.py +62 -1
  6. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_rewrite_aggregation_states.py +5 -0
  7. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_tables.py +36 -1
  8. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/LICENSE +0 -0
  9. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/MANIFEST.in +0 -0
  10. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/README.md +0 -0
  11. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/setup.cfg +0 -0
  12. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/chtoolset/__init__.py +0 -0
  13. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/chtoolset/query.py +0 -0
  14. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/SOURCES.txt +0 -0
  15. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/dependency_links.txt +0 -0
  16. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/requires.txt +0 -0
  17. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/top_level.txt +0 -0
  18. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_check_compatible_types.py +0 -0
  19. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_check_ttl_partition_compatibility.py +0 -0
  20. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_check_write_query.py +0 -0
  21. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_chquery.py +0 -0
  22. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_convert_to_row_binary.py +0 -0
  23. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_explain_ast.py +0 -0
  24. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_get_columns_from_create_query.py +0 -0
  25. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_get_left_table.py +0 -0
  26. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_internal_cache.py +0 -0
  27. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_normalize_query_keep_names.py +0 -0
  28. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_normalize_table_column.py +0 -0
  29. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_parse_create_materialized_view_target_table.py +0 -0
  30. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_replace_tables_backward_compat.py +0 -0
  31. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/tests/test_validate_partition_key.py +0 -0
  32. {tinybird_toolset-2.7.1 → tinybird_toolset-2.7.3}/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.1
3
+ Version: 2.7.3
4
4
  Home-page: https://gitlab.com/tinybird/clickhouse-toolset
5
5
  Author: Tinybird.co
6
6
  Author-email: support@tinybird.co
@@ -90,82 +90,63 @@ def apply_patch(patch_path):
90
90
  f"=== stderr ===\n\n{stderr_buffer.getvalue()}")
91
91
 
92
92
 
93
- class ClickHouseBuildExt(build_ext):
94
- def run(self):
95
-
96
- if not os.path.exists(os.path.join(CLICKHOUSE_PATH, 'CMakeLists.txt')):
97
- raise RuntimeError('Git submodules are not initialized. Run: `git submodule update --init --recursive`.')
98
-
99
- # One of the libraries, chosen randomly (+ the TTL functions one, added later)
100
- if os.path.isfile(os.path.join(CLICKHOUSE_BUILD_PATH,
101
- 'src/AggregateFunctions/libclickhouse_aggregate_functions.a')) \
102
- and os.path.isfile(os.path.join(CLICKHOUSE_BUILD_PATH,
103
- 'src/Functions/libclickhouse_ttl_functions.a')):
104
- return
105
-
106
- # Avoid segfault caused by missing global context
107
- apply_patch("patches/createJSON.patch")
108
-
109
- # Disable analyzer by default
110
- apply_patch("patches/disable_analyzer.patch")
111
-
112
- # Unwind with external code leads to crashes
113
- apply_patch("patches/unwind.patch")
93
+ def apply_patches():
94
+ """Apply all patches needed on the ClickHouse tree. Idempotent."""
95
+ # Unwind with external code leads to crashes
96
+ apply_patch("patches/unwind.patch")
114
97
 
115
- # Sets timezone to UTC manually and avoids reading system files
116
- apply_patch("patches/timezone.patch")
98
+ # Sets timezone to UTC manually and avoids reading system files
99
+ apply_patch("patches/timezone.patch")
117
100
 
118
- # Easier access to ASTIdentifier private data
119
- apply_patch("patches/ASTIdentifier.patch")
101
+ # This patch is used to make it possible to use valgrind with the module
102
+ # see https://jira.mongodb.org/browse/SERVER-25771
103
+ apply_patch("patches/boost_flags.patch")
120
104
 
121
- # Easier access to AggregateFunctionFactory private data
122
- apply_patch("patches/AggregateFunctionFactory.patch")
105
+ # Be able to set our flags in the build (PIC)
106
+ apply_patch("patches/Preload.patch")
123
107
 
124
- # This patch is used to make it possible to use valgrind with the module
125
- # see https://jira.mongodb.org/browse/SERVER-25771
126
- apply_patch("patches/boost_flags.patch")
108
+ # This is only for performance.
109
+ # Avoids calling getTreeHash() which is slow
110
+ # Might change the output of the query since it won't replace same subqueries with the alias
111
+ # This is ok as long as the subquery isn't super long, but it should be ok since in our case that would
112
+ # mean the query was already super long
113
+ apply_patch("patches/ASTWithAlias_perf.patch")
127
114
 
128
- # Be able to set our flags in the build (PIC)
129
- apply_patch("patches/Preload.patch")
115
+ # Emit standard SQL TRIM(BOTH/LEADING/TRAILING ... FROM ...) syntax for 2-arg
116
+ # trimBoth/trimLeft/trimRight calls, so the output is compatible with CH < 25.2
117
+ apply_patch("patches/trim_format.patch")
130
118
 
131
- # This is only for performance.
132
- # Avoids calling getTreeHash() which is slow
133
- # Might change the output of the query since it won't replace same subqueries with the alias
134
- # This is ok as long as the subquery isn't super long, but it should be ok since in our case that would
135
- # mean the query was already super long
136
- apply_patch("patches/ASTWithAlias_perf.patch")
119
+ # Builds the functions needed by validate_ttl into libclickhouse_ttl_functions.a,
120
+ # which is linked with --whole-archive/-force_load (see extra_libs).
121
+ # NOTE: after editing this patch (or any other), the early-return above skips the
122
+ # ClickHouse build; delete ch_build/src/Functions/libclickhouse_ttl_functions.a
123
+ # (or the whole ch_build) to force it to run again.
124
+ apply_patch("patches/dbmsfunctions.patch")
137
125
 
138
- # Emit standard SQL TRIM(BOTH/LEADING/TRAILING ... FROM ...) syntax for 2-arg
139
- # trimBoth/trimLeft/trimRight calls, so the output is compatible with CH < 25.2
140
- apply_patch("patches/trim_format.patch")
126
+ # Range-check narrow-integer Field inserts so JSON/Dynamic paths widen instead of
127
+ # silently wrapping (1944 -> -104). Backport of the ColumnVector::tryInsert fix;
128
+ # remove once the fix lands in the pinned ClickHouse submodule.
129
+ apply_patch("patches/ColumnVectorTryInsert.patch")
141
130
 
142
- # Removes TSA warnings (we don't compile with a libc++ with annotations)
143
- apply_patch("patches/tsa.patch")
131
+ # Keep TTL result validation compatible with ClickHouse versions before 25.8:
132
+ # DateTime64 and Date32 results must remain rejected until all servers migrate.
133
+ apply_patch("patches/ttl_result_type_compat.patch")
144
134
 
145
- # Builds the functions needed by validate_ttl into libclickhouse_ttl_functions.a,
146
- # which is linked with --whole-archive/-force_load (see extra_libs).
147
- # NOTE: after editing this patch (or any other), the early-return above skips the
148
- # ClickHouse build; delete ch_build/src/Functions/libclickhouse_ttl_functions.a
149
- # (or the whole ch_build) to force it to run again.
150
- apply_patch("patches/dbmsfunctions.patch")
151
135
 
152
- # Range-check narrow-integer Field inserts so JSON/Dynamic paths widen instead of
153
- # silently wrapping (1944 -> -104). Backport of the ColumnVector::tryInsert fix;
154
- # remove once the fix lands in the pinned ClickHouse submodule.
155
- apply_patch("patches/ColumnVectorTryInsert.patch")
156
-
157
- # Keep TTL result validation compatible with ClickHouse versions before 25.8:
158
- # DateTime64 and Date32 results must remain rejected until all servers migrate.
159
- apply_patch("patches/ttl_result_type_compat.patch")
136
+ class ClickHouseBuildExt(build_ext):
137
+ def run(self):
160
138
 
161
- if sys.platform == 'darwin':
162
- # We disable whole_archive options destined for AppleClang, which is unsupported but keeps being a PITA
163
- apply_patch("patches/darwin.patch")
139
+ if not os.path.exists(os.path.join(CLICKHOUSE_PATH, 'CMakeLists.txt')):
140
+ raise RuntimeError('Git submodules are not initialized. Run: `git submodule update --init --recursive`.')
164
141
 
165
- # Problem with offsetof macro definition
166
- # NOTE: offsetof.patch is no longer needed for ClickHouse 25.3+ as the changes are already upstream
167
- # apply_patch("patches/offsetof.patch")
142
+ # One of the libraries, chosen randomly (+ the TTL functions one, added later)
143
+ if os.path.isfile(os.path.join(CLICKHOUSE_BUILD_PATH,
144
+ 'src/AggregateFunctions/libclickhouse_aggregate_functions.a')) \
145
+ and os.path.isfile(os.path.join(CLICKHOUSE_BUILD_PATH,
146
+ 'src/Functions/libclickhouse_ttl_functions.a')):
147
+ return
168
148
 
149
+ apply_patches()
169
150
 
170
151
  cmake_cmd = os.environ.get('CMAKE_BIN', 'cmake')
171
152
  try:
@@ -499,3 +480,8 @@ def requirements_from_file(path):
499
480
  for line in Path(path).read_text().split("\n")
500
481
  if not line.startswith(('"', "#", "-", "git+"))
501
482
  ]
483
+
484
+
485
+ if __name__ == '__main__':
486
+ # Used by `make apply-patches` (e.g. clang-tidy needs the patched ClickHouse sources)
487
+ apply_patches()
@@ -1,7 +1,7 @@
1
1
  from setuptools import setup, Extension
2
2
 
3
3
  NAME = 'tinybird-toolset'
4
- VERSION = '2.7.1'
4
+ VERSION = '2.7.3'
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.1
3
+ Version: 2.7.3
4
4
  Home-page: https://gitlab.com/tinybird/clickhouse-toolset
5
5
  Author: Tinybird.co
6
6
  Author-email: support@tinybird.co
@@ -687,6 +687,67 @@ class TestReplaceTables(unittest.TestCase):
687
687
  replaced = chquery.replace_tables(sql, replacements, default_database="default")
688
688
  self.assertEqual(replaced, chquery.format(expected_query))
689
689
 
690
+ def test_explain_query(self):
691
+ sql = "EXPLAIN SELECT table.col FROM table"
692
+ replacements = {("default", "table"): ("d_012345", "t_wadus")}
693
+ expected_query = "EXPLAIN SELECT t_wadus.col FROM d_012345.t_wadus as table"
694
+ replaced = chquery.replace_tables(sql, replacements, default_database="default")
695
+ self.assertEqual(replaced, chquery.format(expected_query))
696
+
697
+ def test_explain_query_with_options(self):
698
+ replacements = {("default", "table"): ("d_012345", "t_wadus")}
699
+ for sql in [
700
+ "EXPLAIN PLAN actions=1 SELECT table.col FROM table",
701
+ ]:
702
+ expected_query = sql.replace("FROM table", "FROM d_012345.t_wadus as table").replace("table.col", "t_wadus.col")
703
+ replaced = chquery.replace_tables(sql, replacements, default_database="default")
704
+ self.assertEqual(replaced, chquery.format(expected_query))
705
+
706
+ def test_explain_query_validates_the_explained_query(self):
707
+ explained = [
708
+ "SELECT * FROM url('http://127.0.0.1:18765/x.csv', 'CSV')",
709
+ "SELECT * FROM file('/etc/passwd', 'CSV', 'a String')",
710
+ "SELECT * FROM view(SELECT 1)",
711
+ ]
712
+ for explain in ["EXPLAIN", "EXPLAIN PLAN actions=1"]:
713
+ for query in explained:
714
+ with self.assertRaisesRegex(ValueError, "is restricted"):
715
+ chquery.replace_tables(f"{explain} {query}", {("default", "t"): ("d_1", "t_1")})
716
+
717
+ def test_explain_query_does_not_leak_replacements_through_the_cache(self):
718
+ for sql in ["EXPLAIN SELECT * FROM events", "EXPLAIN PLAN actions=1 SELECT * FROM events"]:
719
+ replaced_a = chquery.replace_tables(sql, {("default", "events"): ("db_a", "events_a")}, default_database="default")
720
+ replaced_b = chquery.replace_tables(sql, {("default", "events"): ("db_b", "events_b")}, default_database="default")
721
+ self.assertIn("db_a.events_a", replaced_a)
722
+ self.assertNotIn("db_b", replaced_a)
723
+ self.assertIn("db_b.events_b", replaced_b)
724
+ self.assertNotIn("db_a", replaced_b)
725
+
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
+ def test_explain_query_throws_with_unsupported_explained_query(self):
732
+ queries = [
733
+ "EXPLAIN INSERT INTO test.table VALUES (1,2,3)",
734
+ "EXPLAIN INSERT INTO test.table SELECT * FROM other",
735
+ "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
+ "EXPLAIN TABLE OVERRIDE mysql('127.0.0.1:3306', 'db', 't', 'u', 'p') PARTITION BY toYYYYMM(d)",
743
+ "EXPLAIN CURRENT TRANSACTION",
744
+ "EXPLAIN AST DROP TABLE test",
745
+ "EXPLAIN AST INSERT INTO test.table VALUES (1,2,3)",
746
+ ]
747
+ for q in queries:
748
+ with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
749
+ chquery.replace_tables(q, {("default", "table"): ("d_012345", "t_wadus")})
750
+
690
751
  def test_replace_of_table_function_throws(self):
691
752
  sql = "SELECT * FROM numbers(10)"
692
753
  replacement = {("", "", "numbers"): ("", "", "one")}
@@ -763,7 +824,7 @@ class TestReplaceTables(unittest.TestCase):
763
824
  replacement = {("default", "test_pipe_1"): ("", "something_else")}
764
825
  for q in queries:
765
826
  with self.assertRaisesRegex(
766
- ValueError, "Only SELECT or DESCRIBE queries are supported. Got: .*"
827
+ ValueError, "Only SELECT, DESCRIBE and EXPLAIN queries are supported. Got: .*"
767
828
  ):
768
829
  chquery.replace_tables(q, replacement)
769
830
 
@@ -148,3 +148,8 @@ class TestGetLeftTable(unittest.TestCase):
148
148
  sql = "WITH t as (select value from table) SELECT avg(value) FROM t"
149
149
  expected = "WITH t as (select value from table) SELECT avgState(value) FROM t"
150
150
  self.assertEqual(chquery.format(chquery.rewrite_aggregation_states(sql)), chquery.format(expected))
151
+
152
+ def test_throws_with_explain_and_describe(self):
153
+ for sql in ["EXPLAIN SELECT avg(value) FROM table", "DESCRIBE TABLE table"]:
154
+ with self.assertRaisesRegex(ValueError, "Only SELECT queries are supported"):
155
+ chquery.rewrite_aggregation_states(sql)
@@ -254,6 +254,41 @@ SELECT *
254
254
  """
255
255
  self.assertEqual(chquery.tables(sql), [('', 'table', '')])
256
256
 
257
+ def test_explain_query(self):
258
+ for kind in ["", "PLAN", "PLAN indexes=1", "actions=1"]:
259
+ sql = f"EXPLAIN {kind} SELECT table.col FROM db.table JOIN other ON table.id = other.id"
260
+ self.assertEqual(sorted(chquery.tables(sql)),
261
+ [('', 'other', ''), ('db', 'table', '')], sql)
262
+
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
+ def test_explain_query_throws_with_invalid_inner_function(self):
269
+ with self.assertRaisesRegex(ValueError, 'DB::Exception: Unknown function doesNotExist'):
270
+ chquery.tables("EXPLAIN SELECT doesNotExist(number) FROM numbers(100)")
271
+
272
+ def test_explain_query_throws_with_unsupported_explained_query(self):
273
+ queries = [
274
+ "EXPLAIN INSERT INTO test.table VALUES (1,2,3)",
275
+ "EXPLAIN INSERT INTO test.table SELECT * FROM other",
276
+ "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
+ "EXPLAIN TABLE OVERRIDE mysql('127.0.0.1:3306', 'db', 't', 'u', 'p') PARTITION BY toYYYYMM(d)",
284
+ "EXPLAIN CURRENT TRANSACTION",
285
+ "EXPLAIN AST DROP TABLE test",
286
+ "EXPLAIN AST INSERT INTO test.table VALUES (1,2,3)",
287
+ ]
288
+ for q in queries:
289
+ with self.assertRaisesRegex(ValueError, 'Only plain EXPLAIN is supported'):
290
+ chquery.tables(q)
291
+
257
292
  def test_throws_with_invalid_query_types(self):
258
293
  queries = [
259
294
  "INSERT INTO test.table VALUES (1,2,3)",
@@ -265,7 +300,7 @@ SELECT *
265
300
  "DROP TABLE test"
266
301
  ]
267
302
  for q in queries:
268
- with self.assertRaisesRegex(ValueError, 'Only SELECT or DESCRIBE queries are supported. Got: .*'):
303
+ with self.assertRaisesRegex(ValueError, 'Only SELECT, DESCRIBE and EXPLAIN queries are supported. Got: .*'):
269
304
  chquery.tables(q)
270
305
 
271
306
  def test_throws_with_invalid_functions(self):