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 53bafd1 commit e46c6c0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
6 changes: 4 additions & 2 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# Global CLI commands
USE_EXPERIMENTAL_PARSER = None
NO_STATIC_PARSER = None
WARN_ERROR = None
WRITE_JSON = None
PARTIAL_PARSE = None
Expand Down Expand Up @@ -91,8 +92,8 @@ def _get_context():

def set_from_args(args, user_config):
global STRICT_MODE, FULL_REFRESH, WARN_ERROR, \
USE_EXPERIMENTAL_PARSER, WRITE_JSON, PARTIAL_PARSE, USE_COLORS, \
STORE_FAILURES, PROFILES_DIR, DEBUG, LOG_FORMAT, GREEDY, \
USE_EXPERIMENTAL_PARSER, NO_STATIC_PARSER, WRITE_JSON, PARTIAL_PARSE, \
USE_COLORS, STORE_FAILURES, PROFILES_DIR, DEBUG, LOG_FORMAT, GREEDY, \
VERSION_CHECK, FAIL_FAST, SEND_ANONYMOUS_USAGE_STATS, PRINTER_WIDTH

STRICT_MODE = False # backwards compatibility
Expand All @@ -103,6 +104,7 @@ def set_from_args(args, user_config):

# global cli flags with env var and user_config alternatives
USE_EXPERIMENTAL_PARSER = get_flag_value('USE_EXPERIMENTAL_PARSER', args, user_config)
NO_STATIC_PARSER = get_flag_value('NO_STATIC_PARSER', args, user_config)
WARN_ERROR = get_flag_value('WARN_ERROR', args, user_config)
WRITE_JSON = get_flag_value('WRITE_JSON', args, user_config)
PARTIAL_PARSE = get_flag_value('PARTIAL_PARSE', args, user_config)
Expand Down
16 changes: 13 additions & 3 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,14 +1066,24 @@ 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',
default=None,
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 @@ -577,7 +577,7 @@ def read_manifest_for_partial_parse(self) -> Optional[Manifest]:
def build_perf_info(self):
mli = ManifestLoaderInfo(
is_partial_parse_enabled=flags.PARTIAL_PARSE,
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 @@ -38,7 +38,7 @@ def test_postgres_experimental_parser_basic(self):
def test_postgres_env_experimental_parser(self):
os.environ['DBT_USE_EXPERIMENTAL_PARSER'] = 'true'
results = self.run_dbt(['parse'])

# test that the static parser extracts some basic ref, source, and config calls by default
# without the experimental flag
@use_profile('postgres')
Expand All @@ -63,6 +63,24 @@ 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
Expand Down

0 comments on commit e46c6c0

Please sign in to comment.