Skip to content
New issue

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

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

Already on GitHub? # to your account

Increase readability of generate_model_import_ctes.sql by using VERBOSE mode for re #91

Closed
b-per opened this issue Nov 21, 2022 · 1 comment · Fixed by #93
Closed

Increase readability of generate_model_import_ctes.sql by using VERBOSE mode for re #91

b-per opened this issue Nov 21, 2022 · 1 comment · Fixed by #93
Labels
enhancement New feature or request

Comments

@b-per
Copy link
Contributor

b-per commented Nov 21, 2022

Describe the feature

Modify generate_model_import_ctes.sql to use the verbose mode (adding x to the i flag) for re, allowing to split regexes between different lines and providing the ability to add comments to those.

Additional context

Here is an example of regex without verbose (all in 1 line):

{% set re = modules.re %}
{% set my_string = <my_sql_code> %}
{% set re_pattern = '(?i)(from|join)\s+({{\s*ref\s*\(\s*[\'\"]?)([^)\'\"]+)([\'\"]?\s*)(\)\s*}})' 
%}

{% set is_match = re.findall(re_pattern, my_string) %}

and with verbose:

{% set re = modules.re %}
{% set my_string = <my_sql_code> %}
{% set re_pattern = "(?ix)

    # first matching group
    (from|join)\s+       # from or join followed by at least a sep character

    # second matching group
    (
    {{                   # opening {{
    \s*ref\s*\(          # the word ref followed by a (
    \s*[\'\"]?
    )

    ([^)\'\"]+)([\'\"]?\s*)(
    \)\s*                # closing ) for ref
    }}                   # closing {{
    )" 
%}

{% set is_match = re.findall(re_pattern, my_string) %}

Who will this benefit?

People wanting to understand/enhance regexes to find tables in models.

Are you interested in contributing this feature?

Why not but keen to let someone else look at it

@b-per b-per added the enhancement New feature or request label Nov 21, 2022
@graciegoheen
Copy link
Contributor

meme_for_benoit_2

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants