-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #441 from dbt-labs/feature/calculate-sql-complexity
- Loading branch information
Showing
10 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
docs/customization/querying-columns.md → ...uerying-columns-names-and-descriptions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% macro calculate_number_lines(node) %} | ||
{{ return(adapter.dispatch('calculate_number_lines', 'dbt_project_evaluator')(node)) }} | ||
{% endmacro %} | ||
|
||
{% macro default__calculate_number_lines(node) %} | ||
|
||
{% if node.resource_type == 'model' %} | ||
|
||
{% if execute %} | ||
{%- set model_raw_sql = node.raw_sql or node.raw_code -%} | ||
{%- else -%} | ||
{%- set model_raw_sql = '' -%} | ||
{%- endif -%} | ||
|
||
{{ return(model_raw_sql.count("\n")) + 1 }} | ||
|
||
{% endif %} | ||
|
||
{{ return(0) }} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{% macro calculate_sql_complexity(node) %} | ||
{{ return(adapter.dispatch('calculate_sql_complexity', 'dbt_project_evaluator')(node)) }} | ||
{% endmacro %} | ||
|
||
{% macro default__calculate_sql_complexity(node) %} | ||
|
||
{% if node.resource_type == 'model' and node.language == 'sql' %} | ||
|
||
{% if execute %} | ||
{%- set model_raw_sql = node.raw_sql or node.raw_code -%} | ||
{%- else -%} | ||
{%- set model_raw_sql = '' -%} | ||
{%- endif -%} | ||
|
||
{%- set re = modules.re -%} | ||
{%- set ns = namespace(complexity = 0) -%} | ||
|
||
{# we remove the comments that start with -- , or other characters configured #} | ||
{%- set comment_chars_match = "(" ~ var('comment_chars') | join("|") ~ ").*" -%} | ||
{%- set model_raw_sql_no_comments = re.sub(comment_chars_match, '', model_raw_sql) -%} | ||
|
||
{%- for token, token_cost in var('token_costs').items() -%} | ||
|
||
{# this is not 100% perfect but it checks more or less if the token exists as a word by itself or followed by "("" like for least()/greatest() #} | ||
{%- set token_with_boundaries = "\\b" ~ token ~ "[\\t\\r\\n (]" -%} | ||
{%- set all_regex_matches = re.findall(token_with_boundaries, model_raw_sql_no_comments, re.IGNORECASE) -%} | ||
{%- set ns.complexity = ns.complexity + token_cost * (all_regex_matches | length) -%} | ||
|
||
{%- endfor -%} | ||
|
||
{{ return(ns.complexity) }} | ||
|
||
{% endif %} | ||
|
||
{{ return(0) }} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters