tinybird 5.0.2.dev0__tar.gz → 5.0.3__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.
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/PKG-INFO +16 -3
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/pyproject.toml +5 -5
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/sql_template.py +13 -8
- tinybird-5.0.3/tinybird/sql_template_fmt.py +514 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/__cli__.py +2 -2
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/local_common.py +1 -2
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tornado_template.py +2 -2
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/PKG-INFO +16 -3
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/SOURCES.txt +0 -3
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/requires.txt +3 -2
- tinybird-5.0.2.dev0/tinybird/sql_template_fmt.py +0 -286
- tinybird-5.0.2.dev0/tinybird/tb/modules/datafile/build_datasource.py +0 -409
- tinybird-5.0.2.dev0/tinybird/tb/modules/datafile/pipe_checker.py +0 -562
- tinybird-5.0.2.dev0/tinybird/tb/modules/datafile/playground.py +0 -1060
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/setup.cfg +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/__cli__.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/ch_utils/constants.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/ch_utils/engine.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/check_pypi.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/client.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/config.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/context.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datafile/common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datafile/exceptions.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datafile/parse_connection.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datafile/parse_datasource.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datafile/parse_pipe.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/datatypes.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/feedback_manager.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/git_settings.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/iterating/__init__.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/iterating/data_branch_modes.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/prompts.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/service_datasources.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/sql.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/sql_toolset.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/syncasync.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/check_pypi.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/cli.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/client.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/config.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/branch.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/build.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/build_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/cicd.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/cli.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/config.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/connection.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/connection_dynamodb.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/connection_kafka.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/connection_s3.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/copy.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/create.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/build.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/build_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/build_pipe.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/diff.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/fixture.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/format_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/format_connection.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/format_datasource.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/format_pipe.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datafile/pull.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/datasource.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/deployment.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/deployment_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/deprecations.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/endpoint.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/exceptions.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/feedback_manager.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/fmt.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/info.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/infra.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/job.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/job_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/llm.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/llm_utils.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/local.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/local_logs.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/login.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/login_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/logout.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/logs.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/materialization.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/open.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/pipe.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/preview.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/project.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/project_commands.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/py_project.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/query_output.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/regions.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/secret.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/secret_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/sink.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/table.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/telemetry.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/test.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/test_common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/tinyunit/tinyunit.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/token.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/ts_project.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/watch.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/workspace.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb/modules/workspace_members.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/auth.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/branch.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/cicd.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/cli.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/common.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/config.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/connection.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/datasource.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/exceptions.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/fmt.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/job.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/pipe.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/regions.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/tag.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/telemetry.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/test.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/workspace.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/tb_cli_modules/workspace_members.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/utils/__init__.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird/utils/bools.py +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/dependency_links.txt +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/entry_points.txt +0 -0
- {tinybird-5.0.2.dev0 → tinybird-5.0.3}/tinybird.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: tinybird
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.3
|
|
4
4
|
Summary: Tinybird Command Line Tool
|
|
5
5
|
Home-page: https://www.tinybird.co/docs/forward/commands
|
|
6
6
|
Author: Tinybird
|
|
@@ -9,6 +9,7 @@ Requires-Python: >=3.11, <3.14
|
|
|
9
9
|
Description-Content-Type: text/x-rst
|
|
10
10
|
Requires-Dist: aiofiles==24.1.0
|
|
11
11
|
Requires-Dist: boto3
|
|
12
|
+
Requires-Dist: certifi>=2026.10.19
|
|
12
13
|
Requires-Dist: click<8.2,>=8.1.6
|
|
13
14
|
Requires-Dist: clickhouse-toolset==0.34.dev0
|
|
14
15
|
Requires-Dist: colorama==0.4.6
|
|
@@ -24,8 +25,8 @@ Requires-Dist: pydantic~=2.11.7
|
|
|
24
25
|
Requires-Dist: pyperclip==1.9.0
|
|
25
26
|
Requires-Dist: pyyaml<6.1,>=6.0
|
|
26
27
|
Requires-Dist: requests<3,>=2.28.1
|
|
27
|
-
Requires-Dist: shandy-sqlfmt==0.
|
|
28
|
-
Requires-Dist: shandy-sqlfmt[jinjafmt]==0.
|
|
28
|
+
Requires-Dist: shandy-sqlfmt==0.29.0
|
|
29
|
+
Requires-Dist: shandy-sqlfmt[jinjafmt]==0.29.0
|
|
29
30
|
Requires-Dist: toposort==1.10
|
|
30
31
|
Requires-Dist: tornado~=6.5.5
|
|
31
32
|
Requires-Dist: urllib3<2,>=1.26.14
|
|
@@ -52,9 +53,21 @@ The Tinybird command-line tool allows you to use all the Tinybird functionality
|
|
|
52
53
|
Changelog
|
|
53
54
|
----------
|
|
54
55
|
|
|
56
|
+
5.0.3
|
|
57
|
+
*******
|
|
58
|
+
|
|
59
|
+
- `Changed` The CLI requires ``certifi>=2026.10.19``, which no longer trusts the compromised eMudhra intermediate CAs.
|
|
60
|
+
- `Changed` Upgrade the ``shandy-sqlfmt`` SQL formatter from 0.11.1 to 0.29.0. ``tb fmt`` keeps its existing output.
|
|
61
|
+
|
|
62
|
+
5.0.2
|
|
63
|
+
*******
|
|
64
|
+
|
|
65
|
+
- `Fixed` ``tb fmt`` keeps ClickHouse numeric literals such as ``1e9``, ``0x1F``, ``0b101``, ``0x1p4`` and ``1_000_000`` intact instead of splitting them into separate tokens.
|
|
66
|
+
|
|
55
67
|
5.0.1
|
|
56
68
|
*******
|
|
57
69
|
|
|
70
|
+
- `Fixed` SQL template ``backend_hint()`` and ``max_threads()`` directives so line breaks cannot escape their SQL comments.
|
|
58
71
|
- `Fixed` Git branches whose name starts with a digit (for example ``3-clean-up-tokens``) work with ``tb build`` and ``tb deploy``. Cloud branches keep the leading digit; Tinybird Local workspaces use a ``branch_`` prefix.
|
|
59
72
|
- `Fixed` ``tb branch clear <name>`` also finds the ``branch_``-prefixed name that ``tb branch create <name>`` generates. If the name matches more than one Branch, use the Branch ID.
|
|
60
73
|
|
|
@@ -71,7 +71,6 @@ dependencies = [
|
|
|
71
71
|
"orjson==3.11.9",
|
|
72
72
|
"packaging~=26.3",
|
|
73
73
|
"passlib==1.7.1",
|
|
74
|
-
"posthog==7.28.0",
|
|
75
74
|
"pre-commit==4.6.2",
|
|
76
75
|
"prometheus_client==0.26.0",
|
|
77
76
|
"prompt_toolkit==3.0.48",
|
|
@@ -99,8 +98,8 @@ dependencies = [
|
|
|
99
98
|
"requests~=2.32.5",
|
|
100
99
|
"sentry-sdk==2.69.2",
|
|
101
100
|
"setproctitle==1.3.3",
|
|
102
|
-
"shandy-sqlfmt==0.
|
|
103
|
-
"shandy-sqlfmt[jinjafmt]==0.
|
|
101
|
+
"shandy-sqlfmt==0.29.0",
|
|
102
|
+
"shandy-sqlfmt[jinjafmt]==0.29.0",
|
|
104
103
|
"sqlparse==0.4.3",
|
|
105
104
|
"starlette==1.0.1",
|
|
106
105
|
"streaming-form-data==1.20.0",
|
|
@@ -108,7 +107,7 @@ dependencies = [
|
|
|
108
107
|
"tabulate==0.8.10",
|
|
109
108
|
"thefuzz==0.22.1",
|
|
110
109
|
"tinybird-python-sdk[ai]==0.3.7",
|
|
111
|
-
"tinybird-toolset==2.
|
|
110
|
+
"tinybird-toolset==2.8.0",
|
|
112
111
|
"toposort==1.10",
|
|
113
112
|
"tornado==6.5.5",
|
|
114
113
|
"urllib3~=2.8",
|
|
@@ -155,7 +154,7 @@ lint = [
|
|
|
155
154
|
"flake8~=7.4",
|
|
156
155
|
"flake8-async~=26.8",
|
|
157
156
|
"mypy==2.3.1",
|
|
158
|
-
"ruff==0.
|
|
157
|
+
"ruff==0.17.0",
|
|
159
158
|
"types-Markdown",
|
|
160
159
|
"types-PyYAML",
|
|
161
160
|
"types-aiofiles==24.1.0.20241221",
|
|
@@ -210,6 +209,7 @@ members = [
|
|
|
210
209
|
"data_connector",
|
|
211
210
|
"gatherer",
|
|
212
211
|
"platform-api",
|
|
212
|
+
"songbird",
|
|
213
213
|
"tinybird_orchestrator",
|
|
214
214
|
]
|
|
215
215
|
|
|
@@ -1389,10 +1389,6 @@ _namespace = {
|
|
|
1389
1389
|
"__doc__": {},
|
|
1390
1390
|
"__name__": {},
|
|
1391
1391
|
"__package__": {},
|
|
1392
|
-
"open": None,
|
|
1393
|
-
"close": None,
|
|
1394
|
-
"print": None,
|
|
1395
|
-
"input": None,
|
|
1396
1392
|
}
|
|
1397
1393
|
|
|
1398
1394
|
|
|
@@ -1407,6 +1403,14 @@ reserved_vars.discard("id")
|
|
|
1407
1403
|
error_vars = ["error", "custom_error"]
|
|
1408
1404
|
|
|
1409
1405
|
|
|
1406
|
+
_SQL_COMMENT_UNSAFE_CHARS = re.compile(r"[\x00-\x1f\x7f\u2028\u2029]")
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
def _sql_comment_safe(value: Any) -> str:
|
|
1410
|
+
"""Make a value safe to put in a `--` SQL comment: a line break would end the comment."""
|
|
1411
|
+
return _SQL_COMMENT_UNSAFE_CHARS.sub(" ", str(value))
|
|
1412
|
+
|
|
1413
|
+
|
|
1410
1414
|
def generate(self, **kwargs) -> Tuple[str, TemplateExecutionResults]:
|
|
1411
1415
|
"""Generate this template with the given arguments."""
|
|
1412
1416
|
namespace = {}
|
|
@@ -1447,16 +1451,17 @@ def generate(self, **kwargs) -> Tuple[str, TemplateExecutionResults]:
|
|
|
1447
1451
|
|
|
1448
1452
|
def set_max_threads(x):
|
|
1449
1453
|
try:
|
|
1450
|
-
|
|
1451
|
-
return Expression(f"-- max_threads {x}\n")
|
|
1454
|
+
max_threads = int(x)
|
|
1452
1455
|
except Exception:
|
|
1453
|
-
return Expression(
|
|
1456
|
+
return Expression("-- max_threads: wrong argument\n")
|
|
1457
|
+
template_execution_results["max_threads"] = max_threads
|
|
1458
|
+
return Expression(f"-- max_threads {max_threads}\n")
|
|
1454
1459
|
|
|
1455
1460
|
def set_backend_hint(hint):
|
|
1456
1461
|
template_execution_results["backend_hint"] = str(hint)
|
|
1457
1462
|
if hint is None or hint is False:
|
|
1458
1463
|
template_execution_results["backend_hint"] = None
|
|
1459
|
-
return Expression(f"-- backend_hint {hint}\n")
|
|
1464
|
+
return Expression(f"-- backend_hint {_sql_comment_safe(hint)}\n")
|
|
1460
1465
|
|
|
1461
1466
|
def set_cache_ttl(ttl_expression):
|
|
1462
1467
|
valid_ttl_expressions = ("5s", "1m", "5m", "30m", "1h")
|
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import re
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from functools import partial
|
|
5
|
+
from types import MethodType
|
|
6
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
7
|
+
|
|
8
|
+
from sqlfmt import actions, api
|
|
9
|
+
from sqlfmt.analyzer import Analyzer
|
|
10
|
+
from sqlfmt.comment import Comment
|
|
11
|
+
from sqlfmt.dialect import ClickHouse
|
|
12
|
+
from sqlfmt.exception import SqlfmtBracketError
|
|
13
|
+
from sqlfmt.jinjafmt import JinjaFormatter, JinjaTag
|
|
14
|
+
from sqlfmt.line import Line
|
|
15
|
+
from sqlfmt.mode import Mode
|
|
16
|
+
from sqlfmt.node import Node, get_previous_token
|
|
17
|
+
from sqlfmt.node_manager import NodeManager
|
|
18
|
+
from sqlfmt.rule import Rule
|
|
19
|
+
from sqlfmt.rules.common import SQL_QUOTED_EXP, group
|
|
20
|
+
from sqlfmt.tokens import Token, TokenType
|
|
21
|
+
|
|
22
|
+
# This class extends and monkey patches https://github.com/tconbeer/sqlfm
|
|
23
|
+
INDENT = " " * 4
|
|
24
|
+
# This is the default value in tb fmt --diff, let's use the same
|
|
25
|
+
DEFAULT_FMT_LINE_LENGTH = 100
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class TBLine(Line):
|
|
30
|
+
def render_with_comments(self, max_length: int) -> str:
|
|
31
|
+
# 0.11 counted the trailing newline when deciding whether a comment
|
|
32
|
+
# fits and moved overflowing inline comments above the SQL line.
|
|
33
|
+
if len(self.comments) == 1 and not self.comments[0].is_standalone:
|
|
34
|
+
comment = self.comments[0]
|
|
35
|
+
if len(str(self).rstrip()) + len(comment.render_inline()) >= max_length:
|
|
36
|
+
return comment.render_standalone(max_length - 1, self.prefix) + str(self)
|
|
37
|
+
return super().render_with_comments(max_length - 1)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def prefix(self) -> str:
|
|
41
|
+
"""
|
|
42
|
+
Returns the whitespace to be printed at the start of this Line for
|
|
43
|
+
proper indentation.
|
|
44
|
+
|
|
45
|
+
Tinybird => This is overriden from the base Line because we want SQL inside a template to be indented
|
|
46
|
+
https://github.com/tconbeer/sqlfmt/blob/c11775b92d8a45f0e91d871b81a88a894d620bec/src/sqlfmt/line.py#L92
|
|
47
|
+
"""
|
|
48
|
+
return INDENT * (self.depth[0] + self.depth[1])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def from_nodes(
|
|
52
|
+
_cls: type[Line],
|
|
53
|
+
previous_node: Optional[Node],
|
|
54
|
+
nodes: List[Node],
|
|
55
|
+
comments: List[Comment],
|
|
56
|
+
) -> Line:
|
|
57
|
+
"""
|
|
58
|
+
Creates and returns a new line from a list of Nodes. Useful for line
|
|
59
|
+
splitting and merging.
|
|
60
|
+
|
|
61
|
+
Tinybird => Monkey patched to use `TBLine` and our own indentation logic.
|
|
62
|
+
"""
|
|
63
|
+
if nodes:
|
|
64
|
+
formatting_disabled = nodes[0].formatting_disabled + nodes[-1].formatting_disabled
|
|
65
|
+
else:
|
|
66
|
+
formatting_disabled = previous_node.formatting_disabled if previous_node is not None else []
|
|
67
|
+
|
|
68
|
+
return TBLine(
|
|
69
|
+
previous_node=previous_node,
|
|
70
|
+
nodes=nodes,
|
|
71
|
+
comments=comments,
|
|
72
|
+
formatting_disabled=formatting_disabled,
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _format_jinja_node(self: JinjaFormatter, node: Node, max_length: int) -> bool:
|
|
77
|
+
"""
|
|
78
|
+
Format a single jinja tag. No-ops for nodes that
|
|
79
|
+
are not jinja. Returns True if the node was blackened.
|
|
80
|
+
"""
|
|
81
|
+
if not node.is_jinja:
|
|
82
|
+
return False
|
|
83
|
+
|
|
84
|
+
tag = JinjaTag.from_string(node.value, node.depth)
|
|
85
|
+
if self.use_black and self.code_formatter.black is not None:
|
|
86
|
+
# Monkey patch black to preserve quote style inside Tinybird templates.
|
|
87
|
+
black = self.code_formatter.black
|
|
88
|
+
if not getattr(black, "_tinybird_preserve_string_normalization", False):
|
|
89
|
+
old_format_str = black.format_str
|
|
90
|
+
|
|
91
|
+
def format_str(string: str, mode: Any = None) -> str:
|
|
92
|
+
black_mode = black.Mode(
|
|
93
|
+
line_length=mode.line_length if mode is not None else max_length,
|
|
94
|
+
string_normalization=False,
|
|
95
|
+
)
|
|
96
|
+
return old_format_str(string, mode=black_mode)
|
|
97
|
+
|
|
98
|
+
black.format_str = format_str # type: ignore[attr-defined]
|
|
99
|
+
black._tinybird_preserve_string_normalization = True # type: ignore[attr-defined]
|
|
100
|
+
|
|
101
|
+
if tag.code and self.use_black:
|
|
102
|
+
tag.code, tag.is_blackened = self.code_formatter.format_string(
|
|
103
|
+
tag.code,
|
|
104
|
+
max_length=tag.max_code_length(max_length),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
if "{%" in node.value:
|
|
108
|
+
parts = tag.code.split("\n")
|
|
109
|
+
prefix = INDENT * (node.depth[0] + node.depth[1])
|
|
110
|
+
if len(parts) > 1:
|
|
111
|
+
tag.code = "\n".join([f"{prefix if i != 0 else ''}{part}" for i, part in enumerate(parts)])
|
|
112
|
+
|
|
113
|
+
node.value = str(tag)
|
|
114
|
+
|
|
115
|
+
return tag.is_blackened
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# Some monkey patching
|
|
119
|
+
Line.from_nodes = MethodType(from_nodes, Line) # type: ignore[method-assign]
|
|
120
|
+
JinjaFormatter._format_jinja_node = _format_jinja_node # type: ignore[method-assign]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class TinybirdNodeManager(NodeManager):
|
|
124
|
+
def __init__(self, case_sensitive_names: bool, lower_keywords: bool) -> None:
|
|
125
|
+
super().__init__(case_sensitive_names)
|
|
126
|
+
self.lower_keywords = lower_keywords
|
|
127
|
+
|
|
128
|
+
def create_node(self, token: Token, previous_node: Optional[Node]) -> Node:
|
|
129
|
+
try:
|
|
130
|
+
return super().create_node(token, previous_node)
|
|
131
|
+
except SqlfmtBracketError:
|
|
132
|
+
if token.token == ">":
|
|
133
|
+
raise
|
|
134
|
+
# we already have tb check and the toolset to check the SQL, no need for this extra validation
|
|
135
|
+
prev_token, extra_whitespace = get_previous_token(previous_node)
|
|
136
|
+
prefix = self.whitespace(token, prev_token, extra_whitespace)
|
|
137
|
+
value = self.standardize_value(token)
|
|
138
|
+
return Node(
|
|
139
|
+
token=token,
|
|
140
|
+
previous_node=previous_node,
|
|
141
|
+
prefix=prefix,
|
|
142
|
+
value=value,
|
|
143
|
+
formatting_disabled=[],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def raise_on_mismatched_bracket(self, token: Token, last_bracket: Node) -> None:
|
|
147
|
+
# sqlfmt first tries `>` as an angle bracket. Retry comparisons inside
|
|
148
|
+
# parentheses as operators instead of letting them consume the `(`.
|
|
149
|
+
if token.token == ">":
|
|
150
|
+
super().raise_on_mismatched_bracket(token, last_bracket)
|
|
151
|
+
|
|
152
|
+
def standardize_value(self, token: Token) -> str:
|
|
153
|
+
"""
|
|
154
|
+
Tinybird => Patched to not lower keywords
|
|
155
|
+
https://github.com/tconbeer/sqlfmt/blob/c11775b92d8a45f0e91d871b81a88a894d620bec/src/sqlfmt/node_manager.py#L215
|
|
156
|
+
"""
|
|
157
|
+
if self.lower_keywords:
|
|
158
|
+
return super().standardize_value(token)
|
|
159
|
+
|
|
160
|
+
if token.type in (
|
|
161
|
+
TokenType.UNTERM_KEYWORD,
|
|
162
|
+
TokenType.STATEMENT_START,
|
|
163
|
+
TokenType.STATEMENT_END,
|
|
164
|
+
TokenType.WORD_OPERATOR,
|
|
165
|
+
TokenType.ON,
|
|
166
|
+
TokenType.BOOLEAN_OPERATOR,
|
|
167
|
+
TokenType.SET_OPERATOR,
|
|
168
|
+
):
|
|
169
|
+
return " ".join(token.token.split())
|
|
170
|
+
return token.token
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _replace_rules(rules: Sequence[Rule], override_rules_by_name: Dict[str, Rule]) -> List[Rule]:
|
|
174
|
+
"""Replace rules by name, including nested sqlfmt rulesets."""
|
|
175
|
+
replaced_rules: List[Rule] = []
|
|
176
|
+
for rule in rules:
|
|
177
|
+
new_rule = override_rules_by_name.get(rule.name, rule)
|
|
178
|
+
action = new_rule.action
|
|
179
|
+
if isinstance(action, partial) and action.keywords:
|
|
180
|
+
keywords = dict(action.keywords)
|
|
181
|
+
changed = False
|
|
182
|
+
for key, value in keywords.items():
|
|
183
|
+
if isinstance(value, list) and all(isinstance(item, Rule) for item in value):
|
|
184
|
+
keywords[key] = _replace_rules(value, override_rules_by_name)
|
|
185
|
+
changed = True
|
|
186
|
+
if changed:
|
|
187
|
+
new_rule = Rule(
|
|
188
|
+
name=new_rule.name,
|
|
189
|
+
priority=new_rule.priority,
|
|
190
|
+
pattern=new_rule.pattern,
|
|
191
|
+
action=partial(action.func, *action.args, **keywords),
|
|
192
|
+
)
|
|
193
|
+
replaced_rules.append(new_rule)
|
|
194
|
+
return replaced_rules
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _has_inline_jinja_block(sql: str) -> bool:
|
|
198
|
+
"""Return whether every Jinja control block has an inline body.
|
|
199
|
+
|
|
200
|
+
Opening tags can span several lines when their Python expression is long.
|
|
201
|
+
That formatting alone must not make an otherwise inline block look like a
|
|
202
|
+
multiline one. Match each opening tag with its end tag, then inspect only
|
|
203
|
+
the body between them. We conservatively skip the compatibility pass for
|
|
204
|
+
malformed or genuinely mixed templates, because the pass works on the
|
|
205
|
+
formatted output and cannot safely select individual blocks there.
|
|
206
|
+
"""
|
|
207
|
+
tag_pattern = re.compile(
|
|
208
|
+
r"\{%-?\s*(?P<start>if|for)\b.*?-?%\}|"
|
|
209
|
+
r"\{%-?\s*end(?:\s+(?P<end>if|for))?\s*-?%\}",
|
|
210
|
+
flags=re.IGNORECASE | re.DOTALL,
|
|
211
|
+
)
|
|
212
|
+
blocks: List[tuple[int, str]] = []
|
|
213
|
+
has_control_block = False
|
|
214
|
+
|
|
215
|
+
for tag in tag_pattern.finditer(sql):
|
|
216
|
+
start_kind = tag.group("start")
|
|
217
|
+
if start_kind is not None:
|
|
218
|
+
has_control_block = True
|
|
219
|
+
blocks.append((tag.end(), start_kind.lower()))
|
|
220
|
+
continue
|
|
221
|
+
|
|
222
|
+
if not blocks:
|
|
223
|
+
return False
|
|
224
|
+
|
|
225
|
+
body_start, start_kind = blocks.pop()
|
|
226
|
+
end_kind = tag.group("end")
|
|
227
|
+
if end_kind is not None and end_kind.lower() != start_kind:
|
|
228
|
+
return False
|
|
229
|
+
if "\n" in sql[body_start : tag.start()]:
|
|
230
|
+
return False
|
|
231
|
+
|
|
232
|
+
return has_control_block and not blocks
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _preserve_inline_jinja_blocks(source_sql: str, formatted_sql: str, line_length: int) -> str:
|
|
236
|
+
"""Keep Tinybird's old inline Jinja-block style when the input used it.
|
|
237
|
+
|
|
238
|
+
sqlfmt 0.28 formats recognized Jinja blocks structurally, which turns
|
|
239
|
+
``{% if ... %} select 1 {% end %}`` into multiple lines. That is a valid
|
|
240
|
+
formatting choice, but it creates formatting-only diffs for existing CLI
|
|
241
|
+
users. Preserve the previous Tinybird style only for inputs that already had
|
|
242
|
+
inline block contents; multiline blocks still benefit from proper nested
|
|
243
|
+
block indentation.
|
|
244
|
+
"""
|
|
245
|
+
if not _has_inline_jinja_block(source_sql):
|
|
246
|
+
return formatted_sql
|
|
247
|
+
|
|
248
|
+
lines = formatted_sql.splitlines()
|
|
249
|
+
compacted_lines: List[str] = []
|
|
250
|
+
branch_tag = re.compile(r"\{%-?\s*(if|for|elif|else)\b.*?-?%\}$", flags=re.IGNORECASE)
|
|
251
|
+
chain_tag = re.compile(r"\{%-?\s*(elif|else|end)\b", flags=re.IGNORECASE)
|
|
252
|
+
|
|
253
|
+
def single_line_body(at: int) -> Optional[str]:
|
|
254
|
+
"""Return lines[at] when it is a one-line body followed by a tag line."""
|
|
255
|
+
if at + 1 >= len(lines):
|
|
256
|
+
return None
|
|
257
|
+
body = lines[at].strip()
|
|
258
|
+
# A multiline {{ expression }} must retain its newline: joining
|
|
259
|
+
# its opening {{ makes the next tb fmt pass undo this one.
|
|
260
|
+
if not body or body.startswith("{%") or (body.startswith("{{") and not body.endswith("}}")):
|
|
261
|
+
return None
|
|
262
|
+
return body if lines[at + 1].strip().startswith("{%") else None
|
|
263
|
+
|
|
264
|
+
inline_branch = re.compile(r"\{%-?\s*(elif|else)\b.*?-?%\}\s+[^{\s][^{]*$", flags=re.IGNORECASE)
|
|
265
|
+
open_tag: Optional[str] = None
|
|
266
|
+
index = 0
|
|
267
|
+
while index < len(lines):
|
|
268
|
+
line = lines[index]
|
|
269
|
+
stripped = line.strip()
|
|
270
|
+
# Only opening/branch tags can absorb an inline body in 0.11; joining
|
|
271
|
+
# text after {% end %} would move the following SQL clause or comment.
|
|
272
|
+
if open_tag is not None and "{%" not in stripped and stripped.endswith("%}"):
|
|
273
|
+
# Closing line of a tag whose long condition spans several lines.
|
|
274
|
+
last_tag = f"{open_tag} {stripped}"
|
|
275
|
+
open_tag = None
|
|
276
|
+
else:
|
|
277
|
+
last_tag = stripped[stripped.rfind("{%") :]
|
|
278
|
+
if "{%" in stripped and "%}" not in last_tag:
|
|
279
|
+
open_tag = last_tag
|
|
280
|
+
body = single_line_body(index + 1) if branch_tag.match(last_tag) else None
|
|
281
|
+
if body is None:
|
|
282
|
+
compacted_lines.append(line)
|
|
283
|
+
index += 1
|
|
284
|
+
continue
|
|
285
|
+
|
|
286
|
+
first = f"{line.rstrip()} {body}"
|
|
287
|
+
# Try to fold the whole if/elif/else/end chain onto one line.
|
|
288
|
+
chain = [first]
|
|
289
|
+
closed = False
|
|
290
|
+
cursor = index + 2
|
|
291
|
+
while cursor < len(lines) and chain_tag.match(lines[cursor].strip()):
|
|
292
|
+
tag_line = lines[cursor].strip()
|
|
293
|
+
cursor += 1
|
|
294
|
+
if re.match(r"\{%-?\s*end\b", tag_line, flags=re.IGNORECASE):
|
|
295
|
+
chain.append(tag_line)
|
|
296
|
+
closed = True
|
|
297
|
+
break
|
|
298
|
+
if inline_branch.match(tag_line):
|
|
299
|
+
chain.append(tag_line)
|
|
300
|
+
continue
|
|
301
|
+
branch_body = single_line_body(cursor) if branch_tag.match(tag_line) else None
|
|
302
|
+
if branch_body is None:
|
|
303
|
+
break
|
|
304
|
+
chain.append(f"{tag_line} {branch_body}")
|
|
305
|
+
cursor += 1
|
|
306
|
+
joined = " ".join(chain)
|
|
307
|
+
if closed and len(joined) <= line_length:
|
|
308
|
+
compacted_lines.append(joined)
|
|
309
|
+
index = cursor
|
|
310
|
+
elif len(first) <= line_length:
|
|
311
|
+
compacted_lines.append(first)
|
|
312
|
+
index += 2
|
|
313
|
+
else:
|
|
314
|
+
compacted_lines.append(line)
|
|
315
|
+
index += 1
|
|
316
|
+
|
|
317
|
+
return "\n".join(compacted_lines)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _preserve_legacy_formatting(source_sql: str, formatted_sql: str, line_length: int) -> str:
|
|
321
|
+
"""Apply compatibility shims for customer-visible Tinybird formatting.
|
|
322
|
+
|
|
323
|
+
These transformations intentionally preserve quirks from the sqlfmt 0.11
|
|
324
|
+
based CLI output. The dependency upgrade is for Python 3.14 compatibility;
|
|
325
|
+
it should not make customer projects fail `tb fmt --diff` because of style
|
|
326
|
+
churn unrelated to their code.
|
|
327
|
+
"""
|
|
328
|
+
formatted_sql = _preserve_inline_jinja_blocks(source_sql, formatted_sql, line_length)
|
|
329
|
+
if re.search(r"\bas\s+end\b", source_sql, flags=re.IGNORECASE):
|
|
330
|
+
# When `end` is a column alias, 0.11 kept adjacent Jinja control tags
|
|
331
|
+
# on the same line instead of treating the alias as a CASE terminator.
|
|
332
|
+
formatted_sql = re.sub(r"(?m)^end\n(?=\{%\s*(?:else|end)\b)", "end ", formatted_sql)
|
|
333
|
+
lines = formatted_sql.splitlines()
|
|
334
|
+
# 0.11 attached a trailing comment on two AND terms to the first term;
|
|
335
|
+
# 0.28 attaches it to the last, mislabeling the condition in tb fmt output.
|
|
336
|
+
source_comments = {
|
|
337
|
+
line.split("--", 1)[1].strip(): line.strip()
|
|
338
|
+
for line in source_sql.splitlines()
|
|
339
|
+
if "--" in line and line.lstrip().lower().startswith("and ")
|
|
340
|
+
}
|
|
341
|
+
index = 1
|
|
342
|
+
while index < len(lines):
|
|
343
|
+
previous, current = lines[index - 1], lines[index]
|
|
344
|
+
if (
|
|
345
|
+
" --" in current
|
|
346
|
+
and current.lstrip().lower().startswith("and ")
|
|
347
|
+
and previous.lstrip().lower().startswith("and ")
|
|
348
|
+
):
|
|
349
|
+
statement, comment = current.split(" --", 1)
|
|
350
|
+
source_line = source_comments.get(comment.strip(), "")
|
|
351
|
+
if source_line.lower().count(" and ") >= 1:
|
|
352
|
+
lines[index - 1] = f"{previous} --{comment}"
|
|
353
|
+
lines[index] = statement.rstrip()
|
|
354
|
+
previous, current = lines[index - 1], lines[index]
|
|
355
|
+
# 0.11 kept a following any(...) select item on the same line when
|
|
356
|
+
# space allowed; 0.28 always splits these qualified/long expressions.
|
|
357
|
+
if (
|
|
358
|
+
previous.endswith(",")
|
|
359
|
+
and ("." in previous or "(" in previous or len(previous.strip()) >= 26)
|
|
360
|
+
and not previous.lstrip().lower().startswith("any (")
|
|
361
|
+
and current.lstrip().lower().startswith("any (")
|
|
362
|
+
and len(previous) - len(previous.lstrip()) == len(current) - len(current.lstrip())
|
|
363
|
+
and len(previous) + 1 + len(current.strip()) <= line_length
|
|
364
|
+
):
|
|
365
|
+
lines[index - 1] = f"{previous} {current.strip()}"
|
|
366
|
+
lines.pop(index)
|
|
367
|
+
else:
|
|
368
|
+
index += 1
|
|
369
|
+
return "\n".join(lines)
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
class TinybirdDialect(ClickHouse):
|
|
373
|
+
"""
|
|
374
|
+
This is an extension of the base rules.
|
|
375
|
+
|
|
376
|
+
We might need to override the base `word_operator` and `unterm_keyword` rules with some custom ClickHouse terms.
|
|
377
|
+
|
|
378
|
+
For now we are just overriding the end blocks for `if` and `for` to work with Tornado templates.
|
|
379
|
+
|
|
380
|
+
https://github.com/tconbeer/sqlfmt/blob/c11775b92d8a45f0e91d871b81a88a894d620bec/src/sqlfmt/dialect.py#L55
|
|
381
|
+
"""
|
|
382
|
+
|
|
383
|
+
def __init__(self, lower_keywords: bool = False) -> None:
|
|
384
|
+
super().__init__()
|
|
385
|
+
self.lower_keywords = lower_keywords
|
|
386
|
+
|
|
387
|
+
override_rules = [
|
|
388
|
+
Rule(
|
|
389
|
+
name="number",
|
|
390
|
+
priority=401,
|
|
391
|
+
pattern=group(
|
|
392
|
+
r"-?0x[0-9a-f][0-9a-f_]*(\.[0-9a-f_]*)?(p[+-]?\d[\d_]*)?",
|
|
393
|
+
r"-?0b[01][01_]*",
|
|
394
|
+
r"-?(\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(e[+-]?\d[\d_]*)?",
|
|
395
|
+
),
|
|
396
|
+
action=partial(actions.add_node_to_buffer, token_type=TokenType.NUMBER),
|
|
397
|
+
),
|
|
398
|
+
Rule(
|
|
399
|
+
name="quoted_name",
|
|
400
|
+
priority=200,
|
|
401
|
+
pattern=group(
|
|
402
|
+
SQL_QUOTED_EXP,
|
|
403
|
+
r"((?<!\\)\$[\w$]+)", # Words starting with $ for .incl files
|
|
404
|
+
),
|
|
405
|
+
action=partial(actions.add_node_to_buffer, token_type=TokenType.QUOTED_NAME),
|
|
406
|
+
),
|
|
407
|
+
Rule(
|
|
408
|
+
name="legacy_array_join",
|
|
409
|
+
priority=1040,
|
|
410
|
+
# 0.11 parsed ARRAY and JOIN separately, so wrapped joins keep
|
|
411
|
+
# ARRAY at the end of the preceding line.
|
|
412
|
+
pattern=group(r"array(?=\s+join\b)"),
|
|
413
|
+
action=partial(actions.add_node_to_buffer, token_type=TokenType.NAME),
|
|
414
|
+
),
|
|
415
|
+
Rule(
|
|
416
|
+
name="join_using",
|
|
417
|
+
priority=1049,
|
|
418
|
+
# sqlfmt 0.11 treats USING without parentheses as a word operator.
|
|
419
|
+
pattern=group(r"using") + group(r"\W", r"$"),
|
|
420
|
+
action=partial(actions.add_node_to_buffer, token_type=TokenType.WORD_OPERATOR),
|
|
421
|
+
),
|
|
422
|
+
Rule(
|
|
423
|
+
name="legacy_any_operator",
|
|
424
|
+
priority=1098,
|
|
425
|
+
# 0.11 classified any(...) as an operator and printed any (...).
|
|
426
|
+
pattern=group(r"any") + group(r"\W", r"$"),
|
|
427
|
+
action=partial(actions.add_node_to_buffer, token_type=TokenType.WORD_OPERATOR),
|
|
428
|
+
),
|
|
429
|
+
Rule(
|
|
430
|
+
name="jinja_if_block_end",
|
|
431
|
+
priority=203,
|
|
432
|
+
# Accept both Tornado-style {% end %} and {% end if %}.
|
|
433
|
+
pattern=group(r"\{%-?\s*end(\s+if)?\s*-?%\}"),
|
|
434
|
+
action=actions.handle_jinja_block_end,
|
|
435
|
+
),
|
|
436
|
+
Rule(
|
|
437
|
+
name="jinja_for_block_end",
|
|
438
|
+
priority=211,
|
|
439
|
+
# Accept both Tornado-style {% end %} and {% end for %}.
|
|
440
|
+
pattern=group(r"\{%-?\s*end(\s+for)?\s*-?%\}"),
|
|
441
|
+
action=actions.handle_jinja_block_end,
|
|
442
|
+
),
|
|
443
|
+
]
|
|
444
|
+
|
|
445
|
+
override_rules_by_name = {rule.name: rule for rule in override_rules}
|
|
446
|
+
self.RULES = _replace_rules(self.RULES, override_rules_by_name)
|
|
447
|
+
# Unlike USING, these are extra legacy tokens absent from 0.28's
|
|
448
|
+
# ruleset; register them so old projects keep their formatted output.
|
|
449
|
+
self.RULES.insert(0, override_rules_by_name["legacy_any_operator"])
|
|
450
|
+
self.RULES.insert(0, override_rules_by_name["legacy_array_join"])
|
|
451
|
+
|
|
452
|
+
def initialize_analyzer(self, line_length: int) -> Analyzer:
|
|
453
|
+
"""
|
|
454
|
+
Creates and returns an analyzer that uses the Dialect's rules for lexing
|
|
455
|
+
Custom NodeManager for Tinybird
|
|
456
|
+
"""
|
|
457
|
+
return Analyzer(
|
|
458
|
+
line_length=line_length,
|
|
459
|
+
rules=self.get_rules(),
|
|
460
|
+
node_manager=TinybirdNodeManager(self.case_sensitive_names, self.lower_keywords),
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
@dataclass
|
|
465
|
+
class TBMode(Mode):
|
|
466
|
+
lower_keywords: bool = False
|
|
467
|
+
|
|
468
|
+
def __post_init__(self) -> None:
|
|
469
|
+
"""
|
|
470
|
+
Tinybird => Overriden to use `TinybirdDialect`
|
|
471
|
+
https://github.com/tconbeer/sqlfmt/blob/c11775b92d8a45f0e91d871b81a88a894d620bec/src/sqlfmt/mode.py#L31
|
|
472
|
+
"""
|
|
473
|
+
self.dialect = TinybirdDialect(self.lower_keywords)
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _calc_str(self) -> str:
|
|
477
|
+
if self.is_multiline:
|
|
478
|
+
return self.token.token + "\n"
|
|
479
|
+
marker, comment_text = self._comment_parts()
|
|
480
|
+
if comment_text == "":
|
|
481
|
+
return marker + "\n"
|
|
482
|
+
return marker + " " + comment_text + "\n"
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
Comment._calc_str = property(_calc_str) # type: ignore[attr-defined]
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def format_sql_template(
|
|
489
|
+
sql: str,
|
|
490
|
+
line_length: Optional[int] = None,
|
|
491
|
+
lower_keywords: bool = False,
|
|
492
|
+
resource_name: Optional[str] = None,
|
|
493
|
+
resource_source: Optional[str] = None,
|
|
494
|
+
) -> str:
|
|
495
|
+
try:
|
|
496
|
+
# https://github.com/tconbeer/sqlfmt/blob/c11775b92d8a45f0e91d871b81a88a894d620bec/src/sqlfmt/mode.py#L16-L29
|
|
497
|
+
config: Dict[str, Any] = {
|
|
498
|
+
"line_length": line_length or DEFAULT_FMT_LINE_LENGTH,
|
|
499
|
+
"lower_keywords": lower_keywords,
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
mode = TBMode(**config)
|
|
503
|
+
sql = sql.strip()
|
|
504
|
+
formatted_sql = (
|
|
505
|
+
"%\n" + api.format_string(sql[1:], mode=mode).strip()
|
|
506
|
+
if sql[0] == "%"
|
|
507
|
+
else api.format_string(sql, mode=mode).strip()
|
|
508
|
+
)
|
|
509
|
+
return _preserve_legacy_formatting(sql, formatted_sql, mode.line_length)
|
|
510
|
+
except Exception as e:
|
|
511
|
+
resource_info = f" in '{resource_name}'" if resource_name else ""
|
|
512
|
+
source_info = f" ({resource_source})" if resource_source else ""
|
|
513
|
+
logging.warning(f"sqlfmt error{resource_info}{source_info}: {str(e)}")
|
|
514
|
+
return sql
|
|
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
|
|
|
4
4
|
__url__ = 'https://www.tinybird.co/docs/forward/commands'
|
|
5
5
|
__author__ = 'Tinybird'
|
|
6
6
|
__author_email__ = 'support@tinybird.co'
|
|
7
|
-
__version__ = '5.0.
|
|
8
|
-
__revision__ = '
|
|
7
|
+
__version__ = '5.0.3'
|
|
8
|
+
__revision__ = 'ef090149'
|
|
@@ -17,7 +17,6 @@ from docker.client import DockerClient
|
|
|
17
17
|
from docker.errors import ImageNotFound
|
|
18
18
|
from docker.models.containers import Container
|
|
19
19
|
|
|
20
|
-
import docker
|
|
21
20
|
from tinybird.tb.client import AuthNoTokenException, TinyB
|
|
22
21
|
from tinybird.tb.modules.config import CLIConfig
|
|
23
22
|
from tinybird.tb.modules.exceptions import CLILocalException
|
|
@@ -683,7 +682,7 @@ def get_docker_client() -> DockerClient:
|
|
|
683
682
|
except Exception:
|
|
684
683
|
pass
|
|
685
684
|
try:
|
|
686
|
-
client =
|
|
685
|
+
client = DockerClient.from_env()
|
|
687
686
|
except Exception as e:
|
|
688
687
|
add_telemetry_event(
|
|
689
688
|
"docker_error",
|