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 basic templating to snow sql #879

Merged
merged 10 commits into from
Apr 23, 2024

Conversation

sfc-gh-turbaszek
Copy link
Contributor

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Add basic rendering of templates in SQL.

@sfc-gh-turbaszek sfc-gh-turbaszek force-pushed the add-support-for-basic-sql-templating branch from cb55c48 to 454ede4 Compare March 14, 2024 13:14
@sfc-gh-turbaszek sfc-gh-turbaszek marked this pull request as ready for review March 15, 2024 10:16
@sfc-gh-turbaszek sfc-gh-turbaszek requested review from a team as code owners March 15, 2024 10:16
loader=loaders.FileSystemLoader(template_path.parent),
keep_trailing_newline=True,
undefined=StrictUndefined,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is being used in snow app init, which currently uses the regular jinja syntax {{}}. I think we can constrain it such that all client side rendering must have &{} only. I can change our templates to conform to that. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't agree, for example imagine creating a project for template that includes client side templating...

Copy link
Contributor

Choose a reason for hiding this comment

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

Native app has custom client-side template logic now that uses the standard jinja2 syntax. We should likely also support the Snowflake CLI syntax, but we can't remove support for the current behaviour without risking breaking existing users. I do agree with Tomasz that the Snowflake CLI does make it easier for clients to mix their own client-side template with ours.

src/snowflake/cli/plugins/sql/commands.py Show resolved Hide resolved
RELEASE-NOTES.md Outdated Show resolved Hide resolved
# Using $ as sf variable and client side rendering
("$&{ foo }", "$bar"),
],
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is helpful, thank you!

tests/api/utils/test_rendering.py Show resolved Hide resolved
src/snowflake/cli/plugins/sql/manager.py Show resolved Hide resolved
@sfc-gh-turbaszek sfc-gh-turbaszek force-pushed the add-support-for-basic-sql-templating branch from 69d1542 to 916238b Compare April 22, 2024 15:58
RELEASE-NOTES.md Outdated Show resolved Hide resolved
query: Optional[str],
file: Optional[Path],
std_in: bool,
data: Dict | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional[Dict]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PEP604 make both syntaxes compatible. We don't have a common pattern in our code base.

Copy link
Contributor

Choose a reason for hiding this comment

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

Python-Version: 3.10 What with 3.8 and 3.9?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sfc-gh-astus we already use it across the code base so this is nothing new. If we want to align to standard format (for example #1001 ) we should do so in other PR.



def get_snowflake_cli_jinja_env():
_random_block = "___very___unique___block___to___disable___logic___blocks___"
Copy link
Contributor

Choose a reason for hiding this comment

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

What is it for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A unique block to disable logic blocks. We don't want to support {% for foo in bar %} syntax.

@sfc-gh-turbaszek sfc-gh-turbaszek enabled auto-merge (squash) April 23, 2024 16:15
@sfc-gh-turbaszek sfc-gh-turbaszek merged commit c962461 into main Apr 23, 2024
9 checks passed
@sfc-gh-turbaszek sfc-gh-turbaszek deleted the add-support-for-basic-sql-templating branch April 23, 2024 16:23
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
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.

4 participants