tinybird-cli 5.8.0.dev2__py3-none-any.whl → 5.8.0.dev3__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://www.tinybird.co/docs/cli/introduction.html'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '5.8.0.dev2'
8
- __revision__ = 'edc984c'
7
+ __version__ = '5.8.0.dev3'
8
+ __revision__ = '43074f3'
tinybird/client.py CHANGED
@@ -474,6 +474,24 @@ class TinyB(object):
474
474
  async def datasource_sync(self, datasource_id: str):
475
475
  return await self._req(f"/v0/datasources/{datasource_id}/scheduling/runs", method="POST", data="")
476
476
 
477
+ async def datasource_scheduling_state(self, datasource_id: str):
478
+ response = await self._req(f"/v0/datasources/{datasource_id}/scheduling/state", method="GET")
479
+ return response["state"]
480
+
481
+ async def datasource_scheduling_pause(self, datasource_id: str):
482
+ return await self._req(
483
+ f"/v0/datasources/{datasource_id}/scheduling/state",
484
+ method="PUT",
485
+ data='{"state": "paused"}',
486
+ )
487
+
488
+ async def datasource_scheduling_resume(self, datasource_id: str):
489
+ return await self._req(
490
+ f"/v0/datasources/{datasource_id}/scheduling/state",
491
+ method="PUT",
492
+ data='{"state": "running"}',
493
+ )
494
+
477
495
  async def datasource_exchange(self, datasource_a: str, datasource_b: str):
478
496
  payload = {"datasource_a": datasource_a, "datasource_b": datasource_b}
479
497
  return await self._req("/v0/datasources/exchange", method="POST", data=payload)
@@ -157,6 +157,15 @@ class FeedbackManager:
157
157
  error_creating_copy_job = error_message("Failed creating copy job: {error}")
158
158
  error_pausing_copy_pipe = error_message("Failed pausing copy pipe: {error}")
159
159
  error_resuming_copy_pipe = error_message("Failed resuming copy pipe: {error}")
160
+ error_pausing_datasource_scheduling = error_message(
161
+ "Failed pausing scheduling for Data Source '{datasource}': {error}"
162
+ )
163
+ error_resuming_datasource_scheduling = error_message(
164
+ "Failed resuming scheduling for Data Source '{datasource}': {error}"
165
+ )
166
+ error_datasource_scheduling_state = error_message(
167
+ "Failed requesting scheduling state for Data Source '{datasource}': {error}"
168
+ )
160
169
  error_creating_pipe = error_message("Failed creating pipe {error}")
161
170
  error_creating_sink_job = error_message("Failed creating sink job: {error}")
162
171
  error_running_on_demand_sink_job = error_message("Failed running on-demand sink job: {error}")
@@ -681,6 +690,9 @@ Ready? """
681
690
  info_datasource_title = print_message("** {title}", bcolors.BOLD)
682
691
  info_datasource_row = info_message("{row}")
683
692
  info_datasource_delete_rows_job_url = info_message("** Delete rows job url {url}")
693
+ info_datasource_scheduling_state = info_message("** Scheduling state for Data Source '{datasource}': {state}")
694
+ info_datasource_scheduling_pause = info_message("** Pausing scheduling...")
695
+ info_datasource_scheduling_resume = info_message("** Resuming scheduling...")
684
696
  info_pipes = info_message("** Pipes:")
685
697
  info_pipe_name = info_message("** - {pipe}")
686
698
  info_using_node = print_message("** Using last node {node} as endpoint")
@@ -933,6 +945,8 @@ Ready? """
933
945
  success_datasource_unshared = success_message(
934
946
  "** The Data Source {datasource} has been correctly unshared from {workspace}"
935
947
  )
948
+ success_datasource_scheduling_resumed = success_message("""** Scheduling resumed for Data Source '{datasource}'""")
949
+ success_datasource_scheduling_paused = success_message("""** Scheduling paused for Data Source '{datasource}'""")
936
950
  success_connection_created = success_message("** Connection {id} created successfully!")
937
951
 
938
952
  # TODO: Update the message when the .env feature is implemented
tinybird/sql_template.py CHANGED
@@ -386,14 +386,14 @@ def array_type(types): # noqa: C901
386
386
  for i, t in enumerate(list_values):
387
387
  if _type in testers:
388
388
  if testers[_type](str(t)):
389
- values.append(expression_wrapper(types[_type](t), f"{x}[{i}]"))
389
+ values.append(expression_wrapper(types[_type](t), str(t)))
390
390
  else:
391
391
  raise SQLTemplateException(
392
392
  f"Error validating {x}[{i}]({t}) to type {_type}",
393
393
  documentation="/cli/advanced-templates.html",
394
394
  )
395
395
  else:
396
- values.append(expression_wrapper(types.get(_type, lambda x: x)(t), f"{x}[{i}]"))
396
+ values.append(expression_wrapper(types.get(_type, lambda x: x)(t), str(t)))
397
397
  return Expression(f"[{','.join(map(str, values))}]")
398
398
  except AttributeError as e:
399
399
  logging.warning(f"AttributeError on Array: {e}")
@@ -1314,8 +1314,9 @@ def expression_wrapper(x, name, escape_arrays: bool = False):
1314
1314
  elif isinstance(x, Comment):
1315
1315
  return "-- {x} \n"
1316
1316
  if x is None:
1317
+ truncated_name = name[:20] + "..." if len(name) > 20 else name
1317
1318
  raise SQLTemplateException(
1318
- f'expression "{name}" evaluated to null', documentation="/cli/advanced-templates.html"
1319
+ f'expression "{truncated_name}" evaluated to null', documentation="/cli/advanced-templates.html"
1319
1320
  )
1320
1321
  if isinstance(x, list) and escape_arrays:
1321
1322
  logging.warning(f"expression_wrapper -> list :{x}:")
@@ -1992,6 +1993,14 @@ def render_sql_template(
1992
1993
  Traceback (most recent call last):
1993
1994
  ...
1994
1995
  tinybird.sql_template.SQLTemplateException: Template Syntax Error: expression "test" evaluated to null
1996
+ >>> render_sql_template("SELECT {{testisasuperlongthingandwedontwanttoreturnthefullthing}}", {'token':'testing'})
1997
+ Traceback (most recent call last):
1998
+ ...
1999
+ tinybird.sql_template.SQLTemplateException: Template Syntax Error: expression "testisasuperlongthin..." evaluated to null
2000
+ >>> render_sql_template("SELECT {{ Array(embedding, 'Float32') }}", {'token':'testing', 'embedding': '1,2,3,4, null'})
2001
+ Traceback (most recent call last):
2002
+ ...
2003
+ tinybird.sql_template.SQLTemplateException: Template Syntax Error: Error validating 1,2,3,4, null[4]( null) to type Float32
1995
2004
  >>> render_sql_template('{% if test %}SELECT 1{% else %} select 2 {% end %}')
1996
2005
  (' select 2 ', {}, [])
1997
2006
  >>> render_sql_template('{% if Int32(test, 1) %}SELECT 1{% else %} select 2 {% end %}')
@@ -805,3 +805,65 @@ async def datasource_copy_from_main(
805
805
  if wait:
806
806
  base_msg = "Copy from Main Workspace" if sql_from_main else f"Copy from {sql}"
807
807
  await wait_job(client, job_id, job_url, f"{base_msg} to {datasource_name}")
808
+
809
+
810
+ @datasource.group(name="scheduling")
811
+ @click.pass_context
812
+ def datasource_scheduling(ctx: Context) -> None:
813
+ """Data Source scheduling commands."""
814
+
815
+
816
+ @datasource_scheduling.command(name="state")
817
+ @click.argument("datasource_name")
818
+ @click.pass_context
819
+ @coro
820
+ async def datasource_scheduling_state(ctx: Context, datasource_name: str) -> None:
821
+ """Get the scheduling state of a Data Source."""
822
+ client: TinyB = ctx.obj["client"]
823
+ try:
824
+ state = await client.datasource_scheduling_state(datasource_name)
825
+ click.echo(FeedbackManager.info_datasource_scheduling_state(datasource=datasource_name, state=state))
826
+ except Exception as e:
827
+ raise CLIDatasourceException(
828
+ FeedbackManager.error_datasource_scheduling_state(datasource=datasource_name, error=e)
829
+ )
830
+
831
+
832
+ @datasource_scheduling.command(name="pause")
833
+ @click.argument("datasource_name")
834
+ @click.pass_context
835
+ @coro
836
+ async def datasource_scheduling_pause(ctx: Context, datasource_name: str) -> None:
837
+ """Pause the scheduling of a Data Source."""
838
+
839
+ click.echo(FeedbackManager.info_datasource_scheduling_pause())
840
+ client: TinyB = ctx.ensure_object(dict)["client"]
841
+
842
+ try:
843
+ await client.datasource_scheduling_pause(datasource_name)
844
+ click.echo(FeedbackManager.success_datasource_scheduling_paused(datasource=datasource_name))
845
+
846
+ except Exception as e:
847
+ raise CLIDatasourceException(
848
+ FeedbackManager.error_pausing_datasource_scheduling(datasource=datasource_name, error=e)
849
+ )
850
+
851
+
852
+ @datasource_scheduling.command(name="resume")
853
+ @click.argument("datasource_name")
854
+ @click.pass_context
855
+ @coro
856
+ async def datasource_scheduling_resume(ctx: Context, datasource_name: str) -> None:
857
+ """Resume the scheduling of a Data Source."""
858
+
859
+ click.echo(FeedbackManager.info_datasource_scheduling_resume())
860
+ client: TinyB = ctx.ensure_object(dict)["client"]
861
+
862
+ try:
863
+ await client.datasource_scheduling_resume(datasource_name)
864
+ click.echo(FeedbackManager.success_datasource_scheduling_resumed(datasource=datasource_name))
865
+
866
+ except Exception as e:
867
+ raise CLIDatasourceException(
868
+ FeedbackManager.error_resuming_datasource_scheduling(datasource=datasource_name, error=e)
869
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird-cli
3
- Version: 5.8.0.dev2
3
+ Version: 5.8.0.dev3
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -51,6 +51,11 @@ The Tinybird command-line tool allows you to use all the Tinybird functionality
51
51
  Changelog
52
52
  ----------
53
53
 
54
+ 5.8.0.dev3
55
+ **********
56
+
57
+ - `Added` `tb datasource scheduling` commands to manage the scheduling of a Data Source
58
+
54
59
  5.8.0.dev2
55
60
  ***********
56
61
 
@@ -1,15 +1,15 @@
1
- tinybird/__cli__.py,sha256=8-80CmDRhb-4_YTzdpUFBsiHw0rKhtwr6X9QXQ6CfX4,254
1
+ tinybird/__cli__.py,sha256=36ABzbDg70Y06Sv5FPNSuv9HDzntouKP_j5iDzjx63Y,254
2
2
  tinybird/check_pypi.py,sha256=_4NkharLyR_ELrAdit-ftqIWvOf7jZNPt3i76frlo9g,975
3
- tinybird/client.py,sha256=Zk3kA0fT2lA1UBOWm2u170xBeR9ajVkdfn18JBIVk6Q,49914
3
+ tinybird/client.py,sha256=RVJ8jPkxRpG7vfPN3p_oO2t5IanzqTiRtBhwwaG2vJo,50607
4
4
  tinybird/config.py,sha256=LTHiR5JeAhslZCq4WaIZRW973KQMcEEC7TfN-uyS3wU,5397
5
5
  tinybird/connectors.py,sha256=lkpVSUmSuViEZBa4QjTK7YmPHUop0a5UFoTrSmlVq6k,15244
6
6
  tinybird/context.py,sha256=3KwB9TL-nON6qX9Mm5uev4CkrgLwYyNDvdFfQmNc0Cc,1171
7
7
  tinybird/datafile.py,sha256=CpM6r4ndsfUURrzwrqcidpIw6Dgvc9m-2KGmJk3UMPU,227385
8
8
  tinybird/datatypes.py,sha256=wwXaEy3l_UyfsH9xzYqBENQR7MSrFnDSvgS_CzLucOQ,10462
9
- tinybird/feedback_manager.py,sha256=LnjevE6ZlvYfk93_IeUuA8d0duV_HxV6fUVfMkYlWYw,66038
9
+ tinybird/feedback_manager.py,sha256=y2lWW5JZHh2F0jGCNnfM5w1gokIPn8_zPkiFHoIvyQE,66979
10
10
  tinybird/git_settings.py,sha256=vu8sWb3TAXeM8Tqy27aR0el8MnPm7kqQzTRV76xB0ro,4707
11
11
  tinybird/sql.py,sha256=hUnpfmkRkdyZV2ylIYflzxnwyv5Es7fLEv6cBc39OJA,41589
12
- tinybird/sql_template.py,sha256=Fo-bQNa2NvlGKMG4Mbkh19_giKYd7fV2oob9yZseYd8,89269
12
+ tinybird/sql_template.py,sha256=_E5Hrz8G7oe975eufD1B8xG-dr1u1rFJrp80yygJ0sQ,89929
13
13
  tinybird/sql_template_fmt.py,sha256=1z-PuqSZXtzso8Z_mPqUc-NxIxUrNUcVIPezNieZk-M,10196
14
14
  tinybird/sql_toolset.py,sha256=OIilqfV8o9uIOk6LetDwz4cePzLHKj-iiGvZou203SU,13777
15
15
  tinybird/syncasync.py,sha256=WlcT89npPwxcDEZ6kSF4ViZnyRwoEr74Jk1NDjhW83k,27819
@@ -24,7 +24,7 @@ tinybird/tb_cli_modules/cli.py,sha256=qfiy3jyHe7itzgJjUsphE4s64igXN_0hBddfsl0Fbb
24
24
  tinybird/tb_cli_modules/common.py,sha256=ym2P6ojiDg8gREKvY4IEDeAXFBhTQjoQrb-B5vIAy5c,87235
25
25
  tinybird/tb_cli_modules/config.py,sha256=6NTgIdwf0X132A1j6G_YrdPep87ymZ9b5pABabKLzh4,11484
26
26
  tinybird/tb_cli_modules/connection.py,sha256=Ur2EgXRC25idzcQqh9ayAL5K2KA2EepyavHuj9a4sBM,28306
27
- tinybird/tb_cli_modules/datasource.py,sha256=uqWMe5CamMM5GJAHhocB0XZyqQv6bOjwhrLkD3UzTNw,32312
27
+ tinybird/tb_cli_modules/datasource.py,sha256=WC4q4Lv-4zZT-mgAbGfWpgNXu7WXadh3en5HIl8fycc,34551
28
28
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
29
29
  tinybird/tb_cli_modules/fmt.py,sha256=Xn70KSFP79Huz3Cs7hpL64FSCkehyW1zrxp_gmSW6jw,3324
30
30
  tinybird/tb_cli_modules/job.py,sha256=AG69LPb9MbobA1awwJFZJvxqarDKfRlsBjw2V1zvYqc,2964
@@ -38,8 +38,8 @@ tinybird/tb_cli_modules/workspace.py,sha256=pGFyLeKLXG8PaqvBVBy707ckwGRBkXlmvRqC
38
38
  tinybird/tb_cli_modules/workspace_members.py,sha256=OeEypt5wtHrXBAV5AWtCl2UYuiG-9jgy-JDFUH4JphA,8612
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-5.8.0.dev2.dist-info/METADATA,sha256=cTpmdwWJWcWC9O87S01Jc1wJI7vpF4Cy8KEF1jUBFgA,75924
42
- tinybird_cli-5.8.0.dev2.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
43
- tinybird_cli-5.8.0.dev2.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
44
- tinybird_cli-5.8.0.dev2.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
45
- tinybird_cli-5.8.0.dev2.dist-info/RECORD,,
41
+ tinybird_cli-5.8.0.dev3.dist-info/METADATA,sha256=PJVXTlJET92VavYhWR-KkYHT4cTgKO7nTrgYycUYdDY,76036
42
+ tinybird_cli-5.8.0.dev3.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
43
+ tinybird_cli-5.8.0.dev3.dist-info/entry_points.txt,sha256=PKPKuPmA4IfJYnCFHHUiw-aAWZuBomFvwCklv1OyCjE,43
44
+ tinybird_cli-5.8.0.dev3.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
45
+ tinybird_cli-5.8.0.dev3.dist-info/RECORD,,