tinybird 0.0.1.dev24__py3-none-any.whl → 0.0.1.dev25__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.

Potentially problematic release.


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

tinybird/prompts.py CHANGED
@@ -117,6 +117,93 @@ FROM numbers({rows})
117
117
  - Do NOT add a semicolon at the end of the query
118
118
  - Do NOT add any FORMAT at the end of the query, because it will be added later by Tinybird.
119
119
 
120
+ # Examples with different schemas, like an array field or a nested JSON field:
121
+
122
+ ## Example schema with an array field:
123
+
124
+ ### Schema:
125
+
126
+ SCHEMA >
127
+ `order_id` UInt64 `json:$.order_id`,
128
+ `customer_id` UInt64 `json:$.customer_id`,
129
+ `order_date` DateTime `json:$.order_date`,
130
+ `total_amount` Float64 `json:$.total_amount`,
131
+ `items` Array(String) `json:$.items[:]` // This is an array field
132
+
133
+ ### Desired final output of the query:
134
+ {
135
+ "order_id": 123456,
136
+ "customer_id": 7890,
137
+ "order_date": "2024-11-30T10:30:00.000Z",
138
+ "total_amount": 150.0,
139
+ "items": ["item1", "item2", "item3"]
140
+ }
141
+
142
+ ### Example SQL output with an array field:
143
+
144
+ SELECT
145
+ concat('ord_', toString(rand() % 10000)) AS order_id,
146
+ concat('cust_', toString(rand() % 10000)) AS customer_id,
147
+ now() - rand() % 86400 AS order_date,
148
+ rand() % 1000 AS total_amount,
149
+ arrayMap(x -> concat('item_', toString(x)), range(1, rand() % 5 + 1)) AS items
150
+ FROM numbers(ROWS)
151
+
152
+ ## Example schema with a nested JSON field:
153
+
154
+ ### Schema:
155
+
156
+ SCHEMA >
157
+ `request_id` String `json:$.request_id`,
158
+ `timestamp` DateTime `json:$.timestamp`,
159
+ `model` String `json:$.request.model`,
160
+ `temperature` Float32 `json:$.request.options.temperature`,
161
+ `max_tokens` UInt32 `json:$.request.options.max_tokens`,
162
+ `stream` UInt8 `json:$.request.options.stream`
163
+
164
+ ### Desired final output of the query:
165
+
166
+ Note that the important part is generating the nested fields:
167
+ json:$.request.options.max_tokens > this means that the max_tokens field is nested inside the options field inside the request field.
168
+
169
+ {
170
+ "request_id": "req_abc123",
171
+ "timestamp": "2024-11-30T10:30:00.000Z",
172
+ "request": {
173
+ "model": "gpt-4",
174
+ "options": {
175
+ "temperature": 0.7,
176
+ "max_tokens": 1000,
177
+ "stream": false
178
+ }
179
+ }
180
+ }
181
+
182
+ ### Example SQL output with nested fields:
183
+
184
+ SELECT
185
+ request_id,
186
+ timestamp,
187
+ CAST(concat('{
188
+ "model": "', model, '",
189
+ "options": {
190
+ "temperature": ', temperature, ',
191
+ "max_tokens": ', max_tokens, ',
192
+ "stream": ', IF(stream = 1, 'true', 'false'), '
193
+ }
194
+ }'), 'JSON') AS request
195
+ FROM
196
+ (
197
+ SELECT
198
+ concat('req_', lower(hex(randomString(6)))) AS request_id,
199
+ (now() - toIntervalDay(rand() % 30)) + toIntervalSecond(rand() % 86400) AS timestamp,
200
+ ['gpt-4', 'gpt-3.5-turbo', 'gpt-4-turbo'][(rand() % 3) + 1] AS model,
201
+ round(rand() / 10, 2) AS temperature,
202
+ 500 + (rand() % 2500) AS max_tokens,
203
+ rand() % 2 AS stream
204
+ FROM numbers(ROWS)
205
+ )
206
+
120
207
  # Extra context:
121
208
  {context}
122
209
 
tinybird/tb/__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__ = '0.0.1.dev24'
8
- __revision__ = '3de7f2a'
7
+ __version__ = '0.0.1.dev25'
8
+ __revision__ = 'd7ae6dd'
@@ -773,11 +773,11 @@ async def get_processed(
773
773
  filenames: Iterable[str],
774
774
  changed: Optional[Dict[str, Any]] = None,
775
775
  verbose: bool = False,
776
- deps: List[str] = [],
777
- dep_map: Dict[str, Any] = {},
778
- to_run: Dict[str, Any] = {},
776
+ deps: Optional[List[str]] = None,
777
+ dep_map: Optional[Dict[str, Any]] = None,
778
+ to_run: Optional[Dict[str, Any]] = None,
779
779
  vendor_paths: Optional[List[Tuple[str, str]]] = None,
780
- processed: Set[str] = set(),
780
+ processed: Optional[Set[str]] = None,
781
781
  tb_client: TinyB = None,
782
782
  skip_connectors: bool = False,
783
783
  current_ws: Optional[Dict[str, Any]] = None,
@@ -786,6 +786,15 @@ async def get_processed(
786
786
  dir_path: Optional[str] = None,
787
787
  embedded_datasources: Optional[Dict[str, Any]] = None,
788
788
  ):
789
+ if deps is None:
790
+ deps = []
791
+ if dep_map is None:
792
+ dep_map = {}
793
+ if to_run is None:
794
+ to_run = {}
795
+ if processed is None:
796
+ processed = set()
797
+
789
798
  for filename in filenames:
790
799
  # just process changed filenames (tb deploy and --only-changes)
791
800
  if changed:
@@ -25,7 +25,7 @@ def print_message(message: str, color: str = bcolors.ENDC) -> Callable[..., str]
25
25
 
26
26
 
27
27
  def error_message(message: str) -> Callable[..., str]:
28
- return print_message(f"\n** {message}", bcolors.FAIL)
28
+ return print_message(f"{message}", bcolors.FAIL)
29
29
 
30
30
 
31
31
  def error_exception(message: str) -> Callable[..., str]:
@@ -81,7 +81,7 @@ async def test_create(pipe: str, prompt: Optional[str], folder: str) -> None:
81
81
  if not pipe_path.exists():
82
82
  pipe_path = Path("pipes", f"{pipe}.pipe")
83
83
 
84
- click.echo(FeedbackManager.gray(message=f"\nCreating tests for {pipe_name} endpoint..."))
84
+ click.echo(FeedbackManager.highlight(message=f"\ Creating tests for {pipe_name} endpoint..."))
85
85
  pipe_path = Path(folder) / pipe_path
86
86
  pipe_content = pipe_path.read_text()
87
87
 
@@ -96,7 +96,7 @@ async def test_create(pipe: str, prompt: Optional[str], folder: str) -> None:
96
96
  test_expectations = await llm.create_tests(
97
97
  pipe_content=pipe_content, pipe_params=pipe_params, prompt=prompt or ""
98
98
  )
99
- valid_test_expectations = []
99
+ valid_test_expectations: List[Dict[str, Any]] = []
100
100
  for test in test_expectations.tests:
101
101
  valid_test = test.model_dump()
102
102
  test_params = (
@@ -118,9 +118,13 @@ async def test_create(pipe: str, prompt: Optional[str], folder: str) -> None:
118
118
  valid_test["expected_result"] = response.text or ""
119
119
 
120
120
  valid_test_expectations.append(valid_test)
121
+
121
122
  if valid_test_expectations:
122
123
  generate_test_file(pipe_name, valid_test_expectations, folder, mode="a")
123
- click.echo(FeedbackManager.info(message=f"✓ /tests/{pipe_name}.yaml"))
124
+ for test in valid_test_expectations:
125
+ test_name = test["name"]
126
+ click.echo(FeedbackManager.info(message=f"✓ {test_name} created"))
127
+
124
128
  click.echo(FeedbackManager.success(message="✓ Done!\n"))
125
129
  except Exception as e:
126
130
  raise CLIException(FeedbackManager.error_exception(error=e))
@@ -139,37 +143,43 @@ async def test_create(pipe: str, prompt: Optional[str], folder: str) -> None:
139
143
  )
140
144
  @coro
141
145
  async def test_update(pipe: str, folder: str) -> None:
142
- client = await get_tinybird_local_client(os.path.abspath(folder))
143
- pipe_tests_path = Path(pipe)
144
- pipe_name = pipe
145
- if pipe_tests_path.suffix == ".yaml":
146
- pipe_name = pipe_tests_path.stem
147
- else:
148
- pipe_tests_path = Path("tests", f"{pipe}.yaml")
149
-
150
- click.echo(FeedbackManager.gray(message=f"\nUpdating tests expectations for {pipe_name} endpoint..."))
151
- pipe_tests_path = Path(folder) / pipe_tests_path
152
- pipe_tests_content = yaml.safe_load(pipe_tests_path.read_text())
153
- for test in pipe_tests_content:
154
- test_params = test["parameters"] if test["parameters"].startswith("?") else f"?{test['parameters']}"
155
- response = None
156
- try:
157
- response = await client._req_raw(f"/v0/pipes/{pipe_name}.ndjson{test_params}")
158
- except Exception:
159
- continue
160
-
161
- if response.status_code >= 400:
162
- test["expected_http_status"] = response.status_code
163
- test["expected_result"] = response.json()["error"]
146
+ try:
147
+ client = await get_tinybird_local_client(os.path.abspath(folder))
148
+ pipe_tests_path = Path(pipe)
149
+ pipe_name = pipe
150
+ if pipe_tests_path.suffix == ".yaml":
151
+ pipe_name = pipe_tests_path.stem
164
152
  else:
165
- if "expected_http_status" in test:
166
- del test["expected_http_status"]
153
+ pipe_tests_path = Path("tests", f"{pipe}.yaml")
167
154
 
168
- test["expected_result"] = response.text or ""
155
+ click.echo(FeedbackManager.highlight(message=f"\n» Updating tests expectations for {pipe_name} endpoint..."))
156
+ pipe_tests_path = Path(folder) / pipe_tests_path
157
+ pipe_tests_content = yaml.safe_load(pipe_tests_path.read_text())
158
+ for test in pipe_tests_content:
159
+ test_params = test["parameters"] if test["parameters"].startswith("?") else f"?{test['parameters']}"
160
+ response = None
161
+ try:
162
+ response = await client._req_raw(f"/v0/pipes/{pipe_name}.ndjson{test_params}")
163
+ except Exception:
164
+ continue
165
+
166
+ if response.status_code >= 400:
167
+ test["expected_http_status"] = response.status_code
168
+ test["expected_result"] = response.json()["error"]
169
+ else:
170
+ if "expected_http_status" in test:
171
+ del test["expected_http_status"]
169
172
 
170
- generate_test_file(pipe_name, pipe_tests_content, folder)
171
- click.echo(FeedbackManager.info(message=f"✓ /tests/{pipe_name}.yaml"))
172
- click.echo(FeedbackManager.success(message="✓ Done!\n"))
173
+ test["expected_result"] = response.text or ""
174
+
175
+ generate_test_file(pipe_name, pipe_tests_content, folder)
176
+ for test in pipe_tests_content:
177
+ test_name = test["name"]
178
+ click.echo(FeedbackManager.info(message=f"✓ {test_name} updated"))
179
+
180
+ click.echo(FeedbackManager.success(message="✓ Done!\n"))
181
+ except Exception as e:
182
+ click.echo(FeedbackManager.error(message=str(e)))
173
183
 
174
184
 
175
185
  @test.command(
@@ -185,6 +195,7 @@ async def test_update(pipe: str, folder: str) -> None:
185
195
  )
186
196
  @coro
187
197
  async def test_run(name: Tuple[str, ...], folder: str) -> None:
198
+ click.echo(FeedbackManager.highlight(message="\n» Running tests"))
188
199
  client = await get_tinybird_local_client(os.path.abspath(folder))
189
200
  paths = [Path(n) for n in name]
190
201
  endpoints = [f"./tests/{p.stem}.yaml" for p in paths]
@@ -192,6 +203,7 @@ async def test_run(name: Tuple[str, ...], folder: str) -> None:
192
203
 
193
204
  async def run_test(test_file):
194
205
  test_file_path = Path(test_file)
206
+ click.echo(FeedbackManager.info(message=f"\n* {test_file_path.stem}{test_file_path.suffix}"))
195
207
  test_file_content = yaml.safe_load(test_file_path.read_text())
196
208
  for test in test_file_content:
197
209
  try:
@@ -219,20 +231,21 @@ async def test_run(name: Tuple[str, ...], folder: str) -> None:
219
231
  raise Exception(
220
232
  f"\nExpected: \n{test['expected_result']}\nGot: \n{expected_result}\nDiff: \n{printable_diff}"
221
233
  )
222
- click.echo(FeedbackManager.success(message=f"✓ {test_file_path.name} - {test['name']}"))
234
+ click.echo(FeedbackManager.info(message=f"✓ {test['name']} passed"))
223
235
  except Exception as e:
224
- click.echo(FeedbackManager.error(message=f"✗ {test_file_path.name} - {test['name']}"))
225
- click.echo(FeedbackManager.error(message=f"Output and expected output are different: \n{e}"))
236
+ click.echo(FeedbackManager.error(message=f"✗ {test['name']} failed"))
237
+ click.echo(FeedbackManager.error(message=f"\n** Output and expected output are different: \n{e}"))
226
238
  return False
227
239
  return True
228
240
 
229
- tests_failed = False
241
+ failed_tests_count = 0
242
+ test_count = len(file_list)
230
243
  for test_file in file_list:
231
244
  if not await run_test(test_file):
232
- tests_failed = True
245
+ failed_tests_count += 1
233
246
 
234
- if tests_failed:
235
- click.echo(FeedbackManager.error(message="✗ Some tests failed"))
247
+ if failed_tests_count:
248
+ click.echo(FeedbackManager.error(message=f"\n{test_count - failed_tests_count}/{test_count} passed"))
236
249
  exit(1)
237
250
  else:
238
- click.echo(FeedbackManager.success(message="✓ All tests passed"))
251
+ click.echo(FeedbackManager.success(message=f"\n{test_count}/{test_count} passed"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird
3
- Version: 0.0.1.dev24
3
+ Version: 0.0.1.dev25
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -6,7 +6,7 @@ tinybird/context.py,sha256=kutUQ0kCwparowI74_YLXx6wtTzGLRouJ6oGHVBPzBo,1291
6
6
  tinybird/datatypes.py,sha256=IHyhZ86ib54Vnd1pbod9y2aS8DDvDKZm1HJGlThdbuQ,10460
7
7
  tinybird/feedback_manager.py,sha256=cNUbt0Jxim02UiIdlyP12DJfXfFFzxDCfJK9XRWZ9A0,67488
8
8
  tinybird/git_settings.py,sha256=XUL9ZUj59-ZVQJDYmMEq4UpnuuOuQOHGlNcX3JgQHjQ,3954
9
- tinybird/prompts.py,sha256=t2AuOlyBy7dEOuZcUVZzTXExP7VnK337u7z-GftSY-Q,6410
9
+ tinybird/prompts.py,sha256=UPFvQe74foRz1FP-hJDYdUC4lKFwicDmVZ_uZQH59EE,8923
10
10
  tinybird/sql.py,sha256=gfRKjdqEygcE1WOTeQ1QV2Jal8Jzl4RSX8fftu1KSEs,45825
11
11
  tinybird/sql_template.py,sha256=IqYRfUxDYBCoOYjqqvn--_8QXLv9FSRnJ0bInx7q1Xs,93051
12
12
  tinybird/sql_template_fmt.py,sha256=1z-PuqSZXtzso8Z_mPqUc-NxIxUrNUcVIPezNieZk-M,10196
@@ -15,7 +15,7 @@ tinybird/syncasync.py,sha256=fAvq0qkRgqXqXMKwbY2iJNYqLT_r6mDsh1MRpGKrdRU,27763
15
15
  tinybird/tornado_template.py,sha256=o2HguxrL1Evnt8o3IvrsI8Zm6JtRQ3zhLJKf1XyR3SQ,41965
16
16
  tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
17
17
  tinybird/ch_utils/engine.py,sha256=OXkBhlzGjZotjD0vaT-rFIbSGV4tpiHxE8qO_ip0SyQ,40454
18
- tinybird/tb/__cli__.py,sha256=1fysm8mkLcvnBe_6GnnZ0KRMztaWMMR2cLtUdB6ZtiE,251
18
+ tinybird/tb/__cli__.py,sha256=tCyhGm300ADIFgyriAGzuSPNGnYfrOEb_GX9KqH1ziQ,251
19
19
  tinybird/tb/cli.py,sha256=onCxcKvTV4RuokC5V3t82OXWAIwgU6pMWs8rpWOUi_o,815
20
20
  tinybird/tb/modules/auth.py,sha256=EzRWFmwRkXNhUmRaruEVFLdkbUg8xMSix0cAWl5D4Jg,9029
21
21
  tinybird/tb/modules/build.py,sha256=XQHivOYRoMYJJ2VeiGsGueuUtCwFF4OR54rZikvGshY,7077
@@ -27,7 +27,7 @@ tinybird/tb/modules/connection.py,sha256=FhDM-OAnLN2epbO2YonpjJQhHqBjyuanBsZmKlD
27
27
  tinybird/tb/modules/create.py,sha256=ykiacZ0e-ZdHhj27a_Fc1lemyO8b8wQjwlkSJ1gGC70,10637
28
28
  tinybird/tb/modules/datasource.py,sha256=3ySFOTXVnuqwQQNJBYhD8Sq41S2BJO2ymZRsFmEvHqY,32899
29
29
  tinybird/tb/modules/exceptions.py,sha256=4A2sSjCEqKUMqpP3WI00zouCWW4uLaghXXLZBSw04mY,3363
30
- tinybird/tb/modules/feedback_manager.py,sha256=a76KSrIdtNT5cs56jMYUfpqoXMwEPq_SErRGlX0i4hc,68384
30
+ tinybird/tb/modules/feedback_manager.py,sha256=e8tqehRR0Buhs8O0n8N2Sg2vnnBVb1NLtnZqkPrYD_A,68379
31
31
  tinybird/tb/modules/fmt.py,sha256=poh6_cwVGSf-sBu6LKWuO2TANL_J8Sgm25sPpwxa3Aw,3558
32
32
  tinybird/tb/modules/job.py,sha256=956Pj8BEEsiD2GZsV9RKKVM3I_CveOLgS82lykO5ukk,2963
33
33
  tinybird/tb/modules/llm.py,sha256=Rx3QHl9D8kp8MnUM2CFQtxWfaLPiIczVJX1iSRyjyBw,2923
@@ -41,12 +41,12 @@ tinybird/tb/modules/shell.py,sha256=OfFQ4lx3v_XSTr5cm_mTDG6CLc3zFdikM2pOamifG84,
41
41
  tinybird/tb/modules/table.py,sha256=4XrtjM-N0zfNtxVkbvLDQQazno1EPXnxTyo7llivfXk,11035
42
42
  tinybird/tb/modules/tag.py,sha256=anPmMUBc-TbFovlpFi8GPkKA18y7Y0GczMsMms5TZsU,3502
43
43
  tinybird/tb/modules/telemetry.py,sha256=iEGnMuCuNhvF6ln__j6X9MSTwL_0Hm-GgFHHHvhfknk,10466
44
- tinybird/tb/modules/test.py,sha256=RSqN4LRlvR89SKolo5hatdiw7nUojIaY67YzomAXGQ0,9146
44
+ tinybird/tb/modules/test.py,sha256=MJMfORQd0ny_Wc8RORbT4aGG8tnKQgArOm-b5VBVeco,9800
45
45
  tinybird/tb/modules/token.py,sha256=AePr-QMv_vtWwZDWQ92Zp0kPrCjze61i4npiPhoLMZg,12717
46
46
  tinybird/tb/modules/watch.py,sha256=fHRMm3iqHdK-wQNSwWxroJjD7fbWuEbz8NLOqBdtN1Y,3931
47
47
  tinybird/tb/modules/workspace.py,sha256=6icAgnTvfL3d1kx4L1Z1cGXCD_2Yx0fNRjbZHNxRbYc,10927
48
48
  tinybird/tb/modules/workspace_members.py,sha256=Ai6iCOzXX1zQ8q9iXIFSFHsBJlT-8Q28DaG5Ie-UweY,8726
49
- tinybird/tb/modules/datafile/build.py,sha256=-hw5iP7uMVi_lLQ51ihO-UooJKZ_fRzwKEbGuXRpEZk,56490
49
+ tinybird/tb/modules/datafile/build.py,sha256=-hhzw1890prLSH8itKtvhk2WoeuzJYadIxNTpQxTpNY,56715
50
50
  tinybird/tb/modules/datafile/build_common.py,sha256=IXl-Z51zUi1dypV7meNenX0iu2UmowNeqgG6WHyMHlk,4562
51
51
  tinybird/tb/modules/datafile/build_datasource.py,sha256=4aP8_DYCRGghXntZSeWDNJxjps1QRVa7WHoYCzQwQts,17355
52
52
  tinybird/tb/modules/datafile/build_pipe.py,sha256=n6jjfBaDl014-jxM5gI9XjUb0XCmgEVoAoAuy_Br8nw,27842
@@ -69,8 +69,8 @@ tinybird/tb_cli_modules/config.py,sha256=6NTgIdwf0X132A1j6G_YrdPep87ymZ9b5pABabK
69
69
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
70
70
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
71
71
  tinybird/tb_cli_modules/telemetry.py,sha256=iEGnMuCuNhvF6ln__j6X9MSTwL_0Hm-GgFHHHvhfknk,10466
72
- tinybird-0.0.1.dev24.dist-info/METADATA,sha256=jhgjC0xVQkjru503B-AssrXKlGmBuWrBBxs1oABVzaY,2446
73
- tinybird-0.0.1.dev24.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
74
- tinybird-0.0.1.dev24.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
75
- tinybird-0.0.1.dev24.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
76
- tinybird-0.0.1.dev24.dist-info/RECORD,,
72
+ tinybird-0.0.1.dev25.dist-info/METADATA,sha256=Bc-rL4ndx0D6ZcZ-WJ9hPbg-U-HL4w6bbNT8XiZVGUM,2446
73
+ tinybird-0.0.1.dev25.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
74
+ tinybird-0.0.1.dev25.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
75
+ tinybird-0.0.1.dev25.dist-info/top_level.txt,sha256=pgw6AzERHBcW3YTi2PW4arjxLkulk2msOz_SomfOEuc,45
76
+ tinybird-0.0.1.dev25.dist-info/RECORD,,