tinybird 0.0.1.dev15__tar.gz → 0.0.1.dev16__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.
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/PKG-INFO +1 -1
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/client.py +3 -1
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/feedback_manager.py +12 -1
- {tinybird-0.0.1.dev15/tinybird/tb/modules → tinybird-0.0.1.dev16/tinybird}/prompts.py +26 -64
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/cli.py +2 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/build.py +4 -129
- tinybird-0.0.1.dev16/tinybird/tb/modules/build_shell.py +133 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/cli.py +8 -1
- tinybird-0.0.1.dev16/tinybird/tb/modules/create.py +411 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/llm.py +35 -3
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/local.py +2 -46
- tinybird-0.0.1.dev16/tinybird/tb/modules/local_common.py +54 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/mock.py +1 -1
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/test.py +23 -12
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/PKG-INFO +1 -1
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/SOURCES.txt +3 -1
- tinybird-0.0.1.dev15/tinybird/tb/modules/create.py +0 -172
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/setup.cfg +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/__cli__.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/ch_utils/constants.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/ch_utils/engine.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/check_pypi.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/config.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/connectors.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/context.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/datafile.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/datatypes.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/git_settings.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/sql.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/sql_template.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/sql_template_fmt.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/sql_toolset.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/syncasync.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/auth.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/branch.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/cicd.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/common.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/config.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/connection.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/build.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/build_common.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/build_datasource.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/build_pipe.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/common.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/diff.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/exceptions.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/fixture.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/format_common.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/format_datasource.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/format_pipe.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/parse_datasource.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/parse_pipe.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/pipe_checker.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datafile/pull.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/datasource.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/fmt.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/job.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/login.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/pipe.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/regions.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/table.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/tag.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/token.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/workspace.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb/modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/auth.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/branch.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/cicd.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/cli.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/common.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/config.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/connection.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/datasource.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/fmt.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/job.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/pipe.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/regions.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/tag.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/test.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/workspace.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tb_cli_modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird/tornado_template.py +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/dependency_links.txt +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/entry_points.txt +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/requires.txt +0 -0
- {tinybird-0.0.1.dev15 → tinybird-0.0.1.dev16}/tinybird.egg-info/top_level.txt +0 -0
|
@@ -188,7 +188,9 @@ class TinyB:
|
|
|
188
188
|
if response.status_code == 599:
|
|
189
189
|
raise TimeoutException("timeout")
|
|
190
190
|
if "Content-Type" in response.headers and (
|
|
191
|
-
response.headers["Content-Type"] == "text/plain"
|
|
191
|
+
response.headers["Content-Type"] == "text/plain"
|
|
192
|
+
or "text/csv" in response.headers["Content-Type"]
|
|
193
|
+
or "ndjson" in response.headers["Content-Type"]
|
|
192
194
|
):
|
|
193
195
|
return response.content.decode("utf-8")
|
|
194
196
|
if response.status_code >= 400 and response.status_code not in [400, 403, 404, 409, 429]:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from collections import namedtuple
|
|
2
2
|
from typing import Any, Callable
|
|
3
|
+
import os
|
|
3
4
|
|
|
4
5
|
FeedbackMessage = namedtuple("FeedbackMessage", "message")
|
|
5
6
|
|
|
@@ -26,6 +27,16 @@ def print_message(message: str, color: str = bcolors.ENDC) -> Callable[..., str]
|
|
|
26
27
|
def error_message(message: str) -> Callable[..., str]:
|
|
27
28
|
return print_message(f"\n** {message}", bcolors.FAIL)
|
|
28
29
|
|
|
30
|
+
def error_exception(message: Exception) -> Callable[..., str]:
|
|
31
|
+
def formatter(**kwargs: Any) -> str:
|
|
32
|
+
color = bcolors.FAIL
|
|
33
|
+
if isinstance(kwargs.get('error', ''), Exception) and os.environ.get('TB_DEBUG', '') != '':
|
|
34
|
+
import traceback
|
|
35
|
+
stack_trace = f"Traceback:\n{''.join(traceback.format_tb(kwargs['error'].__traceback__))}"
|
|
36
|
+
return f"{color}{message.format(**kwargs)}{stack_trace}{bcolors.ENDC}"
|
|
37
|
+
return f"{color}{message.format(**kwargs)}{bcolors.ENDC}"
|
|
38
|
+
return formatter
|
|
39
|
+
|
|
29
40
|
|
|
30
41
|
def simple_error_message(message: str) -> Callable[..., str]:
|
|
31
42
|
return print_message(f"{message}", bcolors.FAIL)
|
|
@@ -56,7 +67,7 @@ def gray_message(message: str) -> Callable[..., str]:
|
|
|
56
67
|
|
|
57
68
|
|
|
58
69
|
class FeedbackManager:
|
|
59
|
-
error_exception =
|
|
70
|
+
error_exception = error_exception("{error}")
|
|
60
71
|
simple_error_exception = simple_error_message("{error}")
|
|
61
72
|
error_exception_trace = error_message("{error}\n** Trace:\n{trace}")
|
|
62
73
|
error_notoken = error_message(
|
|
@@ -76,68 +76,7 @@ SQL >
|
|
|
76
76
|
</instructions>
|
|
77
77
|
"""
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
You are a Tinybird expert. You will be given a pipe endpoint containing different nodes with SQL and Tinybird templating syntax. You will generate URLs to test it with different parameters combinations.
|
|
81
|
-
|
|
82
|
-
<test>
|
|
83
|
-
<test_1>:
|
|
84
|
-
name: <test_name_1>
|
|
85
|
-
description: <description_1>
|
|
86
|
-
parameters: <url_encoded_parameters_1>
|
|
87
|
-
<test_2>:
|
|
88
|
-
name: <test_name_2>
|
|
89
|
-
description: <description_2>
|
|
90
|
-
parameters: <url_encoded_parameters_2>
|
|
91
|
-
</test>
|
|
92
|
-
<instructions>
|
|
93
|
-
- The test name must be unique.
|
|
94
|
-
- The test command must be a valid Tinybird command that can be run in the terminal.
|
|
95
|
-
- The test command can have as many parameters as are needed to test the pipe.
|
|
96
|
-
- The parameter within Tinybird templating syntax looks like this one {{String(my_param_name, default_value)}}.
|
|
97
|
-
- If there are no parameters in the , you can omit parametrs and generate a single test command.
|
|
98
|
-
- Extra context: {context}
|
|
99
|
-
</instructions>
|
|
100
|
-
"""
|
|
101
|
-
|
|
102
|
-
sample_data_prompt = """Your role is to generate sample data for a given data source. A data source is a table in Tinybird. You will be given a schema for the data source, and you will need to generate a set of rows that fit that schema.
|
|
103
|
-
|
|
104
|
-
The schema will be provided to you at the end of this prompt in the following format:
|
|
105
|
-
|
|
106
|
-
```
|
|
107
|
-
SCHEMA >
|
|
108
|
-
`span_id` String `json:$.span_id`,
|
|
109
|
-
`operation_id` String `json:$.operation_name`,
|
|
110
|
-
`duration` Nullable(Float32) `json:$.duration`,
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
In the example above, `span_id` are column names, String and Float32 are column types, and `json:$.duration` is a JSON path expression that points to the duration value in the JSON data. Use this information to generate valid data.
|
|
114
|
-
|
|
115
|
-
You will generate {row_count} rows of data in JSON format, newlines separated. Your reponse will only contain the {row_count} rows of data, without any other text. Do not format the data in any way, and do not place it inside any markers for a code block of any kind. Most importantly, do not use backticks on the first or last line or anywhere else in the response. This is extremely important, ensure that your response doesn't include any backticks.
|
|
116
|
-
|
|
117
|
-
Remember that for a JSON to be valid, there can't be a trailing comma after the last value in an object.
|
|
118
|
-
|
|
119
|
-
Make sure to include all columns in the schema, and use valid JSON. You may leave some columns empty only if the column type allows it (e.g. Nullable(String)). Use realistic values for the data, and make sure to include a variety of values in each column.
|
|
120
|
-
|
|
121
|
-
For columns that represent timestamps, use values that are close to the current date and time. The current date and time is {current_datetime}"""
|
|
122
|
-
|
|
123
|
-
sample_data_with_errors_prompt = """Your role is to generate incorrect sample data for a given data source. A data source is a table in Tinybird. You will be given a schema for the data source, and you will need to generate a set of rows that mostly fit that schema, but with some errors.
|
|
124
|
-
|
|
125
|
-
The schema will be provided to you at the end of this prompt in the following format:
|
|
126
|
-
|
|
127
|
-
```
|
|
128
|
-
SCHEMA >
|
|
129
|
-
`span_id` String `json:$.span_id`,
|
|
130
|
-
`operation_id` String `json:$.operation_name`,
|
|
131
|
-
`duration` Nullable(Float32) `json:$.duration`,
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
In the example above, `span_id` are column names, String and Float32 are column types, and `json:$.duration` is a JSON path expression that points to the duration value in the JSON data. Use this information to generate valid data.
|
|
135
|
-
|
|
136
|
-
You will generate {row_count} rows of data in JSON format, newlines separated. Your reponse will be a single string containing all {row_count} rows, without any other text. Make sure to include all columns in the schema, and use valid JSON. Use realistic values for the data, and make sure to include a variety of values in each column. In every set of {row_count} rows, there should be at least one row that has an error. The error could be in any column, and it could be a type error (e.g. a string where a number is expected), or it could be an error in the structure of the JSON (e.g. a value in the wrong place in the document).
|
|
137
|
-
|
|
138
|
-
For columns that represent timestamps, use values that are close to the current date and time. The current date and time is {current_datetime}"""
|
|
139
|
-
|
|
140
|
-
sample_data_sql_prompt = """
|
|
79
|
+
generate_sql_mock_data_prompt = """
|
|
141
80
|
Given the schema for a Tinybird datasource, return a can you create a clickhouse sql query to generate some random data that matches that schema.
|
|
142
81
|
|
|
143
82
|
Response format MUST be just a valid clickhouse sql query.
|
|
@@ -164,13 +103,13 @@ SELECT
|
|
|
164
103
|
rand() % 50 AS pvp_kills, -- Random PvP kills between 0 and 49
|
|
165
104
|
rand() % 200 AS quest_completions, -- Random quest completions between 0 and 199
|
|
166
105
|
now() - rand() % 86400 AS timestamp -- Random timestamp within the last day
|
|
167
|
-
FROM numbers({
|
|
106
|
+
FROM numbers({rows})
|
|
168
107
|
|
|
169
108
|
# Instructions:
|
|
170
109
|
|
|
171
110
|
- The query MUST return a random sample of data that matches the schema.
|
|
172
111
|
- The query MUST return a valid clickhouse sql query.
|
|
173
|
-
- The query MUST return a sample of EXACTLY {
|
|
112
|
+
- The query MUST return a sample of EXACTLY {rows} rows.
|
|
174
113
|
- The query MUST be valid for clickhouse and Tinybird.
|
|
175
114
|
- Return JUST the sql query, without any other text or symbols.
|
|
176
115
|
- Do NOT include ```clickhouse or ```sql or any other wrapping text.
|
|
@@ -182,3 +121,26 @@ FROM numbers({row_count})
|
|
|
182
121
|
{context}
|
|
183
122
|
|
|
184
123
|
"""
|
|
124
|
+
|
|
125
|
+
create_test_calls_prompt = """
|
|
126
|
+
You are a Tinybird expert. You will be given a pipe endpoint containing different nodes with SQL and Tinybird templating syntax. You will generate URLs to test it with different parameters combinations.
|
|
127
|
+
|
|
128
|
+
<test>
|
|
129
|
+
<test_1>:
|
|
130
|
+
name: <test_name_1>
|
|
131
|
+
description: <description_1>
|
|
132
|
+
parameters: <url_encoded_parameters_1>
|
|
133
|
+
<test_2>:
|
|
134
|
+
name: <test_name_2>
|
|
135
|
+
description: <description_2>
|
|
136
|
+
parameters: <url_encoded_parameters_2>
|
|
137
|
+
</test>
|
|
138
|
+
<instructions>
|
|
139
|
+
- The test name must be unique.
|
|
140
|
+
- The test command must be a valid Tinybird command that can be run in the terminal.
|
|
141
|
+
- The test command can have as many parameters as are needed to test the pipe.
|
|
142
|
+
- The parameter within Tinybird templating syntax looks like this one {{String(my_param_name, default_value)}}.
|
|
143
|
+
- If there are no parameters in the , you can omit parametrs and generate a single test command.
|
|
144
|
+
- Extra context: {context}
|
|
145
|
+
</instructions>
|
|
146
|
+
"""
|
|
@@ -14,10 +14,12 @@ import tinybird.tb.modules.create
|
|
|
14
14
|
import tinybird.tb.modules.datasource
|
|
15
15
|
import tinybird.tb.modules.fmt
|
|
16
16
|
import tinybird.tb.modules.job
|
|
17
|
+
import tinybird.tb.modules.local
|
|
17
18
|
import tinybird.tb.modules.login
|
|
18
19
|
import tinybird.tb.modules.mock
|
|
19
20
|
import tinybird.tb.modules.pipe
|
|
20
21
|
import tinybird.tb.modules.tag
|
|
22
|
+
import tinybird.tb.modules.test
|
|
21
23
|
import tinybird.tb.modules.token
|
|
22
24
|
import tinybird.tb.modules.workspace
|
|
23
25
|
import tinybird.tb.modules.workspace_members
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
import cmd
|
|
3
2
|
import os
|
|
4
|
-
import random
|
|
5
|
-
import subprocess
|
|
6
|
-
import sys
|
|
7
3
|
import threading
|
|
8
4
|
import time
|
|
9
5
|
from pathlib import Path
|
|
10
6
|
from typing import Any, Awaitable, Callable, List, Union
|
|
11
7
|
|
|
12
8
|
import click
|
|
13
|
-
import humanfriendly
|
|
14
9
|
from click import Context
|
|
15
10
|
from watchdog.events import FileSystemEventHandler
|
|
16
11
|
from watchdog.observers import Observer
|
|
17
12
|
|
|
18
13
|
import tinybird.context as context
|
|
19
|
-
from tinybird.
|
|
20
|
-
from tinybird.client import TinyB, AuthNoTokenException
|
|
21
|
-
from tinybird.tb.modules.common import CLIException
|
|
14
|
+
from tinybird.client import TinyB
|
|
22
15
|
from tinybird.config import FeatureFlags
|
|
23
|
-
from tinybird.feedback_manager import FeedbackManager
|
|
16
|
+
from tinybird.feedback_manager import FeedbackManager
|
|
17
|
+
from tinybird.tb.modules.build_shell import BuildShell, print_table_formatted
|
|
24
18
|
from tinybird.tb.modules.cli import cli
|
|
25
19
|
from tinybird.tb.modules.common import coro, push_data
|
|
26
20
|
from tinybird.tb.modules.datafile.build import folder_build
|
|
@@ -29,48 +23,7 @@ from tinybird.tb.modules.datafile.exceptions import ParseException
|
|
|
29
23
|
from tinybird.tb.modules.datafile.fixture import build_fixture_name, get_fixture_dir
|
|
30
24
|
from tinybird.tb.modules.datafile.parse_datasource import parse_datasource
|
|
31
25
|
from tinybird.tb.modules.datafile.parse_pipe import parse_pipe
|
|
32
|
-
from tinybird.tb.modules.
|
|
33
|
-
from tinybird.tb.modules.table import format_table
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class BuildShell(cmd.Cmd):
|
|
37
|
-
prompt = "\n\001\033[1;32m\002TB > \001\033[0m\002"
|
|
38
|
-
|
|
39
|
-
def __init__(self, folder: str, client: TinyB):
|
|
40
|
-
super().__init__()
|
|
41
|
-
self.folder = folder
|
|
42
|
-
self.client = client
|
|
43
|
-
def do_exit(self, arg):
|
|
44
|
-
sys.exit(0)
|
|
45
|
-
|
|
46
|
-
def do_quit(self, arg):
|
|
47
|
-
sys.exit(0)
|
|
48
|
-
|
|
49
|
-
def default(self, argline):
|
|
50
|
-
click.echo("")
|
|
51
|
-
if argline.startswith("tb build"):
|
|
52
|
-
click.echo(FeedbackManager.error(message="Build command is already running"))
|
|
53
|
-
else:
|
|
54
|
-
arg_stripped = argline.strip().lower()
|
|
55
|
-
if not arg_stripped:
|
|
56
|
-
return
|
|
57
|
-
if arg_stripped.startswith("tb"):
|
|
58
|
-
extra_args = f" --folder {self.folder}" if arg_stripped.startswith("tb mock") else ""
|
|
59
|
-
subprocess.run(arg_stripped + extra_args, shell=True, text=True)
|
|
60
|
-
elif arg_stripped.startswith("with") or arg_stripped.startswith("select"):
|
|
61
|
-
try:
|
|
62
|
-
run_sql(self.client, argline)
|
|
63
|
-
except Exception as e:
|
|
64
|
-
click.echo(FeedbackManager.error(message=str(e)))
|
|
65
|
-
|
|
66
|
-
elif arg_stripped.startswith("mock "):
|
|
67
|
-
subprocess.run(f"tb {arg_stripped} --folder {self.folder}", shell=True, text=True)
|
|
68
|
-
else:
|
|
69
|
-
click.echo(FeedbackManager.error(message="Invalid command"))
|
|
70
|
-
|
|
71
|
-
def reprint_prompt(self):
|
|
72
|
-
self.stdout.write(self.prompt)
|
|
73
|
-
self.stdout.flush()
|
|
26
|
+
from tinybird.tb.modules.local_common import get_tinybird_local_client
|
|
74
27
|
|
|
75
28
|
|
|
76
29
|
class FileChangeHandler(FileSystemEventHandler):
|
|
@@ -131,44 +84,6 @@ def watch_files(
|
|
|
131
84
|
observer.join()
|
|
132
85
|
|
|
133
86
|
|
|
134
|
-
|
|
135
|
-
def run_sql(client: TinyB, query, rows_limit=20):
|
|
136
|
-
try:
|
|
137
|
-
q = query.strip()
|
|
138
|
-
if q.startswith("insert"):
|
|
139
|
-
click.echo(FeedbackManager.info_append_data())
|
|
140
|
-
raise CLIException(FeedbackManager.error_invalid_query())
|
|
141
|
-
if q.startswith("delete"):
|
|
142
|
-
raise CLIException(FeedbackManager.error_invalid_query())
|
|
143
|
-
|
|
144
|
-
# fuck my life
|
|
145
|
-
def run_query_in_thread():
|
|
146
|
-
loop = asyncio.new_event_loop()
|
|
147
|
-
asyncio.set_event_loop(loop)
|
|
148
|
-
try:
|
|
149
|
-
return loop.run_until_complete(client.query(f"SELECT * FROM ({query}) LIMIT {rows_limit} FORMAT JSON"))
|
|
150
|
-
finally:
|
|
151
|
-
loop.close()
|
|
152
|
-
|
|
153
|
-
# Run the query in a separate thread
|
|
154
|
-
import concurrent.futures
|
|
155
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
156
|
-
res = executor.submit(run_query_in_thread).result()
|
|
157
|
-
|
|
158
|
-
except AuthNoTokenException:
|
|
159
|
-
raise
|
|
160
|
-
except Exception as e:
|
|
161
|
-
raise CLIException(FeedbackManager.error_exception(error=str(e)))
|
|
162
|
-
|
|
163
|
-
if isinstance(res, dict) and "error" in res:
|
|
164
|
-
raise CLIException(FeedbackManager.error_exception(error=res["error"]))
|
|
165
|
-
|
|
166
|
-
if isinstance(res, dict) and "data" in res and res["data"]:
|
|
167
|
-
print_table_formatted(res, 'QUERY')
|
|
168
|
-
else:
|
|
169
|
-
click.echo(FeedbackManager.info_no_rows())
|
|
170
|
-
|
|
171
|
-
|
|
172
87
|
@cli.command()
|
|
173
88
|
@click.option(
|
|
174
89
|
"--folder",
|
|
@@ -286,46 +201,6 @@ async def build_and_print_resource(tb_client: TinyB, filename: str):
|
|
|
286
201
|
res = await tb_client.query(f"SELECT * FROM {name} FORMAT JSON", pipeline=pipeline)
|
|
287
202
|
print_table_formatted(res, name)
|
|
288
203
|
|
|
289
|
-
def print_table_formatted(res: dict, name: str):
|
|
290
|
-
rebuild_colors = [bcolors.FAIL, bcolors.OKBLUE, bcolors.WARNING, bcolors.OKGREEN, bcolors.HEADER]
|
|
291
|
-
rebuild_index = random.randint(0, len(rebuild_colors) - 1)
|
|
292
|
-
rebuild_color = rebuild_colors[rebuild_index % len(rebuild_colors)]
|
|
293
|
-
data = []
|
|
294
|
-
limit = 5
|
|
295
|
-
for d in res["data"][:5]:
|
|
296
|
-
data.append(d.values())
|
|
297
|
-
meta = res["meta"]
|
|
298
|
-
row_count = res.get("rows", 0)
|
|
299
|
-
stats = res.get("statistics", {})
|
|
300
|
-
elapsed = stats.get("elapsed", 0)
|
|
301
|
-
cols = len(meta)
|
|
302
|
-
try:
|
|
303
|
-
|
|
304
|
-
def print_message(message: str, color=bcolors.CGREY):
|
|
305
|
-
return f"{color}{message}{bcolors.ENDC}"
|
|
306
|
-
|
|
307
|
-
table = format_table(data, meta)
|
|
308
|
-
colored_char = print_message("│", rebuild_color)
|
|
309
|
-
table_with_marker = "\n".join(f"{colored_char} {line}" for line in table.split("\n"))
|
|
310
|
-
click.echo(f"\n{colored_char} {print_message('⚡', rebuild_color)} Running {name}")
|
|
311
|
-
click.echo(colored_char)
|
|
312
|
-
click.echo(table_with_marker)
|
|
313
|
-
click.echo(colored_char)
|
|
314
|
-
rows_read = humanfriendly.format_number(stats.get("rows_read", 0))
|
|
315
|
-
bytes_read = humanfriendly.format_size(stats.get("bytes_read", 0))
|
|
316
|
-
elapsed = humanfriendly.format_timespan(elapsed) if elapsed >= 1 else f"{elapsed * 1000:.2f}ms"
|
|
317
|
-
stats_message = f"» {bytes_read} ({rows_read} rows x {cols} cols) in {elapsed}"
|
|
318
|
-
rows_message = f"» Showing {limit} first rows" if row_count > limit else "» Showing all rows"
|
|
319
|
-
click.echo(f"{colored_char} {print_message(stats_message, bcolors.OKGREEN)}")
|
|
320
|
-
click.echo(f"{colored_char} {print_message(rows_message, bcolors.CGREY)}")
|
|
321
|
-
except ValueError as exc:
|
|
322
|
-
if str(exc) == "max() arg is an empty sequence":
|
|
323
|
-
click.echo("------------")
|
|
324
|
-
click.echo("Empty")
|
|
325
|
-
click.echo("------------")
|
|
326
|
-
else:
|
|
327
|
-
raise exc
|
|
328
|
-
|
|
329
204
|
|
|
330
205
|
async def append_datasource(
|
|
331
206
|
ctx: click.Context,
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import cmd
|
|
3
|
+
import random
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
import humanfriendly
|
|
9
|
+
|
|
10
|
+
from tinybird.client import TinyB
|
|
11
|
+
from tinybird.feedback_manager import FeedbackManager, bcolors
|
|
12
|
+
from tinybird.tb.modules.exceptions import CLIException
|
|
13
|
+
from tinybird.tb.modules.table import format_table
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BuildShell(cmd.Cmd):
|
|
17
|
+
prompt = "\n\001\033[1;32m\002TB > \001\033[0m\002"
|
|
18
|
+
|
|
19
|
+
def __init__(self, folder: str, client: TinyB):
|
|
20
|
+
super().__init__()
|
|
21
|
+
self.folder = folder
|
|
22
|
+
self.client = client
|
|
23
|
+
|
|
24
|
+
def do_exit(self, arg):
|
|
25
|
+
sys.exit(0)
|
|
26
|
+
|
|
27
|
+
def do_quit(self, arg):
|
|
28
|
+
sys.exit(0)
|
|
29
|
+
|
|
30
|
+
def default(self, argline):
|
|
31
|
+
click.echo("")
|
|
32
|
+
if argline.startswith("tb build"):
|
|
33
|
+
click.echo(FeedbackManager.error(message="Build command is already running"))
|
|
34
|
+
else:
|
|
35
|
+
arg_stripped = argline.strip().lower()
|
|
36
|
+
if not arg_stripped:
|
|
37
|
+
return
|
|
38
|
+
if arg_stripped.startswith("tb"):
|
|
39
|
+
arg_stripped = arg_stripped.replace("tb", "tb --local")
|
|
40
|
+
extra_args = f" --folder {self.folder}" if arg_stripped.startswith("tb mock") else ""
|
|
41
|
+
subprocess.run(arg_stripped + extra_args, shell=True, text=True)
|
|
42
|
+
elif arg_stripped.startswith("with") or arg_stripped.startswith("select"):
|
|
43
|
+
try:
|
|
44
|
+
self.run_sql(self.client, argline)
|
|
45
|
+
except Exception as e:
|
|
46
|
+
click.echo(FeedbackManager.error(message=str(e)))
|
|
47
|
+
|
|
48
|
+
elif arg_stripped.startswith("mock "):
|
|
49
|
+
subprocess.run(f"tb {arg_stripped} --folder {self.folder}", shell=True, text=True)
|
|
50
|
+
else:
|
|
51
|
+
click.echo(FeedbackManager.error(message="Invalid command"))
|
|
52
|
+
|
|
53
|
+
def reprint_prompt(self):
|
|
54
|
+
self.stdout.write(self.prompt)
|
|
55
|
+
self.stdout.flush()
|
|
56
|
+
|
|
57
|
+
def run_sql(self, query, rows_limit=20):
|
|
58
|
+
try:
|
|
59
|
+
q = query.strip()
|
|
60
|
+
if q.startswith("insert"):
|
|
61
|
+
click.echo(FeedbackManager.info_append_data())
|
|
62
|
+
raise CLIException(FeedbackManager.error_invalid_query())
|
|
63
|
+
if q.startswith("delete"):
|
|
64
|
+
raise CLIException(FeedbackManager.error_invalid_query())
|
|
65
|
+
|
|
66
|
+
# fuck my life
|
|
67
|
+
def run_query_in_thread():
|
|
68
|
+
loop = asyncio.new_event_loop()
|
|
69
|
+
asyncio.set_event_loop(loop)
|
|
70
|
+
try:
|
|
71
|
+
return loop.run_until_complete(
|
|
72
|
+
self.client.query(f"SELECT * FROM ({query}) LIMIT {rows_limit} FORMAT JSON")
|
|
73
|
+
)
|
|
74
|
+
finally:
|
|
75
|
+
loop.close()
|
|
76
|
+
|
|
77
|
+
# Run the query in a separate thread
|
|
78
|
+
import concurrent.futures
|
|
79
|
+
|
|
80
|
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
81
|
+
res = executor.submit(run_query_in_thread).result()
|
|
82
|
+
|
|
83
|
+
except Exception as e:
|
|
84
|
+
raise CLIException(FeedbackManager.error_exception(error=str(e)))
|
|
85
|
+
|
|
86
|
+
if isinstance(res, dict) and "error" in res:
|
|
87
|
+
raise CLIException(FeedbackManager.error_exception(error=res["error"]))
|
|
88
|
+
|
|
89
|
+
if isinstance(res, dict) and "data" in res and res["data"]:
|
|
90
|
+
print_table_formatted(res, "QUERY")
|
|
91
|
+
else:
|
|
92
|
+
click.echo(FeedbackManager.info_no_rows())
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def print_table_formatted(res: dict, name: str):
|
|
96
|
+
rebuild_colors = [bcolors.FAIL, bcolors.OKBLUE, bcolors.WARNING, bcolors.OKGREEN, bcolors.HEADER]
|
|
97
|
+
rebuild_index = random.randint(0, len(rebuild_colors) - 1)
|
|
98
|
+
rebuild_color = rebuild_colors[rebuild_index % len(rebuild_colors)]
|
|
99
|
+
data = []
|
|
100
|
+
limit = 5
|
|
101
|
+
for d in res["data"][:5]:
|
|
102
|
+
data.append(d.values())
|
|
103
|
+
meta = res["meta"]
|
|
104
|
+
row_count = res.get("rows", 0)
|
|
105
|
+
stats = res.get("statistics", {})
|
|
106
|
+
elapsed = stats.get("elapsed", 0)
|
|
107
|
+
cols = len(meta)
|
|
108
|
+
try:
|
|
109
|
+
|
|
110
|
+
def print_message(message: str, color=bcolors.CGREY):
|
|
111
|
+
return f"{color}{message}{bcolors.ENDC}"
|
|
112
|
+
|
|
113
|
+
table = format_table(data, meta)
|
|
114
|
+
colored_char = print_message("│", rebuild_color)
|
|
115
|
+
table_with_marker = "\n".join(f"{colored_char} {line}" for line in table.split("\n"))
|
|
116
|
+
click.echo(f"\n{colored_char} {print_message('⚡', rebuild_color)} Running {name}")
|
|
117
|
+
click.echo(colored_char)
|
|
118
|
+
click.echo(table_with_marker)
|
|
119
|
+
click.echo(colored_char)
|
|
120
|
+
rows_read = humanfriendly.format_number(stats.get("rows_read", 0))
|
|
121
|
+
bytes_read = humanfriendly.format_size(stats.get("bytes_read", 0))
|
|
122
|
+
elapsed = humanfriendly.format_timespan(elapsed) if elapsed >= 1 else f"{elapsed * 1000:.2f}ms"
|
|
123
|
+
stats_message = f"» {bytes_read} ({rows_read} rows x {cols} cols) in {elapsed}"
|
|
124
|
+
rows_message = f"» Showing {limit} first rows" if row_count > limit else "» Showing all rows"
|
|
125
|
+
click.echo(f"{colored_char} {print_message(stats_message, bcolors.OKGREEN)}")
|
|
126
|
+
click.echo(f"{colored_char} {print_message(rows_message, bcolors.CGREY)}")
|
|
127
|
+
except ValueError as exc:
|
|
128
|
+
if str(exc) == "max() arg is an empty sequence":
|
|
129
|
+
click.echo("------------")
|
|
130
|
+
click.echo("Empty")
|
|
131
|
+
click.echo("------------")
|
|
132
|
+
else:
|
|
133
|
+
raise exc
|
|
@@ -63,6 +63,7 @@ from tinybird.tb.modules.datafile.exceptions import (
|
|
|
63
63
|
from tinybird.tb.modules.datafile.parse_datasource import parse_datasource
|
|
64
64
|
from tinybird.tb.modules.datafile.parse_pipe import parse_pipe
|
|
65
65
|
from tinybird.tb.modules.datafile.pull import folder_pull
|
|
66
|
+
from tinybird.tb.modules.local_common import get_tinybird_local_client
|
|
66
67
|
from tinybird.tb.modules.telemetry import add_telemetry_event
|
|
67
68
|
|
|
68
69
|
__old_click_echo = click.echo
|
|
@@ -108,6 +109,7 @@ DEFAULT_PATTERNS: List[Tuple[str, Union[str, Callable[[str], str]]]] = [
|
|
|
108
109
|
"--with-headers", help="Flag to enable connector to export with headers", is_flag=True, default=False, hidden=True
|
|
109
110
|
)
|
|
110
111
|
@click.option("--show-tokens", is_flag=True, default=False, help="Enable the output of tokens")
|
|
112
|
+
@click.option("--local", is_flag=True, default=False, help="Run in local mode")
|
|
111
113
|
@click.version_option(version=VERSION)
|
|
112
114
|
@click.pass_context
|
|
113
115
|
@coro
|
|
@@ -131,6 +133,7 @@ async def cli(
|
|
|
131
133
|
sf_stage,
|
|
132
134
|
with_headers: bool,
|
|
133
135
|
show_tokens: bool,
|
|
136
|
+
local: bool,
|
|
134
137
|
) -> None:
|
|
135
138
|
"""
|
|
136
139
|
Use `OBFUSCATE_REGEX_PATTERN` and `OBFUSCATE_PATTERN_SEPARATOR` environment variables to define a regex pattern and a separator (in case of a single string with multiple regex) to obfuscate secrets in the CLI output.
|
|
@@ -228,7 +231,11 @@ async def cli(
|
|
|
228
231
|
|
|
229
232
|
logging.debug("debug enabled")
|
|
230
233
|
|
|
231
|
-
ctx.ensure_object(dict)["client"] =
|
|
234
|
+
ctx.ensure_object(dict)["client"] = (
|
|
235
|
+
await get_tinybird_local_client()
|
|
236
|
+
if local
|
|
237
|
+
else _get_tb_client(config.get("token", None), config["host"], semver)
|
|
238
|
+
)
|
|
232
239
|
|
|
233
240
|
for connector in SUPPORTED_CONNECTORS:
|
|
234
241
|
load_connector_config(ctx, connector, debug, check_uninstalled=True)
|