tinybird-cli 3.3.1.dev12__py3-none-any.whl → 3.3.1.dev14__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.
tinybird/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://docs.tinybird.co/cli.html'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '3.3.1.dev12'
8
- __revision__ = '059af77'
7
+ __version__ = '3.3.1.dev14'
8
+ __revision__ = '5fde94c'
@@ -1,9 +1,10 @@
1
1
  import logging
2
2
  import re
3
3
  from collections import defaultdict
4
+ from dataclasses import asdict
4
5
  from typing import Any, Callable, Dict, Iterable, List, Optional
5
6
 
6
- from ..sql import col_name, engine_replicated_to_local, parse_table_structure
7
+ from ..sql import TableIndex, col_name, engine_replicated_to_local, parse_indices_structure, parse_table_structure
7
8
 
8
9
  DEFAULT_EMPTY_PARAMETERS = ["ttl", "partition_key", "sorting_key"]
9
10
  DEFAULT_JOIN_EMPTY_PARAMETERS = ["join_strictness", "join_type", "key_columns"]
@@ -204,6 +205,10 @@ class TableDetails:
204
205
  "row_count": self.details.get("total_rows", None),
205
206
  }
206
207
 
208
+ @property
209
+ def indices(self) -> List[TableIndex]:
210
+ return _parse_indices(str(self.details.get("create_table_query", "")))
211
+
207
212
  def to_json(self, exclude: Optional[List[str]] = None, include_empty_details: bool = False):
208
213
  # name, database are not exported since they are not part of the engine
209
214
  d: Dict[str, Any] = {
@@ -234,6 +239,8 @@ class TableDetails:
234
239
  d["version"] = self.version
235
240
  if self.ttl:
236
241
  d["ttl"] = self.ttl.strip()
242
+ if self.indices:
243
+ d["indices"] = [asdict(index) for index in self.indices]
237
244
 
238
245
  if self.engine_full:
239
246
  engine_params = engine_params_from_engine_full(self.engine_full)
@@ -253,7 +260,9 @@ class TableDetails:
253
260
  return d
254
261
 
255
262
  def to_datafile(self, include_empty_details: bool = False) -> str:
256
- d: Dict[str, Any] = self.to_json(exclude=["engine", "engine_full"], include_empty_details=include_empty_details)
263
+ d: Dict[str, Any] = self.to_json(
264
+ exclude=["engine", "engine_full", "indices"], include_empty_details=include_empty_details
265
+ )
257
266
  engine: str = self.engine
258
267
 
259
268
  datafile: str = ""
@@ -774,3 +783,21 @@ def ttl_condition_from_engine_full(engine_full: Optional[str]) -> Optional[str]:
774
783
  except Exception as e:
775
784
  logging.error(str(e))
776
785
  return None
786
+
787
+
788
+ def _parse_indices(create_table_query_expr: str) -> List[TableIndex]:
789
+ if create_table_query_expr == "":
790
+ return []
791
+ try:
792
+ from tinybird.sql_toolset import format_sql
793
+
794
+ indices = [
795
+ line.strip()
796
+ for line in format_sql(create_table_query_expr).splitlines()
797
+ if line.strip().startswith("INDEX")
798
+ ]
799
+ except ModuleNotFoundError:
800
+ # this is not needed from CLI
801
+ return []
802
+
803
+ return parse_indices_structure(indices)
tinybird/datafile.py CHANGED
@@ -65,7 +65,7 @@ from tinybird.tb_cli_modules.exceptions import CLIGitReleaseException, CLIPipeEx
65
65
  from .ch_utils.engine import ENABLED_ENGINES
66
66
  from .client import AuthException, CanNotBeDeletedException, DoesNotExistException, TinyB
67
67
  from .feedback_manager import FeedbackManager
68
- from .sql import parse_table_structure, schema_to_sql_columns
68
+ from .sql import parse_indices_structure, parse_table_structure, schema_to_sql_columns
69
69
  from .sql_template import get_used_tables_in_template, render_sql_template
70
70
  from .tornado_template import UnClosedIfError
71
71
 
@@ -824,6 +824,17 @@ def parse(
824
824
  parser_state.current_node["schema"] = ",".join(schema_to_sql_columns(sh))
825
825
  parser_state.current_node["columns"] = sh
826
826
 
827
+ def indices(*args, **kwargs):
828
+ s = _unquote("".join(args))
829
+ if not s:
830
+ return
831
+ try:
832
+ indices = parse_indices_structure(s.splitlines())
833
+ except Exception as e:
834
+ raise ParseException(FeedbackManager.error_parsing_indices(line=kwargs["lineno"], error=e))
835
+
836
+ parser_state.current_node["indices"] = indices
837
+
827
838
  def assign_var(v: str) -> Callable[[VarArg(str), KwArg(Any)], None]:
828
839
  def _f(*args: str, **kwargs: Any):
829
840
  s = _unquote((" ".join(args)).strip())
@@ -970,6 +981,7 @@ def parse(
970
981
  "source": sources,
971
982
  "maintainer": assign("maintainer"),
972
983
  "schema": schema,
984
+ "indices": indices,
973
985
  "engine": set_engine,
974
986
  "partition_key": assign_var("partition_key"),
975
987
  "sorting_key": assign_var("sorting_key"),
@@ -1307,10 +1319,16 @@ async def process_file(
1307
1319
  return name
1308
1320
 
1309
1321
  description = node.get("description", "")
1322
+ indices_list = node.get("indices", [])
1323
+ indices = None
1324
+ if indices_list:
1325
+ indices = "\n".join([index.to_sql() for index in indices_list])
1310
1326
  params = {
1311
1327
  "name": append_version_to_name(name, version),
1312
1328
  "description": description,
1313
1329
  "schema": schema,
1330
+ "indices": indices,
1331
+ "indices_list": indices_list,
1314
1332
  "format": _format,
1315
1333
  }
1316
1334
 
@@ -96,6 +96,9 @@ class FeedbackManager:
96
96
  error_pull = error_message("there was a problem while pulling: {error}")
97
97
  error_parsing_file = error_message("error parsing {filename}:{lineno} {error}")
98
98
  error_parsing_schema = error_message("error parsing schema (line {line}): {error}")
99
+ error_parsing_indices = error_message(
100
+ "error parsing indices (line {line}): {error}. Usage: `name expr TYPE type_full GRANULARITY granularity`. Separate multiple indices by a new line."
101
+ )
99
102
  error_sorting_key = error_message("SORTING_KEY should be set with {engine}")
100
103
  error_unknown_resource = error_message("Unknown resource '{resource}'")
101
104
  error_file_extension = error_message(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird-cli
3
- Version: 3.3.1.dev12
3
+ Version: 3.3.1.dev14
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://docs.tinybird.co/cli.html
6
6
  Author: Tinybird
@@ -52,6 +52,16 @@ Changelog
52
52
 
53
53
  ---------
54
54
 
55
+ 3.3.1.dev14
56
+ ************
57
+
58
+ - `Added` Support `tb deploy` .datasource with `INDICES`
59
+
60
+ 3.3.1.dev13
61
+ ************
62
+
63
+ - `Added` Support `tb push` .datasource with `INDICES`
64
+
55
65
  3.3.1.dev12
56
66
  ************
57
67
 
@@ -60,7 +70,7 @@ Changelog
60
70
  3.3.1.dev11
61
71
  ************
62
72
 
63
- - `Add` Check backfill on preview is required when `tb deploy` modified datasources. Disable check with `TB_CHECK_BACKFILL_REQUIRED=0`.
73
+ - `Added` Check backfill on preview is required when `tb deploy` modified datasources. Disable check with `TB_CHECK_BACKFILL_REQUIRED=0`.
64
74
 
65
75
  3.3.1.dev10
66
76
  ************
@@ -1,13 +1,13 @@
1
- tinybird/__cli__.py,sha256=KRIjqk_5xPZ1L4o_pIx0mX1JXXmiFF-A__D9XkbEtdE,238
1
+ tinybird/__cli__.py,sha256=MRI1KpxSe_rofDh_2zh_cT5MtvWxbS-pKdAMOAjMUSE,238
2
2
  tinybird/check_pypi.py,sha256=_4NkharLyR_ELrAdit-ftqIWvOf7jZNPt3i76frlo9g,975
3
3
  tinybird/client.py,sha256=iLQHu8tVUZ25U3DeWTxO2vAhsy-pko1XDX2r0xNoays,46468
4
4
  tinybird/config.py,sha256=E0jDwbFD1zhdijNhtF8fg6mqIyKbZ8xpNPP_3n2PFpE,2003
5
5
  tinybird/connector_settings.py,sha256=js2LvL8bAv5PegDICWB6EQ-LhqhAQU9VPApU1dW0vyA,6258
6
6
  tinybird/connectors.py,sha256=lkpVSUmSuViEZBa4QjTK7YmPHUop0a5UFoTrSmlVq6k,15244
7
7
  tinybird/context.py,sha256=604s0gs82KfNzdVoGSuAUTLZqPslPVHuBZb0PdowX_I,853
8
- tinybird/datafile.py,sha256=vtUFa972q5jIJFiWoNH1a5Dok-CDULSHplhMWwf8yBk,206483
8
+ tinybird/datafile.py,sha256=EunuL98NmOe8ocVJorALq9ubs1n5RbjzFQbplZ06QIk,207155
9
9
  tinybird/datatypes.py,sha256=adYOQBTyfeBGVINIlaRex_81gTQQuqF2M9VTQpzq1H0,7060
10
- tinybird/feedback_manager.py,sha256=iCDhtnSCqd_jEu5vRw6I0Hij8k-NmJavlDIQeKMG8GI,55661
10
+ tinybird/feedback_manager.py,sha256=7JAPUmgDXHg4mzRqhUeWpyesb9GYCUqm_nvsPCFGf-U,55866
11
11
  tinybird/git_settings.py,sha256=JsnUVBTMEKFh3WLUxrih7TKoGzQJCita6I_bZd-p36A,4424
12
12
  tinybird/sql.py,sha256=fEVF2pi8zkgCCREWDhUbaHku5fBQYW_YTNflVF9Q17o,41181
13
13
  tinybird/sql_template.py,sha256=BnIh7kDl3W4PViak7jaa6S8h7xlY7dQnELK6GwqHfrY,74896
@@ -17,7 +17,7 @@ tinybird/syncasync.py,sha256=fAvq0qkRgqXqXMKwbY2iJNYqLT_r6mDsh1MRpGKrdRU,27763
17
17
  tinybird/tb_cli.py,sha256=XPyQ8QQ85ohpfVv7ZGzZjIbeijFZEzWQDwCz5zVpZ_U,674
18
18
  tinybird/tornado_template.py,sha256=0CMUKHZXMfe86mKgEWSuQdYG1ptRfJCg8TGnUjhOJlc,41970
19
19
  tinybird/ch_utils/constants.py,sha256=QtaTrpYsmxnlogsC57YEnkrbw22t9hx6ueCvl6qD9f4,3657
20
- tinybird/ch_utils/engine.py,sha256=LzQxPraFN7tTl6YP-xwd3Z2o3BjjD4VNqWDrreC4koI,37634
20
+ tinybird/ch_utils/engine.py,sha256=GDICiBGV1jup9Mmt_xRfg_HiWZnrrQplF8UmbDK8VVY,38465
21
21
  tinybird/data_connectors/credentials.py,sha256=c52x4f6PTORcnoDJAtYC186GYBbTzdbEY3bi79OrCaU,638
22
22
  tinybird/tb_cli_modules/auth.py,sha256=joR1uS821o2bPTpgDyMCYed9Kw7MutR0aa-YvmIb4zA,8561
23
23
  tinybird/tb_cli_modules/branch.py,sha256=5d0lDMxUOt68BK5rmcVCxPYshdUfs42oz_sxIn9NSsk,37863
@@ -38,8 +38,8 @@ tinybird/tb_cli_modules/workspace.py,sha256=NDHINzW3SBo8FcWH8Bx-DCeUXQ8YUJX6FW8c
38
38
  tinybird/tb_cli_modules/workspace_members.py,sha256=6oZM7oJQPxDMycL95TPtALriL5WRI2DhNlQWD8MP8JU,8205
39
39
  tinybird/tb_cli_modules/tinyunit/tinyunit.py,sha256=0dYYmZMMJVubxSPls2e_a-fqtUYvgLfu2B0xwLfkbHw,11667
40
40
  tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py,sha256=j92za8QbXrv4eIPjKBZPn9ghR-nYQ2wZZ88MeXyMWXE,1868
41
- tinybird_cli-3.3.1.dev12.dist-info/METADATA,sha256=yRZd9saF3rnAEthxWsKPeu2M6JKlpQSnWsbGaougXP0,67667
42
- tinybird_cli-3.3.1.dev12.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
43
- tinybird_cli-3.3.1.dev12.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
44
- tinybird_cli-3.3.1.dev12.dist-info/top_level.txt,sha256=8TRt5snq9vZpx4rBBc9EWpj76Er6IAdfnx_Eq6cNBk8,45
45
- tinybird_cli-3.3.1.dev12.dist-info/RECORD,,
41
+ tinybird_cli-3.3.1.dev14.dist-info/METADATA,sha256=e6QOrUL72DNu23afm8nJOwAuIuy3VklNzuN49C8hgYU,67835
42
+ tinybird_cli-3.3.1.dev14.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
43
+ tinybird_cli-3.3.1.dev14.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
44
+ tinybird_cli-3.3.1.dev14.dist-info/top_level.txt,sha256=8TRt5snq9vZpx4rBBc9EWpj76Er6IAdfnx_Eq6cNBk8,45
45
+ tinybird_cli-3.3.1.dev14.dist-info/RECORD,,