dbt-labs / dbt-snowflake

dbt-snowflake contains all of the code enabling dbt to work with Snowflake
https://getdbt.com
Apache License 2.0
296 stars 176 forks source link

fix(format): Fixed SQL view formatting issue not following SQLFluff recommandations #1154

Open Cedric-Magnan opened 3 months ago

Cedric-Magnan commented 3 months ago

Problem

If the sql string variable in the relations/view/create.sql macro has multiple lines, the SQL view generated by dbt has one first line indented by 4 spaces, but the rest of the SQL code has no indentation.

This does not respect SQLFluff best practices for indentation : https://docs.sqlfluff.com/en/stable/layout.html#indentation

The indentation should be treated as a hint to the reader of the structure of the code.
This explains the common practice within most languages that nested elements (for example the contents of a set of brackets in a function call) should be indented one step from the outer elements.
It’s also convention that elements with the same level in a nested structure should have the same indentation, at least with regards to their local surroundings.

Solution

By adding the Jinja2 indent function : https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.indent

We are able to indent all content from the sql variable (except the first line which is already indented) !

Checklist

cla-bot[bot] commented 3 months ago

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @Cedric-Magnan