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

Allow not specifying parameters names when using placeholder templater #5101

Merged
merged 13 commits into from Sep 10, 2023

Conversation

shyaginuma
Copy link
Contributor

@shyaginuma shyaginuma commented Aug 17, 2023

Brief summary of the change made

fixes #4139, fixes #2108 (actually enhancement)

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

From my perspective, nothing. But this change was different from the intent of placeholder templater, I'd like to discuss.

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.

@shyaginuma shyaginuma changed the title allow placeholder templater not to set values Allow not specifying parameters names when using placeholder templater Aug 17, 2023
"Failure in placeholder templating: {}. Have you configured your "
"variables?".format(err)
)
replacement = str(context.get(param_name, ""))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be better to set custom default value instead of blank string, but I'd like to hear your opinion.

Copy link
Member

Choose a reason for hiding this comment

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

@shyaginuma - I think it would be safer to replace with the name of the variable as a string. That way it's transparent and most likely to still parse. This is similar to what we've done with the dbt ref() macro.

i.e. SELECT :foo, 1 would get parsed as SELECT "foo", 1 rather than SELECT , 1 (the latter would fail to parse, but the earlier one would pass).

How does that sound to you? I think most SQL dialects allow quoted literals in most cases that would accept strings, dates or other datatypes.

@barrywhart - do you have any views as you put up one of the original issues?

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, when I implemented the similar behavior for the Jinja and dbt templaters, I had it simply return the unquoted string. Either behavior may be reasonable, but I think we should be consistent. Can someone confirm the dbt templater's behavior?

Copy link
Member

Choose a reason for hiding this comment

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

Our current jinja templater renders this:

select * from {{ ref("foo") }}

as

select * from foo

so that means it would be more consistent to render it unquoted. thanks @barrywhart !

@shyaginuma - could you update your code to that? I think then this is good to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alanmcruickshank Thanks for your suggestion! Fixed in 31bd5f1, could you take a look again?

@shyaginuma shyaginuma marked this pull request as ready for review August 17, 2023 03:45
@greg-finley
Copy link
Contributor

n.b., to close two issues, next time put "fixes #4139, fixes #2108" ("fixes" twice) in the PR description https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

@shyaginuma
Copy link
Contributor Author

thanks for the suggestion. let me fix 🙇

@shyaginuma
Copy link
Contributor Author

now, I think it's ready for review. Could someone take a look?

@coveralls
Copy link

coveralls commented Aug 29, 2023

Coverage Status

coverage: 100.0%. remained the same when pulling b7daa9a on shyaginuma:issue-4139 into f6c0758 on sqlfluff:main.

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

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

Hi @shyaginuma - could you resolve the thread above about how to resolve missing variables? To be consistent with other places where we do something similar, I think we should resolve any missing variables as the name of the variable rather than an empty string, I think that gives us the best chance of the SQL still parsing afterward.

Otherwise I think this is good to go. Thanks for putting this together! 🏆

Copy link
Member

@alanmcruickshank alanmcruickshank left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀 Thanks for the somewhat longer review process on this one.

@alanmcruickshank alanmcruickshank added this pull request to the merge queue Sep 10, 2023
Merged via the queue into sqlfluff:main with commit 4428162 Sep 10, 2023
28 checks passed
@shyaginuma
Copy link
Contributor Author

Thanks for the review!! 😄

@shyaginuma shyaginuma deleted the issue-4139 branch September 10, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants