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

Add flyway variables support via placeholder templater #4026

Merged
merged 9 commits into from Nov 13, 2022

Conversation

srjonemed
Copy link
Contributor

@srjonemed srjonemed commented Nov 3, 2022

Brief summary of the change made

Proposed solution for #4025

Are there any other side effects of this change that we should be aware of?

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Nov 4, 2022

Codecov Report

Base: 100.00% // Head: 100.00% // No change to project coverage 👍

Coverage data is based on head (1c69cda) compared to base (29faf04).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #4026   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          190       190           
  Lines        14585     14585           
=========================================
  Hits         14585     14585           
Impacted Files Coverage Δ
src/sqlfluff/core/templaters/placeholder.py 100.00% <ø> (ø)
src/sqlfluff/core/config.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]:
# Disable interpolation so we can load macros
kw: Dict = {}
kw["interpolation"] = None
config = configparser.ConfigParser(**kw)
config = configparser.ConfigParser(delimiters="=", **kw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the configparser doc, "The first occurrence of a delimiting substring on a line is considered a delimiter" and it assumes both ':' and '=' to be delimiters by default. This would mean that the defining a key called "flyway:database = test_db_name" would split key="flyway" and val="database=test_db_name" :(
I see that all our keys use '=' as delimiter and ':' is only used in section names hence made this change. But, If there's a better way to not impose this globally, pls do let me know

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears the current tests don't test for this change. See my comment on test/fixtures/templater/placeholder_flyway_var/placeholder_flyway_var_a.sql for a suggestion on how to test it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned adding another test. Will any of your tests fail if this delimiters change is removed? I think it's important to have a test for this.

@@ -0,0 +1,5 @@
USE ${flyway:database}.test_schema;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any mention of flyway in the CI output. Perhaps you need to change something else to make this run? The placeholder templater tests are in this file: test/core/templaters/placeholder_test.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, will take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated with a test, pls take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, could u let me know if this fixture is needed - not sure where/how it'd be used

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently not used because the placeholder templater doesn't have a test that reads from file fixtures. See this jinja test: https://github.com/sqlfluff/sqlfluff/blob/main/test/core/templaters/jinja_test.py#L568L624

Can you look at adding a similar test for the placeholder templater? This would test the config delimiter change you made in a realistic way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, sorry it took me a while to respond. I had actually written the comment above several days ago, but I forgot to submit the pending comments. Occasionally GitHub confuses me. 😢

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pointers, I'll have take a look soon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a test to config_test.py that should hopefully cover the delimiters codecov

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the tests pass, this looks good to me. I'd perhaps like to take a look from my computer (currently on my phone) before merging.

@srjonemed
Copy link
Contributor Author

Thanks!

@srjonemed
Copy link
Contributor Author

@barrywhart i've pushed a new commit including adding another test. pls have a look..
Also, do we know when this pr could get merged and to what version?

@barrywhart
Copy link
Member

See my comment about the need to add a config test for the = delimiter. If we can address that, the PR is ready for merge.

I think 1.4.2 will be released in the next few days.

@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]:
# Disable interpolation so we can load macros
kw: Dict = {}
kw["interpolation"] = None
config = configparser.ConfigParser(**kw)
config = configparser.ConfigParser(delimiters="=", **kw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears the current tests don't test for this change. See my comment on test/fixtures/templater/placeholder_flyway_var/placeholder_flyway_var_a.sql for a suggestion on how to test it.

@@ -0,0 +1,5 @@
USE ${flyway:database}.test_schema;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently not used because the placeholder templater doesn't have a test that reads from file fixtures. See this jinja test: https://github.com/sqlfluff/sqlfluff/blob/main/test/core/templaters/jinja_test.py#L568L624

Can you look at adding a similar test for the placeholder templater? This would test the config delimiter change you made in a realistic way.

@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]:
# Disable interpolation so we can load macros
kw: Dict = {}
kw["interpolation"] = None
config = configparser.ConfigParser(**kw)
config = configparser.ConfigParser(delimiters="=", **kw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned adding another test. Will any of your tests fail if this delimiters change is removed? I think it's important to have a test for this.

@@ -306,6 +322,8 @@ def test__templater_raw():
"numeric_dollar_with_braces_and_string",
"percent",
"ampersand",
"flyway_var",
"flyway_var",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does flyway_var appear twice?

Copy link
Contributor Author

@srjonemed srjonemed Nov 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw some warning to the effect that ids list has less elements than the test sql's list
____________________________________________ ERROR collecting test/core/templaters/placeholder_test.py ____________________________________________ In test__templater_param_style: 17 parameter sets specified, with different number of ids: 16

I can remove and retest if above can be ignored

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting addition of a test for the = delimiter

@srjonemed
Copy link
Contributor Author

Requesting addition of a test for the = delimiter

added test__config__load_placeholder_cfg to config_test.py, pls have a look if this satisfies the gap

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I temporarily removed the delimiters addition and verified that your new test fails. This will prevent future maintainers from simply removing that change and thinking it's safe because no tests fail.

Unfortunately, the new release happened earlier today, so this will have to wait for the next release (usually 2-4 weeks apart).

@barrywhart barrywhart merged commit 4d2a83c into sqlfluff:main Nov 13, 2022
@srjonemed
Copy link
Contributor Author

sounds good, thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants