tinybird 4.6.24.dev0__py3-none-any.whl → 4.6.25.dev0__py3-none-any.whl

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.
@@ -1,3 +1,4 @@
1
+ import functools
1
2
  import logging
2
3
  import re
3
4
  from collections import defaultdict
@@ -25,6 +26,9 @@ DEFAULT_EMPTY_PARAMETERS = ["ttl", "partition_key", "sorting_key"]
25
26
  # * `N` is a number
26
27
  SIMPLE_TTL_DEFINITION = re.compile(r"""^([a-zA-Z0-9_\-\.\(\)\ \/\*]*) \+ (toInterval[a-zA-Z]*\([0-9]+\))$""")
27
28
 
29
+ # ClickHouse 25.8 quotes the engine name `Null`, as `null` is a keyword.
30
+ _BACKQUOTED_ENGINE_NAME = re.compile(r"^`(\w+)`")
31
+
28
32
 
29
33
  class TableDetails:
30
34
  """
@@ -78,6 +82,16 @@ class TableDetails:
78
82
 
79
83
  @property
80
84
  def engine_full(self) -> Optional[str]:
85
+ """
86
+ >>> TableDetails({"engine_full": "`Null`", "engine": "Null"}).engine_full
87
+ 'Null'
88
+ >>> TableDetails({"engine_full": "`Null`()", "engine": "Null"}).engine_full
89
+ 'Null()'
90
+ >>> TableDetails({"engine_full": "Null", "engine": "Null"}).to_json()
91
+ {'engine_full': 'Null', 'engine': 'Null'}
92
+ >>> TableDetails({"engine_full": "`Null`", "engine": "Null"}).to_json()
93
+ {'engine_full': 'Null', 'engine': 'Null'}
94
+ """
81
95
  _engine_full: Optional[str] = self.details.get("engine_full", None)
82
96
  if not _engine_full:
83
97
  return None
@@ -86,7 +100,7 @@ class TableDetails:
86
100
  # We cannot remove index_granularity = 8192 blindly because it might be followed by other settings
87
101
  if settings and settings.strip().lower() == "index_granularity = 8192":
88
102
  _engine_full = _engine_full.replace(" SETTINGS index_granularity = 8192", "")
89
- return engine_replicated_to_local(_engine_full)
103
+ return engine_replicated_to_local(_BACKQUOTED_ENGINE_NAME.sub(r"\1", _engine_full))
90
104
 
91
105
  @property
92
106
  def original_engine_full(self) -> Optional[str]:
@@ -776,17 +790,22 @@ def ttl_condition_from_engine_full(engine_full: Optional[str]) -> Optional[str]:
776
790
  return None
777
791
 
778
792
 
793
+ @functools.lru_cache(maxsize=1024)
794
+ def _index_lines(create_table_query_expr: str) -> tuple[str, ...]:
795
+ from tinybird.sql_toolset import format_sql
796
+
797
+ return tuple(
798
+ line.strip() for line in format_sql(create_table_query_expr).splitlines() if line.strip().startswith("INDEX")
799
+ )
800
+
801
+
779
802
  def _parse_indexes(create_table_query_expr: str) -> List[TableIndex]:
780
- if create_table_query_expr == "":
803
+ # format_sql is CPU-heavy and runs on the event loop. ClickHouse writes the
804
+ # INDEX keyword in uppercase in create_table_query.
805
+ if "INDEX" not in create_table_query_expr:
781
806
  return []
782
807
  try:
783
- from tinybird.sql_toolset import format_sql
784
-
785
- indexes = [
786
- line.strip()
787
- for line in format_sql(create_table_query_expr).splitlines()
788
- if line.strip().startswith("INDEX")
789
- ]
808
+ indexes = list(_index_lines(create_table_query_expr))
790
809
  except ModuleNotFoundError:
791
810
  # this is not needed from CLI
792
811
  return []
@@ -2173,9 +2173,14 @@ def parse(
2173
2173
  line = lines[lineno - 1]
2174
2174
  # shlex.shlex(line) removes comments that start with #. This doesn't affect multiline commands
2175
2175
  try:
2176
- sa = shlex.shlex(line)
2177
- sa.whitespace_split = True
2178
- lexer = list(sa)
2176
+ # Without quotes, escapes, or comment characters, str.split tokenizes
2177
+ # the same as shlex with whitespace_split=True, at a fraction of the cost.
2178
+ if '"' in line or "'" in line or "\\" in line or "#" in line:
2179
+ sa = shlex.shlex(line)
2180
+ sa.whitespace_split = True
2181
+ lexer = list(sa)
2182
+ else:
2183
+ lexer = line.split()
2179
2184
  except ValueError:
2180
2185
  sa = shlex.shlex(shlex.quote(line))
2181
2186
  sa.whitespace_split = True
tinybird/sql_template.py CHANGED
@@ -423,22 +423,29 @@ def array_type(types):
423
423
  return _f
424
424
 
425
425
 
426
- def sql_unescape(x, what=""):
426
+ def sql_unescape(x: str, what: str = "") -> Expression:
427
427
  """
428
428
  unescapes specific characters in a string. It allows to allow some
429
429
  special characters to be used, for example in like condictionals
430
430
 
431
431
  {{sql_unescape(String(like_filter), '%')}}
432
432
 
433
+ `what` must be given and must not contain quotes or backslashes: unescaping
434
+ those would let the caller close the string literal, so they stay escaped.
433
435
 
434
436
  >>> sql_unescape('testing%', '%')
435
437
  "'testing%'"
436
438
  >>> sql_unescape('testing%', '$')
437
439
  "'testing\\\\%'"
438
440
  >>> sql_unescape('testing"')
439
- '\\'testing"\\''
441
+ '\\'testing\\\\"\\''
442
+ >>> sql_unescape("x' OR 1=1", "'")
443
+ "'x\\\\' OR 1=1'"
440
444
  """
441
- return Expression("'" + sqlescape_for_string_expression(x).replace(f"\\{what}", what) + "'")
445
+ escaped = sqlescape_for_string_expression(x)
446
+ if what and not any(c in what for c in "'\"\\"):
447
+ escaped = escaped.replace(f"\\{what}", what)
448
+ return Expression("'" + escaped + "'")
442
449
 
443
450
 
444
451
  def split_to_array(x, default="", separator: str = ","):
tinybird/sql_toolset.py CHANGED
@@ -487,7 +487,7 @@ def replacements_to_tuples(replacements: dict) -> dict:
487
487
  return parsed_replacements
488
488
 
489
489
 
490
- @lru_cache(maxsize=2**15)
490
+ @lru_cache(maxsize=2**13)
491
491
  def replace_tables_chquery_cached(
492
492
  sql: str,
493
493
  sorted_replacements: Optional[tuple] = None,
tinybird/tb/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/forward/commands'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '4.6.24.dev0'
8
- __revision__ = '5269fe22'
7
+ __version__ = '4.6.25.dev0'
8
+ __revision__ = '57adbc63'
tinybird/tb/client.py CHANGED
@@ -925,7 +925,6 @@ class TinyB:
925
925
  assert_time_increase_percentage: Optional[float] = None,
926
926
  assert_bytes_read_increase_percentage: Optional[float] = None,
927
927
  assert_max_time: Optional[float] = None,
928
- run_in_main: Optional[bool] = False,
929
928
  ):
930
929
  test: Dict[str, Any] = {
931
930
  test_type: {
@@ -955,20 +954,12 @@ class TinyB:
955
954
  ]
956
955
 
957
956
  data = json.dumps(regression_commands)
958
- if run_in_main:
959
- url = f"/v0/environments/{branch_id}/regression/main"
960
- else:
961
- url = f"/v0/environments/{branch_id}/regression"
957
+ url = f"/v0/environments/{branch_id}/regression"
962
958
  return self._req(url, method="POST", data=data, headers={"Content-Type": "application/json"})
963
959
 
964
- def branch_regression_tests_file(
965
- self, branch_id: str, regression_commands: List[Dict[str, Any]], run_in_main: Optional[bool] = False
966
- ):
960
+ def branch_regression_tests_file(self, branch_id: str, regression_commands: List[Dict[str, Any]]):
967
961
  data = json.dumps(regression_commands)
968
- if run_in_main:
969
- url = f"/v0/environments/{branch_id}/regression/main"
970
- else:
971
- url = f"/v0/environments/{branch_id}/regression"
962
+ url = f"/v0/environments/{branch_id}/regression"
972
963
  return self._req(url, method="POST", data=data, headers={"Content-Type": "application/json"})
973
964
 
974
965
  def delete_workspace(self, id: str, hard_delete_confirmation: Optional[str], version: str = "v0"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 4.6.24.dev0
3
+ Version: 4.6.25.dev0
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -5,24 +5,24 @@ tinybird/git_settings.py,sha256=ETrcrvnhi3I9W-cGOwILXTBBNVFm5lYbeDdgTFaxT48,3898
5
5
  tinybird/prompts.py,sha256=FNYpphDYlrXpm5AQM3yfQPbj4gd_TVnwoaoeswtx0OE,32699
6
6
  tinybird/service_datasources.py,sha256=kNTlnSV6dngANVVDhFQsY77mlD5jKExy_YRC4Cw5rsQ,57555
7
7
  tinybird/sql.py,sha256=V807-z7tlZWMowr2ezYhsxjFWm-rWejaQ1mlr0ZXtPU,47173
8
- tinybird/sql_template.py,sha256=T9dcuB6vdYnw9BvpptIqo4MsWXbzn3O_uS6PoH0xmAM,133695
8
+ tinybird/sql_template.py,sha256=wxVDNCd0T5vmU4m3zM4HDORr8KVj6zZNnkK0FSF5icg,134046
9
9
  tinybird/sql_template_fmt.py,sha256=cOhhkA9h_M8II-06Qx5pt3E7IXUgzvrzfWGMtWdtkUM,10525
10
- tinybird/sql_toolset.py,sha256=gB6ZkQww8pU-7Zu2H1l7GHttPHkgqGhYBt6MfuhduDc,29926
10
+ tinybird/sql_toolset.py,sha256=ZLJUkqYxrvZOeKAoiItMYDjRat4qs9IH8CenbnglF1U,29926
11
11
  tinybird/syncasync.py,sha256=fFQ5GPPnUlTJ-J3VTw9AZCNXtp5IUiP9Q22sZXcixU4,26352
12
12
  tinybird/tornado_template.py,sha256=mTQMTywuqTfk9xX737mT5Fv_o-PNHJxpgTa4LF-edCE,49079
13
13
  tinybird/ch_utils/constants.py,sha256=8q5SH-0uBpYsBzmPpYsyhy-wcqvLgK1hmPr_NsKKoi8,4349
14
- tinybird/ch_utils/engine.py,sha256=XxBpukaupup8QEKWB7CPZu8c3r1NQuliA2ao85oWw8Y,37883
15
- tinybird/datafile/common.py,sha256=QZlhZhzRuVV1UAMQRzyogPjxA6YzgD1SGwrQdEJO6QE,112481
14
+ tinybird/ch_utils/engine.py,sha256=UAa7lFnAN5Wu25I-XyHKh23yGSQ7Ji4M_TvxpWv8q5o,38813
15
+ tinybird/datafile/common.py,sha256=SFZaWqXIIXhhotYcOJ1WQMbIbEaX7-woZ_kRCLJsBb0,112811
16
16
  tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1wnI,556
17
17
  tinybird/datafile/parse_connection.py,sha256=GxmGp_XnWbDZPDbh_PBxitlIMqZRYfDwxMBw-JQBp1g,1890
18
18
  tinybird/datafile/parse_datasource.py,sha256=yd58HrUF4yNJXLn6OsvKGpZJpvrcjLGAeJG1lgBe_zk,1891
19
19
  tinybird/datafile/parse_pipe.py,sha256=StMwF0Y1ny94hQxgPgcyx6-Jr46gCYBuPGpHF4bFiSQ,4956
20
20
  tinybird/iterating/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  tinybird/iterating/data_branch_modes.py,sha256=5YuDa-gr8mKwmES8Xro6TRKbQtaOtIw4GbC606Qhu3o,184
22
- tinybird/tb/__cli__.py,sha256=cSOtgXlDSfy7RTi_BRGXUDdv5zrVJUtpKIQ8hGf8tro,247
22
+ tinybird/tb/__cli__.py,sha256=w2oQQSHA2SaFm5tpT78ejMnV96YSCf7E8oPOmhK91YA,247
23
23
  tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
24
24
  tinybird/tb/cli.py,sha256=IjiGfNIpxSxi1odK1kMj9s8lEhx3sAUgGA263XdmyR0,1119
25
- tinybird/tb/client.py,sha256=gWlh7v_tB7n2VC-sNjVQqMByWIqaR9dLYRJe7pzpb-k,59866
25
+ tinybird/tb/client.py,sha256=feuyhQkCcpNbpBfJPOAIjviwEf7WS-WmLvN5BiQEqvs,59554
26
26
  tinybird/tb/config.py,sha256=l6NtYvSPZDVOtt1W4G4ExXXDIf0hm6lvRnRoDMbdrsY,5429
27
27
  tinybird/tb/modules/branch.py,sha256=U50nj2kZllCkOHQfJWQ-YQ260pvlcssgStMSovmqMiU,10157
28
28
  tinybird/tb/modules/build.py,sha256=q7-aVM7q1tApiax_y6vYSCZq4cJ9ATSAm9D-elpNp7I,6543
@@ -101,8 +101,8 @@ tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0L
101
101
  tinybird/tb_cli_modules/telemetry.py,sha256=W098H6jmS4kpE7hN3tadaREBTf7oMocel-lkKWN0pU8,10466
102
102
  tinybird/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
103
103
  tinybird/utils/bools.py,sha256=Rwuh_R6j62JVkcxKskLQao7DE2Jj6TQzsbgvtCsLHP4,587
104
- tinybird-4.6.24.dev0.dist-info/METADATA,sha256=kXHsAaCfmemek9Dj_XvDXDfgPZdb5Vy1fmf6qUcaBUY,18845
105
- tinybird-4.6.24.dev0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
106
- tinybird-4.6.24.dev0.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
107
- tinybird-4.6.24.dev0.dist-info/top_level.txt,sha256=ZIQJTPCzMqnfDzM_hEGZrJqDSEcKnIK_49T86DGWpyQ,78
108
- tinybird-4.6.24.dev0.dist-info/RECORD,,
104
+ tinybird-4.6.25.dev0.dist-info/METADATA,sha256=NLL52fOGJLUlFPBfxnkCAKBItbWpSUebBLMPEJiFQGU,18845
105
+ tinybird-4.6.25.dev0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
106
+ tinybird-4.6.25.dev0.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
107
+ tinybird-4.6.25.dev0.dist-info/top_level.txt,sha256=ZIQJTPCzMqnfDzM_hEGZrJqDSEcKnIK_49T86DGWpyQ,78
108
+ tinybird-4.6.25.dev0.dist-info/RECORD,,