Skip to content

Commit

Permalink
add --no-static-parser flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel May committed Sep 22, 2021
1 parent 2fd0239 commit 308f591
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
11 changes: 7 additions & 4 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
WARN_ERROR = None
TEST_NEW_PARSER = None
USE_EXPERIMENTAL_PARSER = None
NO_STATIC_PARSER = None
WRITE_JSON = None
PARTIAL_PARSE = None
USE_COLORS = None
Expand Down Expand Up @@ -56,15 +57,16 @@ def _get_context():

def reset():
global STRICT_MODE, FULL_REFRESH, USE_CACHE, WARN_ERROR, TEST_NEW_PARSER, \
USE_EXPERIMENTAL_PARSER, WRITE_JSON, PARTIAL_PARSE, MP_CONTEXT, USE_COLORS, \
STORE_FAILURES, GREEDY
USE_EXPERIMENTAL_PARSER, NO_STATIC_PARSER, WRITE_JSON, PARTIAL_PARSE, \
MP_CONTEXT, USE_COLORS, STORE_FAILURES, GREEDY

STRICT_MODE = False
FULL_REFRESH = False
USE_CACHE = True
WARN_ERROR = False
TEST_NEW_PARSER = False
USE_EXPERIMENTAL_PARSER = False
NO_STATIC_PARSER = False
WRITE_JSON = True
PARTIAL_PARSE = False
MP_CONTEXT = _get_context()
Expand All @@ -75,8 +77,8 @@ def reset():

def set_from_args(args):
global STRICT_MODE, FULL_REFRESH, USE_CACHE, WARN_ERROR, TEST_NEW_PARSER, \
USE_EXPERIMENTAL_PARSER, WRITE_JSON, PARTIAL_PARSE, MP_CONTEXT, USE_COLORS, \
STORE_FAILURES, GREEDY
USE_EXPERIMENTAL_PARSER, NO_STATIC_PARSER, WRITE_JSON, PARTIAL_PARSE, MP_CONTEXT, \
USE_COLORS, STORE_FAILURES, GREEDY

USE_CACHE = getattr(args, 'use_cache', USE_CACHE)

Expand All @@ -89,6 +91,7 @@ def set_from_args(args):

TEST_NEW_PARSER = getattr(args, 'test_new_parser', TEST_NEW_PARSER)
USE_EXPERIMENTAL_PARSER = getattr(args, 'use_experimental_parser', USE_EXPERIMENTAL_PARSER)
NO_STATIC_PARSER = getattr(args, 'no_static_parser', NO_STATIC_PARSER)
WRITE_JSON = getattr(args, 'write_json', WRITE_JSON)
PARTIAL_PARSE = getattr(args, 'partial_parse', None)
MP_CONTEXT = _get_context()
Expand Down
16 changes: 13 additions & 3 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,13 +1071,23 @@ def parse_args(args, cls=DBTArgumentParser):
help=argparse.SUPPRESS
)

# if set, will use the tree-sitter-jinja2 parser and extractor instead of
# jinja rendering when possible.
# if set, will use the latest features from the static parser instead of
# the stable static parser..
p.add_argument(
'--use-experimental-parser',
action='store_true',
help='''
Uses an experimental parser to extract jinja values.
Enables experimental parsing features.
'''
)

# if set, will disable the use of the stable static parser and instead
# always rely on jinja rendering.
p.add_argument(
'--no-static-parser',
action='store_true',
help='''
Disables the static parser.
'''
)

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def read_manifest_for_partial_parse(self) -> Optional[Manifest]:
def build_perf_info(self):
mli = ManifestLoaderInfo(
is_partial_parse_enabled=self._partial_parse_enabled(),
is_static_analysis_enabled=flags.USE_EXPERIMENTAL_PARSER
is_static_analysis_enabled=not flags.NO_STATIC_PARSER
)
for project in self.all_projects.values():
project_info = ProjectLoaderInfo(
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def render_update(
# use the experimental parser exclusively if the flag is on
if flags.USE_EXPERIMENTAL_PARSER:
statically_parsed = self.run_experimental_parser(node)
# run the stable static parser by default
else:
# run the stable static parser unless it is explicitly turned off
elif not flags.NO_STATIC_PARSER:
statically_parsed = self.run_static_parser(node)

# if the static parser succeeded, extract some data in easy-to-compare formats
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def test_postgres_static_parser_basic(self):
self.assertEqual(node.config._extra, {'x': True})
self.assertEqual(node.config.tags, ['hello', 'world'])

# test that the static parser doesn't run when the flag is set
@use_profile('postgres')
def test_postgres_static_parser_is_disabled(self):
_, log_output = self.run_dbt_and_capture(['--debug', '--no-static-parser', 'parse'])

print(log_output)

# successful stable static parsing
self.assertFalse("1699: " in log_output)
# successful experimental static parsing
self.assertFalse("1698: " in log_output)
# experimental parser failed
self.assertFalse("1604: " in log_output)
# static parser failed
self.assertFalse("1603: " in log_output)
# jinja rendering
self.assertTrue("1602: " in log_output)


class TestRefOverrideExperimentalParser(DBTIntegrationTest):
@property
def schema(self):
Expand Down

0 comments on commit 308f591

Please sign in to comment.