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

Snow 1625040 unify sql template syntax #1458

Merged
merged 15 commits into from
Aug 26, 2024

Conversation

sfc-gh-pczajka
Copy link
Contributor

@sfc-gh-pczajka sfc-gh-pczajka commented Aug 20, 2024

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 on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • 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 support for <% ... %> template syntax in SQL queries

@sfc-gh-pczajka sfc-gh-pczajka requested review from a team as code owners August 20, 2024 15:41
@sfc-gh-pczajka sfc-gh-pczajka marked this pull request as draft August 20, 2024 15:41
@sfc-gh-pczajka sfc-gh-pczajka marked this pull request as ready for review August 21, 2024 12:49
@sfc-gh-pczajka sfc-gh-pczajka marked this pull request as draft August 21, 2024 14:45
@sfc-gh-melnacouzi sfc-gh-melnacouzi self-requested a review August 21, 2024 14:54
src/snowflake/cli/api/rendering/jinja.py Outdated Show resolved Hide resolved
src/snowflake/cli/_plugins/nativeapp/manager.py Outdated Show resolved Hide resolved
src/snowflake/cli/api/rendering/sql_templates.py Outdated Show resolved Hide resolved
src/snowflake/cli/_plugins/nativeapp/manager.py Outdated Show resolved Hide resolved
@sfc-gh-pczajka sfc-gh-pczajka marked this pull request as ready for review August 23, 2024 12:50
template = env.get_template(relpath)
result = template.render(**jinja_context)
template_content = script_full_path.read_text(
file_size_limit_mb=DEFAULT_SIZE_LIMIT_MB
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-melnacouzi if we want to omit this check, we can use SecurePath.UNLIMITED here

Copy link
Contributor

@sfc-gh-melnacouzi sfc-gh-melnacouzi Aug 23, 2024

Choose a reason for hiding this comment

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

For SQL files, 128MB is a lot. It's probably ok to keep it here as long as the error message to the user is clear. I am fine with UNLIMITED as well, which is safer for backward compatibility

@sfc-gh-pczajka sfc-gh-pczajka enabled auto-merge (squash) August 23, 2024 13:16
f" and {_SQL_TEMPLATE_START} ... {_SQL_TEMPLATE_END} syntax."
)
if has_old_syntax:
return old_syntax_env
Copy link
Contributor

Choose a reason for hiding this comment

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

do we want a warning here?

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

Returns:
- List of expanded scripts content.
- List of rendered scripts content
Size of the return list is the same as the size of the input scripts list.
"""
scripts_contents = []
for relpath in scripts:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it's not always relative path, so maybe we can call it script_path

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'm confused about this one: previously the function worked on jinja.Environment, which in both usages had FileLoader set on project_root (also in L599 relpath suggests that input paths should be relative). In current implementation the function won't work for global paths - should we change it? Do we currently have a use case for global paths?

template = env.get_template(relpath)
result = template.render(**jinja_context)
template_content = script_full_path.read_text(
file_size_limit_mb=DEFAULT_SIZE_LIMIT_MB
Copy link
Contributor

@sfc-gh-melnacouzi sfc-gh-melnacouzi Aug 23, 2024

Choose a reason for hiding this comment

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

For SQL files, 128MB is a lot. It's probably ok to keep it here as long as the error message to the user is clear. I am fine with UNLIMITED as well, which is safer for backward compatibility


def path_to_jinja_pathlike_str(path: Path) -> str:
# jinja2 template loader user '/' as path separator (even on Windows)
return "/".join(path.parts)
Copy link
Contributor

@sfc-gh-melnacouzi sfc-gh-melnacouzi Aug 26, 2024

Choose a reason for hiding this comment

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

have you tried path.to_posix() instead? It seems to work well for 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.

Nice one!

@sfc-gh-pczajka sfc-gh-pczajka merged commit 43ef058 into main Aug 26, 2024
18 checks passed
@sfc-gh-pczajka sfc-gh-pczajka deleted the SNOW-1625040-unify-sql-template-syntax branch August 26, 2024 11:54
sfc-gh-jvasquezrojas pushed a commit that referenced this pull request Aug 26, 2024
* Add <% ... %> syntax to SQL rendering

* add unit tests

* fix nativeapp rendering

* update release notes

* Add integration tests

* update nativeapp unit tests

* Fix Windows paths

* self-review

* Change SQL rendering to choose syntax depending on template

* revert nativeapp changes

* refactor nativeapp usage

* use SecurePath to open files
sfc-gh-jvasquezrojas pushed a commit that referenced this pull request Aug 26, 2024
* Add <% ... %> syntax to SQL rendering

* add unit tests

* fix nativeapp rendering

* update release notes

* Add integration tests

* update nativeapp unit tests

* Fix Windows paths

* self-review

* Change SQL rendering to choose syntax depending on template

* revert nativeapp changes

* refactor nativeapp usage

* use SecurePath to open files
sfc-gh-sichen pushed a commit that referenced this pull request Oct 17, 2024
* Add <% ... %> syntax to SQL rendering

* add unit tests

* fix nativeapp rendering

* update release notes

* Add integration tests

* update nativeapp unit tests

* Fix Windows paths

* self-review

* Change SQL rendering to choose syntax depending on template

* revert nativeapp changes

* refactor nativeapp usage

* use SecurePath to open files
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