Skip to content

Commit 70850cd

Browse files
author
Nathaniel May
authored
Merge pull request dbt-labs#3497 from fishtown-analytics/experimental-parser-rust
Experimental Parser: Swap python extractor for rust dependency
2 parents 16992e6 + ac65fcd commit 70850cd

File tree

7 files changed

+14
-697
lines changed

7 files changed

+14
-697
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Contributors:
2525

2626
### Under the hood
2727

28+
- Swap experimental parser implementation to use Rust [#3497](https://github.com/fishtown-analytics/dbt/pull/3497)
2829
- Dispatch the core SQL statement of the new test materialization, to benefit adapter maintainers ([#3465](https://github.com/fishtown-analytics/dbt/pull/3465), [#3461](https://github.com/fishtown-analytics/dbt/pull/3461))
2930
- Minimal validation of yaml dictionaries prior to partial parsing ([#3246](https://github.com/fishtown-analytics/dbt/issues/3246), [#3460](https://github.com/fishtown-analytics/dbt/pull/3460))
3031
- Add partial parsing tests and improve partial parsing handling of macros ([#3449](https://github.com/fishtown-analytics/dbt/issues/3449), [#3505](https://github.com/fishtown-analytics/dbt/pull/3505))

core/dbt/parser/models.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dbt.node_types import NodeType
55
from dbt.parser.base import SimpleSQLParser
66
from dbt.parser.search import FileBlock
7-
from dbt.tree_sitter_jinja.extractor import extract_from_source
7+
from dbt_extractor import ExtractionError, py_extract_from_source # type: ignore
88

99

1010
class ModelParser(SimpleSQLParser[ParsedModelNode]):
@@ -32,15 +32,14 @@ def render_update(
3232

3333
# if the --use-experimental-parser flag was set
3434
else:
35-
36-
# run dbt-jinja extractor (powered by tree-sitter)
37-
res = extract_from_source(node.raw_sql)
38-
39-
# if it doesn't need python jinja, fit the refs, sources, and configs
40-
# into the node. Down the line the rest of the node will be updated with
41-
# this information. (e.g. depends_on etc.)
42-
if not res['python_jinja']:
43-
35+
try:
36+
# run dbt jinja extractor (powered by tree-sitter + rust)
37+
# throws an exception if it can't parse the source
38+
res = py_extract_from_source(node.raw_sql)
39+
40+
# since it doesn't need python jinja, fit the refs, sources, and configs
41+
# into the node. Down the line the rest of the node will be updated with
42+
# this information. (e.g. depends_on etc.)
4443
config_calls = []
4544
for c in res['configs']:
4645
config_calls.append({c[0]: c[1]})
@@ -66,5 +65,7 @@ def render_update(
6665

6766
self.manifest._parsing_info.static_analysis_parsed_path_count += 1
6867

69-
else:
68+
# exception was thrown by dbt jinja extractor meaning it can't
69+
# handle this source. fall back to python jinja rendering.
70+
except ExtractionError:
7071
super().render_update(node, config)

core/dbt/tree_sitter_jinja/README.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

core/dbt/tree_sitter_jinja/__init__.py

Whitespace-only changes.

core/dbt/tree_sitter_jinja/extractor.py

Lines changed: 0 additions & 292 deletions
This file was deleted.

core/setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def read(fname):
6363
'networkx>=2.3,<3',
6464
'packaging~=20.9',
6565
'sqlparse>=0.2.3,<0.4',
66-
'tree-sitter==0.19.0',
67-
'tree-sitter-jinja2==0.1.0a1',
66+
'dbt-extractor==0.2.0',
6867
'typing-extensions>=3.7.4,<3.11',
6968
'werkzeug>=0.15,<3.0',
7069
# the following are all to match snowflake-connector-python

0 commit comments

Comments
 (0)