tinybird-toolset 2.7.0__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.
- {tinybird_toolset-2.7.0/src/tinybird_toolset.egg-info → tinybird_toolset-2.7.3}/PKG-INFO +1 -1
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/conf.py +49 -63
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/setup.py +1 -1
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3/src/tinybird_toolset.egg-info}/PKG-INFO +1 -1
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_replace_tables.py +62 -1
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_rewrite_aggregation_states.py +5 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_tables.py +36 -1
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_validate_ttl.py +88 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/LICENSE +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/MANIFEST.in +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/README.md +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/setup.cfg +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/chtoolset/__init__.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/chtoolset/query.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/SOURCES.txt +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/dependency_links.txt +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/requires.txt +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/top_level.txt +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_check_compatible_types.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_check_ttl_partition_compatibility.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_check_write_query.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_chquery.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_convert_to_row_binary.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_explain_ast.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_get_columns_from_create_query.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_get_left_table.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_internal_cache.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_normalize_query_keep_names.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_normalize_table_column.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_parse_create_materialized_view_target_table.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_replace_tables_backward_compat.py +0 -0
- {tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_validate_partition_key.py +0 -0
|
@@ -90,82 +90,63 @@ def apply_patch(patch_path):
|
|
|
90
90
|
f"=== stderr ===\n\n{stderr_buffer.getvalue()}")
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
116
|
-
|
|
98
|
+
# Sets timezone to UTC manually and avoids reading system files
|
|
99
|
+
apply_patch("patches/timezone.patch")
|
|
117
100
|
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
105
|
+
# Be able to set our flags in the build (PIC)
|
|
106
|
+
apply_patch("patches/Preload.patch")
|
|
123
107
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
129
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
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
|
-
|
|
153
|
-
|
|
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
|
|
162
|
-
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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()
|
|
@@ -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
|
|
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
|
|
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):
|
|
@@ -377,6 +377,94 @@ class TestValidateTTL(unittest.TestCase):
|
|
|
377
377
|
)
|
|
378
378
|
)
|
|
379
379
|
|
|
380
|
+
def test_valid_ttl_with_json_extract(self):
|
|
381
|
+
# Reported failure: "Unknown function JSONExtractString".
|
|
382
|
+
self.assertIsNone(
|
|
383
|
+
chquery.validate_ttl(
|
|
384
|
+
ttl="if(parseDateTimeBestEffortOrZero(JSONExtractString(JSONExtractRaw(message, 'mail'), 'timestamp')) = toDateTime(0), "
|
|
385
|
+
"toDateTime('2099-01-01 00:00:00'), "
|
|
386
|
+
"parseDateTimeBestEffortOrZero(JSONExtractString(JSONExtractRaw(message, 'mail'), 'timestamp'))) + toIntervalDay(90)",
|
|
387
|
+
columns=[{"name": "message", "type": "String"}],
|
|
388
|
+
sorting_key="tuple()",
|
|
389
|
+
)
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
def test_ttl_with_json_extract_still_checks_result_type(self):
|
|
393
|
+
# JSON functions must resolve, but the TTL result must still be a DateTime/Date.
|
|
394
|
+
err = chquery.validate_ttl(
|
|
395
|
+
ttl="JSONExtractString(message, 'ts')",
|
|
396
|
+
columns=[{"name": "message", "type": "String"}],
|
|
397
|
+
sorting_key="tuple()",
|
|
398
|
+
)
|
|
399
|
+
self.assertIsNotNone(err)
|
|
400
|
+
self.assertIn("TTL expression result column should have DateTime or Date type", err)
|
|
401
|
+
|
|
402
|
+
def test_ttl_with_json_extract_still_checks_columns(self):
|
|
403
|
+
err = chquery.validate_ttl(
|
|
404
|
+
ttl="toDateTime(JSONExtractInt(other, 'ts')) + toIntervalDay(1)",
|
|
405
|
+
columns=[{"name": "message", "type": "String"}],
|
|
406
|
+
sorting_key="tuple()",
|
|
407
|
+
)
|
|
408
|
+
self.assertIsNotNone(err)
|
|
409
|
+
self.assertNotIn("Unknown function", err)
|
|
410
|
+
self.assertIn("other", err)
|
|
411
|
+
|
|
412
|
+
def test_valid_ttl_with_other_json_functions(self):
|
|
413
|
+
ttls = [
|
|
414
|
+
"toDateTime(JSONExtractInt(message, 'ts')) + toIntervalDay(7)",
|
|
415
|
+
"JSONExtract(message, 'ts', 'DateTime') + toIntervalDay(7)",
|
|
416
|
+
"if(JSONHas(message, 'ts'), toDateTime(JSONExtractInt(message, 'ts')), toDateTime(0)) + toIntervalDay(7)",
|
|
417
|
+
]
|
|
418
|
+
for ttl in ttls:
|
|
419
|
+
with self.subTest(ttl=ttl):
|
|
420
|
+
self.assertIsNone(
|
|
421
|
+
chquery.validate_ttl(
|
|
422
|
+
ttl=ttl,
|
|
423
|
+
columns=[{"name": "message", "type": "String"}],
|
|
424
|
+
sorting_key="tuple()",
|
|
425
|
+
)
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
def test_valid_ttl_with_simple_json_functions(self):
|
|
429
|
+
ttls = [
|
|
430
|
+
"toDateTime(simpleJSONExtractInt(message, 'ts')) + toIntervalDay(7)",
|
|
431
|
+
"if(simpleJSONHas(message, 'ts'), toDateTime(simpleJSONExtractInt(message, 'ts')), toDateTime(0)) + toIntervalDay(7)",
|
|
432
|
+
]
|
|
433
|
+
for ttl in ttls:
|
|
434
|
+
with self.subTest(ttl=ttl):
|
|
435
|
+
self.assertIsNone(
|
|
436
|
+
chquery.validate_ttl(
|
|
437
|
+
ttl=ttl,
|
|
438
|
+
columns=[{"name": "message", "type": "String"}],
|
|
439
|
+
sorting_key="tuple()",
|
|
440
|
+
)
|
|
441
|
+
)
|
|
442
|
+
|
|
443
|
+
def test_valid_ttl_with_sql_json_functions(self):
|
|
444
|
+
ttls = [
|
|
445
|
+
"parseDateTimeBestEffortOrZero(JSON_VALUE(message, '$.mail.timestamp')) + toIntervalDay(90)",
|
|
446
|
+
"parseDateTimeBestEffortOrZero(JSON_VALUE(JSON_QUERY(message, '$.mail'), '$.timestamp')) + toIntervalDay(90)",
|
|
447
|
+
"if(JSON_EXISTS(message, '$.mail.timestamp'), parseDateTimeBestEffortOrZero(JSON_VALUE(message, '$.mail.timestamp')), toDateTime(0)) + toIntervalDay(90)",
|
|
448
|
+
]
|
|
449
|
+
for ttl in ttls:
|
|
450
|
+
with self.subTest(ttl=ttl):
|
|
451
|
+
self.assertIsNone(
|
|
452
|
+
chquery.validate_ttl(
|
|
453
|
+
ttl=ttl,
|
|
454
|
+
columns=[{"name": "message", "type": "String"}],
|
|
455
|
+
sorting_key="tuple()",
|
|
456
|
+
)
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
def test_ttl_with_misspelled_json_function_is_rejected(self):
|
|
460
|
+
err = chquery.validate_ttl(
|
|
461
|
+
ttl="toDateTime(JSONExtractStrng(message, 'ts')) + toIntervalDay(1)",
|
|
462
|
+
columns=[{"name": "message", "type": "String"}],
|
|
463
|
+
sorting_key="tuple()",
|
|
464
|
+
)
|
|
465
|
+
self.assertIsNotNone(err)
|
|
466
|
+
self.assertIn("Unknown function JSONExtractStrng", err)
|
|
467
|
+
|
|
380
468
|
# --- Input validation ---
|
|
381
469
|
def test_columns_must_be_list_of_dicts(self):
|
|
382
470
|
with self.assertRaises(TypeError):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/requires.txt
RENAMED
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/src/tinybird_toolset.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_check_ttl_partition_compatibility.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_get_columns_from_create_query.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tinybird_toolset-2.7.0 → tinybird_toolset-2.7.3}/tests/test_replace_tables_backward_compat.py
RENAMED
|
File without changes
|
|
File without changes
|