Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static parser tracking logic #4332

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Under the hood
- Change some CompilationExceptions to ParsingExceptions ([#4254](http:/dbt-labs/dbt-core/issues/4254), [#4328](https:/dbt-core/pull/4328))
- Reorder logic for static parser sampling to speed up model parsing ([#4332](https:/dbt-labs/dbt-core/pull/4332))


## dbt-core 1.0.0rc2 (November 22, 2021)
Expand Down
24 changes: 14 additions & 10 deletions core/dbt/parser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def render_update(
# not when the experimental parser flag is on.
exp_sample: bool = False
# sampling the stable static parser against jinja is significantly
# more expensive and therefor done far less frequently.
# more expensive and therefore done far less frequently.
stable_sample: bool = False
# there are two samples above, and it is perfectly fine if both happen
# at the same time. If that happens, the experimental parser, stable
Expand Down Expand Up @@ -148,20 +148,24 @@ def render_update(
)

self.manifest._parsing_info.static_analysis_parsed_path_count += 1
# if the static parser failed, add the correct messages for tracking
elif isinstance(statically_parsed, str):
if statically_parsed == "cannot_parse":
result += ["01_stable_parser_cannot_parse"]
elif statically_parsed == "has_banned_macro":
result += ["08_has_banned_macro"]

super().render_update(node, config)
fire_event(StaticParserFallbackJinjaRendering(path=node.path))
# if the static parser didn't succeed, fall back to jinja
else:
# jinja rendering
super().render_update(node, config)
fire_event(StaticParserFallbackJinjaRendering(path=node.path))

# if sampling, add the correct messages for tracking
if exp_sample and isinstance(experimental_sample, str):
if experimental_sample == "cannot_parse":
result += ["01_experimental_parser_cannot_parse"]
elif experimental_sample == "has_banned_macro":
result += ["08_has_banned_macro"]
elif stable_sample and isinstance(statically_parsed, str):
if statically_parsed == "cannot_parse":
result += ["81_stable_parser_cannot_parse"]
elif statically_parsed == "has_banned_macro":
result += ["88_has_banned_macro"]

# only send the tracking event if there is at least one result code
if result:
# fire a tracking event. this fires one event for every sample
Expand Down