sqlmesh 0.206.1.dev3__py3-none-any.whl → 0.206.2.dev2__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.
- sqlmesh/_version.py +2 -2
- sqlmesh/core/linter/helpers.py +52 -0
- sqlmesh/core/linter/rule.py +11 -2
- sqlmesh/core/linter/rules/builtin.py +19 -2
- sqlmesh/core/renderer.py +1 -3
- sqlmesh/lsp/context.py +35 -4
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/METADATA +1 -1
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/RECORD +12 -12
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/WHEEL +0 -0
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/entry_points.txt +0 -0
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/licenses/LICENSE +0 -0
- {sqlmesh-0.206.1.dev3.dist-info → sqlmesh-0.206.2.dev2.dist-info}/top_level.txt +0 -0
sqlmesh/_version.py
CHANGED
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.206.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 206,
|
|
20
|
+
__version__ = version = '0.206.2.dev2'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 206, 2, 'dev2')
|
sqlmesh/core/linter/helpers.py
CHANGED
|
@@ -158,3 +158,55 @@ def get_range_of_model_block(
|
|
|
158
158
|
return Range(
|
|
159
159
|
start=start_position.to_range(splitlines).start, end=end_position.to_range(splitlines).end
|
|
160
160
|
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def get_range_of_a_key_in_model_block(
|
|
164
|
+
sql: str,
|
|
165
|
+
dialect: str,
|
|
166
|
+
key: str,
|
|
167
|
+
) -> t.Optional[Range]:
|
|
168
|
+
"""
|
|
169
|
+
Get the range of a specific key in the model block of an SQL file.
|
|
170
|
+
"""
|
|
171
|
+
tokens = tokenize(sql, dialect=dialect)
|
|
172
|
+
if tokens is None:
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
# Find the start of the model block
|
|
176
|
+
start_index = next(
|
|
177
|
+
(
|
|
178
|
+
i
|
|
179
|
+
for i, t in enumerate(tokens)
|
|
180
|
+
if t.token_type is TokenType.VAR and t.text.upper() == "MODEL"
|
|
181
|
+
),
|
|
182
|
+
None,
|
|
183
|
+
)
|
|
184
|
+
end_index = next(
|
|
185
|
+
(i for i, t in enumerate(tokens) if t.token_type is TokenType.SEMICOLON),
|
|
186
|
+
None,
|
|
187
|
+
)
|
|
188
|
+
if start_index is None or end_index is None:
|
|
189
|
+
return None
|
|
190
|
+
if start_index >= end_index:
|
|
191
|
+
return None
|
|
192
|
+
|
|
193
|
+
tokens_of_interest = tokens[start_index + 1 : end_index]
|
|
194
|
+
# Find the key token
|
|
195
|
+
key_token = next(
|
|
196
|
+
(
|
|
197
|
+
t
|
|
198
|
+
for t in tokens_of_interest
|
|
199
|
+
if t.token_type is TokenType.VAR and t.text.upper() == key.upper()
|
|
200
|
+
),
|
|
201
|
+
None,
|
|
202
|
+
)
|
|
203
|
+
if key_token is None:
|
|
204
|
+
return None
|
|
205
|
+
|
|
206
|
+
position = TokenPositionDetails(
|
|
207
|
+
line=key_token.line,
|
|
208
|
+
col=key_token.col,
|
|
209
|
+
start=key_token.start,
|
|
210
|
+
end=key_token.end,
|
|
211
|
+
)
|
|
212
|
+
return position.to_range(sql.splitlines())
|
sqlmesh/core/linter/rule.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import abc
|
|
4
|
-
from dataclasses import dataclass
|
|
4
|
+
from dataclasses import dataclass, field
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
7
|
from sqlmesh.core.model import Model
|
|
@@ -49,12 +49,21 @@ class TextEdit:
|
|
|
49
49
|
new_text: str
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
@dataclass(frozen=True)
|
|
53
|
+
class CreateFile:
|
|
54
|
+
"""Create a new file with the provided text."""
|
|
55
|
+
|
|
56
|
+
path: Path
|
|
57
|
+
text: str
|
|
58
|
+
|
|
59
|
+
|
|
52
60
|
@dataclass(frozen=True)
|
|
53
61
|
class Fix:
|
|
54
62
|
"""A fix that can be applied to resolve a rule violation."""
|
|
55
63
|
|
|
56
64
|
title: str
|
|
57
|
-
edits: t.List[TextEdit]
|
|
65
|
+
edits: t.List[TextEdit] = field(default_factory=list)
|
|
66
|
+
create_files: t.List[CreateFile] = field(default_factory=list)
|
|
58
67
|
|
|
59
68
|
|
|
60
69
|
class _Rule(abc.ABCMeta):
|
|
@@ -14,7 +14,15 @@ from sqlmesh.core.linter.helpers import (
|
|
|
14
14
|
get_range_of_model_block,
|
|
15
15
|
read_range_from_string,
|
|
16
16
|
)
|
|
17
|
-
from sqlmesh.core.linter.rule import
|
|
17
|
+
from sqlmesh.core.linter.rule import (
|
|
18
|
+
Rule,
|
|
19
|
+
RuleViolation,
|
|
20
|
+
Range,
|
|
21
|
+
Fix,
|
|
22
|
+
TextEdit,
|
|
23
|
+
Position,
|
|
24
|
+
CreateFile,
|
|
25
|
+
)
|
|
18
26
|
from sqlmesh.core.linter.definition import RuleSet
|
|
19
27
|
from sqlmesh.core.model import Model, SqlModel, ExternalModel
|
|
20
28
|
from sqlmesh.utils.lineage import extract_references_from_query, ExternalModelReference
|
|
@@ -227,7 +235,16 @@ class NoMissingExternalModels(Rule):
|
|
|
227
235
|
|
|
228
236
|
external_models_path = root / EXTERNAL_MODELS_YAML
|
|
229
237
|
if not external_models_path.exists():
|
|
230
|
-
return
|
|
238
|
+
return Fix(
|
|
239
|
+
title="Add external model file",
|
|
240
|
+
edits=[],
|
|
241
|
+
create_files=[
|
|
242
|
+
CreateFile(
|
|
243
|
+
path=external_models_path,
|
|
244
|
+
text=f"- name: '{model_name}'\n",
|
|
245
|
+
)
|
|
246
|
+
],
|
|
247
|
+
)
|
|
231
248
|
|
|
232
249
|
# Figure out the position to insert the new external model at the end of the file, whether
|
|
233
250
|
# needs new line or not.
|
sqlmesh/core/renderer.py
CHANGED
|
@@ -523,8 +523,6 @@ class QueryRenderer(BaseExpressionRenderer):
|
|
|
523
523
|
runtime_stage, start, end, execution_time, *kwargs.values()
|
|
524
524
|
)
|
|
525
525
|
|
|
526
|
-
needs_optimization = needs_optimization and self._optimize_query_flag
|
|
527
|
-
|
|
528
526
|
if should_cache and self._optimized_cache:
|
|
529
527
|
query = self._optimized_cache
|
|
530
528
|
else:
|
|
@@ -560,7 +558,7 @@ class QueryRenderer(BaseExpressionRenderer):
|
|
|
560
558
|
)
|
|
561
559
|
raise
|
|
562
560
|
|
|
563
|
-
if needs_optimization:
|
|
561
|
+
if needs_optimization and self._optimize_query_flag:
|
|
564
562
|
deps = d.find_tables(
|
|
565
563
|
query, default_catalog=self._default_catalog, dialect=self._dialect
|
|
566
564
|
)
|
sqlmesh/lsp/context.py
CHANGED
|
@@ -273,13 +273,41 @@ class LSPContext:
|
|
|
273
273
|
if found_violation is not None and found_violation.fixes:
|
|
274
274
|
# Create code actions for each fix
|
|
275
275
|
for fix in found_violation.fixes:
|
|
276
|
-
# Convert our Fix to LSP TextEdits
|
|
277
276
|
changes: t.Dict[str, t.List[types.TextEdit]] = {}
|
|
277
|
+
document_changes: t.List[
|
|
278
|
+
t.Union[
|
|
279
|
+
types.TextDocumentEdit,
|
|
280
|
+
types.CreateFile,
|
|
281
|
+
types.RenameFile,
|
|
282
|
+
types.DeleteFile,
|
|
283
|
+
]
|
|
284
|
+
] = []
|
|
285
|
+
|
|
286
|
+
for create in fix.create_files:
|
|
287
|
+
create_uri = URI.from_path(create.path).value
|
|
288
|
+
document_changes.append(types.CreateFile(uri=create_uri))
|
|
289
|
+
document_changes.append(
|
|
290
|
+
types.TextDocumentEdit(
|
|
291
|
+
text_document=types.OptionalVersionedTextDocumentIdentifier(
|
|
292
|
+
uri=create_uri,
|
|
293
|
+
version=None,
|
|
294
|
+
),
|
|
295
|
+
edits=[
|
|
296
|
+
types.TextEdit(
|
|
297
|
+
range=types.Range(
|
|
298
|
+
start=types.Position(line=0, character=0),
|
|
299
|
+
end=types.Position(line=0, character=0),
|
|
300
|
+
),
|
|
301
|
+
new_text=create.text,
|
|
302
|
+
)
|
|
303
|
+
],
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
|
|
278
307
|
for edit in fix.edits:
|
|
279
308
|
uri_key = URI.from_path(edit.path).value
|
|
280
309
|
if uri_key not in changes:
|
|
281
310
|
changes[uri_key] = []
|
|
282
|
-
# Create a TextEdit for the LSP
|
|
283
311
|
changes[uri_key].append(
|
|
284
312
|
types.TextEdit(
|
|
285
313
|
range=types.Range(
|
|
@@ -296,12 +324,15 @@ class LSPContext:
|
|
|
296
324
|
)
|
|
297
325
|
)
|
|
298
326
|
|
|
299
|
-
|
|
327
|
+
workspace_edit = types.WorkspaceEdit(
|
|
328
|
+
changes=changes if changes else None,
|
|
329
|
+
document_changes=document_changes if document_changes else None,
|
|
330
|
+
)
|
|
300
331
|
code_action = types.CodeAction(
|
|
301
332
|
title=fix.title,
|
|
302
333
|
kind=types.CodeActionKind.QuickFix,
|
|
303
334
|
diagnostics=[diagnostic],
|
|
304
|
-
edit=
|
|
335
|
+
edit=workspace_edit,
|
|
305
336
|
)
|
|
306
337
|
code_actions.append(code_action)
|
|
307
338
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
sqlmesh/__init__.py,sha256=QjwaamJIdW7voXoS880yAx7tHm-Im4_mqGA-XJgafos,7631
|
|
2
|
-
sqlmesh/_version.py,sha256=
|
|
2
|
+
sqlmesh/_version.py,sha256=ODmuGfXnsHOG7yOzSoA-XJjd_1OkCpWgVFsH_K0ggDM,528
|
|
3
3
|
sqlmesh/magics.py,sha256=bEzYqXHcM0P3CjyUZ1O9arlmXAdLAhoglKbQ29fD9AE,41842
|
|
4
4
|
sqlmesh/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
sqlmesh/cicd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -23,7 +23,7 @@ sqlmesh/core/macros.py,sha256=h99VzqXXjFZYA0t2730HKdq4NP6tYo-VKvcpwipAneQ,62422
|
|
|
23
23
|
sqlmesh/core/node.py,sha256=3ChBz1PIMJhp-jzed_GLBrtmEF2v_BVDEM5WNe0ssPk,14658
|
|
24
24
|
sqlmesh/core/notification_target.py,sha256=PPGoDrgbRKxr27vJEu03XqNTQLYTw0ZF_b0yAapxGeI,16158
|
|
25
25
|
sqlmesh/core/reference.py,sha256=k7OSkLqTjPR8WJjNeFj0xAJ297nZUMgb_iTVwKRRKjc,4875
|
|
26
|
-
sqlmesh/core/renderer.py,sha256=
|
|
26
|
+
sqlmesh/core/renderer.py,sha256=PMUmmtwqk3FA5lN-16OWl6buCbrVa1M8NIgRXCYEB8k,26805
|
|
27
27
|
sqlmesh/core/scheduler.py,sha256=CeI-15GrraLUI5YO8fQUACj7WG7dY6otE4TaJOp2_IU,41041
|
|
28
28
|
sqlmesh/core/schema_diff.py,sha256=Sp2MoqAngp-yTYevkLaf9jb26SuAdGXoZ54g5MjWowU,30516
|
|
29
29
|
sqlmesh/core/schema_loader.py,sha256=_Pq2RSw91uthqv1vNi_eHmLlzhtGz_APMJ0wAJZYuvk,3677
|
|
@@ -77,10 +77,10 @@ sqlmesh/core/engine_adapter/spark.py,sha256=sYkVOPS0X43UPbI0z7Hh_EpKlI36qkOcr4NN
|
|
|
77
77
|
sqlmesh/core/engine_adapter/trino.py,sha256=Tws3GxqnC6BmXFohqru1TDxsgPH-21qV6Oky7FaaLpE,15908
|
|
78
78
|
sqlmesh/core/linter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
79
79
|
sqlmesh/core/linter/definition.py,sha256=JDJTkhByUw4Tr3nF-BOHKFAx_eASQqEqzX6AUVQUz8I,5659
|
|
80
|
-
sqlmesh/core/linter/helpers.py,sha256=
|
|
81
|
-
sqlmesh/core/linter/rule.py,sha256=
|
|
80
|
+
sqlmesh/core/linter/helpers.py,sha256=Bv11aGRIrnv9Ym9fudy3XQB0k-FvchkLtBTkGI91SEw,6504
|
|
81
|
+
sqlmesh/core/linter/rule.py,sha256=nB3o1rHyN44ZOg5ImICP16SeUHimf-12ObdXJjkTGyM,3964
|
|
82
82
|
sqlmesh/core/linter/rules/__init__.py,sha256=gevzfb67vFqckTCoVAe_TBGf6hQ-YtE1_YuGuXyh1L0,77
|
|
83
|
-
sqlmesh/core/linter/rules/builtin.py,sha256=
|
|
83
|
+
sqlmesh/core/linter/rules/builtin.py,sha256=BVBoBr1Ru-DA4VPnwfaodZdVq84afCc9qBgPLmwrfiA,10204
|
|
84
84
|
sqlmesh/core/metric/__init__.py,sha256=H1HmoD5IwN4YWe9iJXyueLYNmTQFZwok5nSWNJcZIBQ,237
|
|
85
85
|
sqlmesh/core/metric/definition.py,sha256=Yd5aVgsZCDPJ43aGP7WqtzZOuuSUtB8uJGVA6Jw9x9M,7201
|
|
86
86
|
sqlmesh/core/metric/rewriter.py,sha256=GiSTHfn2kinqCfNPYgZPRk93JFLzVaaejHtHDQ0yXZI,7326
|
|
@@ -166,7 +166,7 @@ sqlmesh/integrations/github/cicd/controller.py,sha256=0I5mHPz3HBJR5lkR-2J9Bj06Yn
|
|
|
166
166
|
sqlmesh/lsp/api.py,sha256=_lA_buSPZFIoLJuINbS53LbNOOaHp3orb0uFTE3aCqI,2328
|
|
167
167
|
sqlmesh/lsp/commands.py,sha256=7tZPePSH-IwBYmXJPIlqGM7pi4rOCLEtc3fKJglAxZs,72
|
|
168
168
|
sqlmesh/lsp/completions.py,sha256=7Lhboh6xyoMJ3kkHG3aZz1xVbDwKiXeQKdIRj5xlUOA,6674
|
|
169
|
-
sqlmesh/lsp/context.py,sha256=
|
|
169
|
+
sqlmesh/lsp/context.py,sha256=VIL_Xl3II6I79ILZ67UTY9u6OzgkLHDTEpTK91DJxAA,20892
|
|
170
170
|
sqlmesh/lsp/custom.py,sha256=3gfN_z9IXKOhTGkaZX7V5I8WUmI4z1GWe1sViOo92pw,3980
|
|
171
171
|
sqlmesh/lsp/errors.py,sha256=3NMim_5J00Eypz7t8b7XbkBfy8gIsRkeq-VcjD4COtc,1489
|
|
172
172
|
sqlmesh/lsp/helpers.py,sha256=EFc1u3-b7kSv5-tNwmKUDxId72RCLDBnN2lLTgRSzzQ,1020
|
|
@@ -287,7 +287,7 @@ sqlmesh/utils/pydantic.py,sha256=o_NsXbIpDqNpUA1Uc5xF0ZzoXQYYB0DfHwdRxBwXPNk,120
|
|
|
287
287
|
sqlmesh/utils/rich.py,sha256=cwQ5nJ6sgz64xHtoh6_ec7ReV5YpsOGhMtUJnwoRfEI,3549
|
|
288
288
|
sqlmesh/utils/windows.py,sha256=r7Yin4WEwbvH7sKA3hOJtRsclmscNuBeCklCfVPvtQs,611
|
|
289
289
|
sqlmesh/utils/yaml.py,sha256=hvo5lmybYLcIx4p6CQwufS8X4MbwS60lEBnCmYJCXmU,2336
|
|
290
|
-
sqlmesh-0.206.
|
|
290
|
+
sqlmesh-0.206.2.dev2.dist-info/licenses/LICENSE,sha256=OlMefUjgWJdULtf84BLW0AZZcY8DwdgQqb_1j2862j8,11346
|
|
291
291
|
web/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
292
292
|
web/client/dist/index.html,sha256=SXykdSRNgrT1k6I2dPZPEfpxPjIsi8-yVFijt-naSA4,5472
|
|
293
293
|
web/client/dist/assets/Audits-Jm353fhk.js,sha256=ry6b5IKT3hLAfD5C3T2BqxulfauEV0n0YZ2vsP4eQ_U,1041
|
|
@@ -405,8 +405,8 @@ web/server/api/endpoints/models.py,sha256=kwj0s7uve3iZSMfmjkoPVMFMeY1sD0peTeyrWf
|
|
|
405
405
|
web/server/api/endpoints/modules.py,sha256=8hqqgonGay_mJmpCw0IdbjsPhWlQH2VLdKAqha-myac,468
|
|
406
406
|
web/server/api/endpoints/plan.py,sha256=bbbY50W_2MsZSTxOHWMKz0tbIm75nsRSlPy8GI2fg9Q,9306
|
|
407
407
|
web/server/api/endpoints/table_diff.py,sha256=SCy3-pr5x6bEEiOaZGCDbiHQhpgxwmnz3Acqa2Ie6jI,2090
|
|
408
|
-
sqlmesh-0.206.
|
|
409
|
-
sqlmesh-0.206.
|
|
410
|
-
sqlmesh-0.206.
|
|
411
|
-
sqlmesh-0.206.
|
|
412
|
-
sqlmesh-0.206.
|
|
408
|
+
sqlmesh-0.206.2.dev2.dist-info/METADATA,sha256=qajqCyJXBIv3CUyhI_xZDP41Mo7zRlMflgxEW0Hs1fs,26685
|
|
409
|
+
sqlmesh-0.206.2.dev2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
410
|
+
sqlmesh-0.206.2.dev2.dist-info/entry_points.txt,sha256=pIYKtg-u-uO7BK_Y0qrdmfyj0bYrcMc3Xiqr5WE3VFk,121
|
|
411
|
+
sqlmesh-0.206.2.dev2.dist-info/top_level.txt,sha256=bspjo5vjELQkuN0qKuTFIbsrUt3Zeo8D2mlKeHG1LdE,12
|
|
412
|
+
sqlmesh-0.206.2.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|