tinybird 0.0.1.dev151__tar.gz → 0.0.1.dev152__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.

Potentially problematic release.


This version of tinybird might be problematic. Click here for more details.

Files changed (109) hide show
  1. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/PKG-INFO +1 -1
  2. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/__cli__.py +2 -2
  3. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/create.py +54 -50
  4. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/common.py +8 -0
  5. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/mock.py +58 -30
  6. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/project.py +9 -0
  7. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/PKG-INFO +1 -1
  8. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/setup.cfg +0 -0
  9. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/__cli__.py +0 -0
  10. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/ch_utils/constants.py +0 -0
  11. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/ch_utils/engine.py +0 -0
  12. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/check_pypi.py +0 -0
  13. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/client.py +0 -0
  14. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/config.py +0 -0
  15. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/connectors.py +0 -0
  16. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/context.py +0 -0
  17. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/datafile.py +0 -0
  18. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/datatypes.py +0 -0
  19. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/feedback_manager.py +0 -0
  20. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/git_settings.py +0 -0
  21. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/prompts.py +0 -0
  22. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/sql.py +0 -0
  23. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/sql_template.py +0 -0
  24. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/sql_template_fmt.py +0 -0
  25. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/sql_toolset.py +0 -0
  26. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/syncasync.py +0 -0
  27. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/check_pypi.py +0 -0
  28. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/cli.py +0 -0
  29. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/client.py +0 -0
  30. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/config.py +0 -0
  31. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/auth.py +0 -0
  32. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/build.py +0 -0
  33. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/cicd.py +0 -0
  34. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/cli.py +0 -0
  35. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/common.py +0 -0
  36. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/config.py +0 -0
  37. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/connection.py +0 -0
  38. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/copy.py +0 -0
  39. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/build.py +0 -0
  40. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/build_common.py +0 -0
  41. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/build_datasource.py +0 -0
  42. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/build_pipe.py +0 -0
  43. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/diff.py +0 -0
  44. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/exceptions.py +0 -0
  45. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/fixture.py +0 -0
  46. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/format_common.py +0 -0
  47. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/format_datasource.py +0 -0
  48. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/format_pipe.py +0 -0
  49. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/parse_datasource.py +0 -0
  50. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/parse_pipe.py +0 -0
  51. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/pipe_checker.py +0 -0
  52. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/playground.py +0 -0
  53. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datafile/pull.py +0 -0
  54. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/datasource.py +0 -0
  55. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/deployment.py +0 -0
  56. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/deprecations.py +0 -0
  57. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/endpoint.py +0 -0
  58. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/exceptions.py +0 -0
  59. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/feedback_manager.py +0 -0
  60. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/infra.py +0 -0
  61. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/job.py +0 -0
  62. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/llm.py +0 -0
  63. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/llm_utils.py +0 -0
  64. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/local.py +0 -0
  65. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/local_common.py +0 -0
  66. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/login.py +0 -0
  67. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/logout.py +0 -0
  68. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/materialization.py +0 -0
  69. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/open.py +0 -0
  70. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/pipe.py +0 -0
  71. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/regions.py +0 -0
  72. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/secret.py +0 -0
  73. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/shell.py +0 -0
  74. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/table.py +0 -0
  75. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/telemetry.py +0 -0
  76. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/test.py +0 -0
  77. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/tinyunit/tinyunit.py +0 -0
  78. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/tinyunit/tinyunit_lib.py +0 -0
  79. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/token.py +0 -0
  80. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/watch.py +0 -0
  81. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/workspace.py +0 -0
  82. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb/modules/workspace_members.py +0 -0
  83. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli.py +0 -0
  84. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/auth.py +0 -0
  85. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/branch.py +0 -0
  86. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/cicd.py +0 -0
  87. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/cli.py +0 -0
  88. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/common.py +0 -0
  89. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/config.py +0 -0
  90. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/connection.py +0 -0
  91. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/datasource.py +0 -0
  92. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/exceptions.py +0 -0
  93. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/fmt.py +0 -0
  94. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/job.py +0 -0
  95. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/pipe.py +0 -0
  96. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/regions.py +0 -0
  97. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/tag.py +0 -0
  98. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/telemetry.py +0 -0
  99. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/test.py +0 -0
  100. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
  101. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +0 -0
  102. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/workspace.py +0 -0
  103. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tb_cli_modules/workspace_members.py +0 -0
  104. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird/tornado_template.py +0 -0
  105. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/SOURCES.txt +0 -0
  106. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/dependency_links.txt +0 -0
  107. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/entry_points.txt +0 -0
  108. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/requires.txt +0 -0
  109. {tinybird-0.0.1.dev151 → tinybird-0.0.1.dev152}/tinybird.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev151
3
+ Version: 0.0.1.dev152
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -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__ = '0.0.1.dev151'
8
- __revision__ = 'd9da445'
7
+ __version__ = '0.0.1.dev152'
8
+ __revision__ = '100f32b'
@@ -1,3 +1,4 @@
1
+ import glob
1
2
  import os
2
3
  import re
3
4
  from pathlib import Path
@@ -5,7 +6,7 @@ from typing import Any, Dict, Optional, Tuple
5
6
 
6
7
  import click
7
8
 
8
- from tinybird.prompts import create_prompt, mock_prompt, readme_prompt, rules_prompt
9
+ from tinybird.prompts import create_prompt, readme_prompt, rules_prompt
9
10
  from tinybird.tb.client import TinyB
10
11
  from tinybird.tb.modules.cicd import init_cicd
11
12
  from tinybird.tb.modules.cli import cli
@@ -17,6 +18,7 @@ from tinybird.tb.modules.feedback_manager import FeedbackManager
17
18
  from tinybird.tb.modules.llm import LLM
18
19
  from tinybird.tb.modules.llm_utils import extract_xml, parse_xml
19
20
  from tinybird.tb.modules.local_common import get_tinybird_local_client
21
+ from tinybird.tb.modules.mock import create_mock_data
20
22
  from tinybird.tb.modules.project import Project
21
23
 
22
24
 
@@ -83,7 +85,7 @@ async def create(
83
85
 
84
86
  if data or (prompt and user_token):
85
87
  click.echo(FeedbackManager.highlight(message="\n» Creating resources..."))
86
- result, created_something = await create_resources(tb_client, user_token, data, prompt, folder, ctx_config)
88
+ result, created_something = await create_resources(tb_client, user_token, data, prompt, project, ctx_config)
87
89
  click.echo(FeedbackManager.success(message="✓ Done!\n"))
88
90
  if prompt:
89
91
  readme_path = Path(root_folder) / "README.md"
@@ -132,22 +134,26 @@ async def create(
132
134
  persist_fixture(ds_name, data_content, folder, format=data_format)
133
135
  created_something = True
134
136
  elif prompt and user_token:
135
- datasource_files = [f for f in os.listdir(Path(folder) / "datasources") if f.endswith(".datasource")]
136
- for datasource_file in datasource_files:
137
- datasource_path = Path(folder) / "datasources" / datasource_file
138
- llm = LLM(user_token=user_token, host=tb_client.host)
137
+ for datasource_file in project.get_datasource_files():
138
+ datasource_path = Path(datasource_file)
139
139
  datasource_name = datasource_path.stem
140
140
  datasource_content = datasource_path.read_text()
141
141
  has_json_path = "`json:" in datasource_content
142
142
  if has_json_path:
143
- prompt = f"<datasource_schema>{datasource_content}</datasource_schema>"
144
- response = llm.ask(system_prompt=mock_prompt(rows), prompt=prompt)
145
- sql = extract_xml(response, "sql")
146
- sql = sql.split("FORMAT")[0]
147
- query_result = await tb_client.query(f"{sql} FORMAT JSON")
148
- data = query_result.get("data", [])
149
- if data:
150
- persist_fixture(datasource_name, data, folder, format="ndjson")
143
+ mock_data = await create_mock_data(
144
+ datasource_name,
145
+ datasource_content,
146
+ rows,
147
+ prompt,
148
+ config,
149
+ ctx_config,
150
+ user_token,
151
+ tb_client,
152
+ format_="ndjson",
153
+ folder=project.folder,
154
+ )
155
+ if mock_data:
156
+ persist_fixture(datasource_name, mock_data, folder, format="ndjson")
151
157
  click.echo(FeedbackManager.info(message=f"✓ /fixtures/{datasource_name}"))
152
158
  created_something = True
153
159
 
@@ -204,12 +210,12 @@ async def create_resources(
204
210
  user_token: Optional[str],
205
211
  data: Optional[str],
206
212
  prompt: Optional[str],
207
- folder: str,
213
+ project: Project,
208
214
  config: Dict[str, Any],
209
215
  ) -> Tuple[str, bool]:
210
216
  result = ""
211
217
  created_any_resource = False
212
- folder_path = Path(folder)
218
+ folder_path = project.path
213
219
  if data:
214
220
  local_client = await get_tinybird_local_client(config)
215
221
  path = folder_path / data
@@ -224,7 +230,7 @@ SQL >
224
230
  SELECT * from {name}
225
231
  TYPE ENDPOINT
226
232
  """,
227
- folder,
233
+ project.folder,
228
234
  )
229
235
  result = (
230
236
  f"<response><resource><type>datasource</type><name>{name}</name><content></content></resource></response>"
@@ -232,19 +238,9 @@ TYPE ENDPOINT
232
238
  created_any_resource = True
233
239
 
234
240
  elif prompt and user_token:
235
- datasource_paths = [
236
- Path(folder) / "datasources" / f
237
- for f in os.listdir(Path(folder) / "datasources")
238
- if f.endswith(".datasource")
239
- ]
240
- pipes_paths = [
241
- Path(folder) / "endpoints" / f for f in os.listdir(Path(folder) / "endpoints") if f.endswith(".pipe")
242
- ]
243
- connections_paths = [
244
- Path(folder) / "connections" / f
245
- for f in os.listdir(Path(folder) / "connections")
246
- if f.endswith(".connection")
247
- ]
241
+ datasource_paths = [Path(ds_file) for ds_file in project.get_datasource_files()]
242
+ pipes_paths = [Path(pipe_file) for pipe_file in project.get_pipe_files()]
243
+ connections_paths = [Path(conn_file) for conn_file in project.get_connection_files()]
248
244
  resources_xml = "\n".join(
249
245
  [
250
246
  f"<resource><type>{resource_type}</type><name>{resource_name}</name><content>{resource_content}</content></resource>"
@@ -300,19 +296,19 @@ TYPE ENDPOINT
300
296
  data=None,
301
297
  _format="ndjson",
302
298
  force=True,
303
- folder=folder,
299
+ folder=project.folder,
304
300
  )
305
301
  created_any_resource = True
306
302
 
307
303
  for pipe in pipes:
308
304
  content = pipe["content"].replace("```", "")
309
- generate_pipe_file(pipe["name"], content, folder)
305
+ generate_pipe_file(pipe["name"], content, project.folder)
310
306
  created_any_resource = True
311
307
 
312
308
  for conn in connections:
313
309
  content = conn["content"].replace("```", "")
314
310
  filename = f"{conn['name']}.connection"
315
- generate_connection_file(conn["name"], content, folder)
311
+ generate_connection_file(conn["name"], content, project.folder)
316
312
  created_any_resource = True
317
313
 
318
314
  return result, created_any_resource
@@ -348,21 +344,25 @@ def generate_pipe_file(name: str, content: str, folder: str) -> Path:
348
344
  def is_endpoint(content: str) -> bool:
349
345
  return re.search(r"TYPE endpoint", content, re.IGNORECASE) is not None
350
346
 
351
- if is_copy(content):
352
- pathname = "copies"
353
- elif is_materialization(content):
354
- pathname = "materializations"
355
- elif is_sink(content):
356
- pathname = "sinks"
357
- elif is_endpoint(content):
358
- pathname = "endpoints"
347
+ already_exists = glob.glob(f"{folder}/**/{name}.pipe")
348
+ if already_exists:
349
+ f = Path(already_exists[0])
359
350
  else:
360
- pathname = "pipes"
351
+ if is_copy(content):
352
+ pathname = "copies"
353
+ elif is_materialization(content):
354
+ pathname = "materializations"
355
+ elif is_sink(content):
356
+ pathname = "sinks"
357
+ elif is_endpoint(content):
358
+ pathname = "endpoints"
359
+ else:
360
+ pathname = "pipes"
361
361
 
362
- base = Path(folder) / pathname
363
- if not base.exists():
364
- base.mkdir()
365
- f = base / (f"{name}.pipe")
362
+ base = Path(folder) / pathname
363
+ if not base.exists():
364
+ base.mkdir()
365
+ f = base / (f"{name}.pipe")
366
366
  with open(f"{f}", "w") as file:
367
367
  file.write(content)
368
368
  click.echo(FeedbackManager.info_file_created(file=f.relative_to(folder)))
@@ -370,10 +370,14 @@ def generate_pipe_file(name: str, content: str, folder: str) -> Path:
370
370
 
371
371
 
372
372
  def generate_connection_file(name: str, content: str, folder: str, skip_feedback: bool = False) -> Path:
373
- base = Path(folder) / "connections"
374
- if not base.exists():
375
- base.mkdir()
376
- f = base / (f"{name}.connection")
373
+ already_exists = glob.glob(f"{folder}/**/{name}.connection")
374
+ if already_exists:
375
+ f = Path(already_exists[0])
376
+ else:
377
+ base = Path(folder) / "connections"
378
+ if not base.exists():
379
+ base.mkdir()
380
+ f = base / (f"{name}.connection")
377
381
  with open(f"{f}", "w") as file:
378
382
  file.write(content)
379
383
  if not skip_feedback:
@@ -846,6 +846,14 @@ def _parse_table_structure(schema: str) -> List[Dict[str, Any]]:
846
846
  lineno=line,
847
847
  pos=pos,
848
848
  )
849
+ if detected_type in ("Int", "UInt"):
850
+ t = detected_type
851
+ raise SchemaSyntaxError(
852
+ message=f"Precision is mandatory for {t} types",
853
+ hint=f"Hint: use one of {t}8, {t}16, {t}32, {t}64, {t}128, {t}256",
854
+ lineno=line,
855
+ pos=pos - len(t),
856
+ )
849
857
 
850
858
  try:
851
859
  # Imported in the body to be compatible with the CLI
@@ -1,5 +1,6 @@
1
1
  import glob
2
2
  from pathlib import Path
3
+ from typing import Any, Dict, List
3
4
 
4
5
  import click
5
6
 
@@ -65,41 +66,23 @@ async def mock(ctx: click.Context, datasource: str, rows: int, prompt: str, form
65
66
 
66
67
  datasource_content = datasource_path.read_text()
67
68
  config = CLIConfig.get_project_config()
68
- user_client = config.get_client(token=ctx_config.get("token"), host=ctx_config.get("host"))
69
69
  user_token = ctx_config.get("user_token")
70
70
 
71
71
  if not user_token:
72
72
  raise Exception("This action requires authentication. Run 'tb login' first.")
73
73
 
74
- llm = LLM(user_token=user_token, host=user_client.host)
75
- prompt = f"<datasource_schema>{datasource_content}</datasource_schema>\n<user_input>{prompt}</user_input>"
76
- sql = ""
77
- attempts = 0
78
- data = []
79
- error = ""
80
- sql_path = None
81
- while True:
82
- try:
83
- response = llm.ask(system_prompt=mock_prompt(rows, error), prompt=prompt)
84
- sql = extract_xml(response, "sql")
85
- sql_path = persist_fixture_sql(datasource_name, sql, folder)
86
- sql_format = "JSON" if format_ == "ndjson" else "CSV"
87
- result = await tb_client.query(f"SELECT * FROM ({sql}) LIMIT {rows} FORMAT {sql_format}")
88
- if sql_format == "JSON":
89
- data = result.get("data", [])[:rows]
90
- error_response = result.get("error", None)
91
- if error_response:
92
- raise Exception(error_response)
93
- else:
94
- data = result
95
- break
96
- except Exception as e:
97
- error = str(e)
98
- attempts += 1
99
- if attempts > 5:
100
- raise Exception(f"Failed to generate a valid solution. Check {str(sql_path)} and try again.")
101
- else:
102
- continue
74
+ data = await create_mock_data(
75
+ datasource_name,
76
+ datasource_content,
77
+ rows,
78
+ prompt,
79
+ config,
80
+ ctx_config,
81
+ user_token,
82
+ tb_client,
83
+ format_,
84
+ folder,
85
+ )
103
86
 
104
87
  fixture_path = persist_fixture(datasource_name, data, folder, format=format_)
105
88
  click.echo(FeedbackManager.info(message=f"✓ /fixtures/{datasource_name}.{format_} created"))
@@ -125,3 +108,48 @@ async def append_fixture(
125
108
  concurrency=1,
126
109
  silent=True,
127
110
  )
111
+
112
+
113
+ async def create_mock_data(
114
+ datasource_name: str,
115
+ datasource_content: str,
116
+ rows: int,
117
+ prompt: str,
118
+ config: CLIConfig,
119
+ ctx_config: Dict[str, Any],
120
+ user_token: str,
121
+ tb_client: TinyB,
122
+ format_: str,
123
+ folder: str,
124
+ ) -> List[Dict[str, Any]]:
125
+ user_client = config.get_client(token=ctx_config.get("token"), host=ctx_config.get("host"))
126
+ llm = LLM(user_token=user_token, host=user_client.host)
127
+ prompt = f"<datasource_schema>{datasource_content}</datasource_schema>\n<user_input>{prompt}</user_input>"
128
+ sql = ""
129
+ attempts = 0
130
+ data = []
131
+ error = ""
132
+ sql_path = None
133
+ while True:
134
+ try:
135
+ response = llm.ask(system_prompt=mock_prompt(rows, error), prompt=prompt)
136
+ sql = extract_xml(response, "sql")
137
+ sql_path = persist_fixture_sql(datasource_name, sql, folder)
138
+ sql_format = "JSON" if format_ == "ndjson" else "CSV"
139
+ result = await tb_client.query(f"SELECT * FROM ({sql}) LIMIT {rows} FORMAT {sql_format}")
140
+ if sql_format == "JSON":
141
+ data = result.get("data", [])[:rows]
142
+ error_response = result.get("error", None)
143
+ if error_response:
144
+ raise Exception(error_response)
145
+ else:
146
+ data = result
147
+ break
148
+ except Exception as e:
149
+ error = str(e)
150
+ attempts += 1
151
+ if attempts > 5:
152
+ raise Exception(f"Failed to generate a valid solution. Check {str(sql_path)} and try again.")
153
+ else:
154
+ continue
155
+ return data
@@ -55,6 +55,15 @@ class Project:
55
55
  def connections(self) -> List[str]:
56
56
  return sorted([Path(f).stem for f in glob.glob(f"{self.path}/**/*.connection", recursive=False)])
57
57
 
58
+ def get_datasource_files(self) -> List[str]:
59
+ return glob.glob(f"{self.path}/**/*.datasource", recursive=False)
60
+
61
+ def get_pipe_files(self) -> List[str]:
62
+ return glob.glob(f"{self.path}/**/*.pipe", recursive=False)
63
+
64
+ def get_connection_files(self) -> List[str]:
65
+ return glob.glob(f"{self.path}/**/*.connection", recursive=False)
66
+
58
67
  def get_pipe_datafile(self, filename: str) -> Optional[Datafile]:
59
68
  try:
60
69
  return parse_pipe(filename).datafile
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev151
3
+ Version: 0.0.1.dev152
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird