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

Demos/sqlfluff jinja templater #30

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions .github/workflows/dbt_on_merge_to_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dbt_pr_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.6
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.6
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/lint_sqlfluff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ name: SQLFluff
on:
- pull_request

env:
DBT_USER: "${{ secrets.DBT_USER }}"
DBT_PW: "${{ secrets.DBT_PW }}"
DBT_ACCOUNT: "${{ secrets.DBT_ACCOUNT }}"

jobs:
lint-models:
runs-on: ubuntu-latest
Expand All @@ -14,9 +19,13 @@ jobs:
- name: Install Python
uses: "actions/setup-python@v2"
with:
python-version: "3.7"
python-version: "3.9"
- name: install sqlfluff
run: "pip install sqlfluff"
- name: install sqlfluff-templater-dbt
run: "pip install sqlfluff-templater-dbt"
- name: install dbt-snowflake
run: "pip install dbt-snowflake"
- name: Get changed files
id: get_file_changes
uses: trilom/[email protected]
Expand Down Expand Up @@ -46,7 +55,7 @@ jobs:
id: sqlfluff_json
if: steps.get_files_to_lint.outputs.lintees != ''
shell: bash -l {0}
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
run: sqlfluff lint --dialect snowflake --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
- name: Annotate
uses: yuzutech/[email protected]
with:
Expand Down
15 changes: 15 additions & 0 deletions .profiles/profiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
snowflake:
target: dev
outputs:
dev:
type: snowflake
account: "{{ env_var('DBT_ACCOUNT') }}"
user: "{{ env_var('DBT_USER') }}"
password: "{{ env_var('DBT_PW') }}"

role: TRANSFORMER
database: ANALYTICS_MWINKLER_DBT_WORKSPACE
warehouse: TRANSFORMING
schema: dbt_mwinkler
threads: 2
client_session_keep_alive: False
53 changes: 53 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[sqlfluff]
verbose = 0
nocolor = False
dialect = snowflake
templater = jinja
rules = None
exclude_rules = L032,L033,L034,L037,L044
recurse = 0
output_line_length = 80
runaway_limit = 10
ignore = parsing,templating
ignore_templated_areas = True

[sqlfluff:indentation]
indented_joins = False
template_blocks_indent = True

# Some rules can be configured directly from the config common to other rules.
[sqlfluff:rules]
tab_space_size = 4
max_line_length = 120
indent_unit = space
comma_style = trailing
allow_scalar = True
single_table_references = consistent
only_aliases = True

[sqlfluff:rules:L010] # Keywords
capitalisation_policy = lower

[sqlfluff:rules:L014] # Unquoted identifiers
# Note that sqlfluff uses the 'postgres' dialect for Redshift.
# Postgres keywords used to check against 'unquoted identifiers':
# https://www.postgresql.org/docs/8.1/sql-keywords-appendix.html
extended_capitalisation_policy = lower
unquoted_identifiers_policy = all

[sqlfluff:rules:L016]
# Setting to True allows us to copy/paste long URLs as comments
ignore_comment_lines = True

[sqlfluff:rules:L030] # Function names
capitalisation_policy = lower

[sqlfluff:rules:L038]
select_clause_trailing_comma = forbid

[sqlfluff:rules:L040] # Null & Boolean Literals
capitalisation_policy = lower

[sqlfluff:rules:L042]
# By default, allow subqueries in from clauses, but not join clauses.
forbid_subquery_in = join
6 changes: 6 additions & 0 deletions .sqlfluffignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target/
# dbt <1.0.0
dbt_modules/
# dbt >=1.0.0
dbt_packages/
macros/
10 changes: 5 additions & 5 deletions dbt/macros/audit/validate_sql_contains_limit.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro validate_sql_contains_limit(model) %}
{% if not model.raw_sql.endswith('limit 100') %}
{{ exceptions.raise_compiler_error("Invalid model sql. Model: " ~ model.path ~ " must end with 'limit 100'") }}
{% endif %}
{% endmacro %}
{# macro validate_sql_contains_limit(model) #}
{# if not model.raw_sql.endswith('limit 100') #}
{# {{ exceptions.raise_compiler_error("Invalid model sql. Model: " ~ model.path ~ " must end with 'limit 100'") }} #}
{# endif #}
{# endmacro #}
8 changes: 8 additions & 0 deletions dbt/models/data_science/ds_sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2

sources:
- name: ds_test
database: dev
schema: dbt_mwinkler
tables:
- name: titantic
6 changes: 6 additions & 0 deletions dbt/models/demos/custom_node_colors/custom_node_colors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2

models:
- name: model_a
meta:
node_color: "#CB998F"
1 change: 1 addition & 0 deletions dbt/models/demos/custom_node_colors/model_a.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1 as id
3 changes: 0 additions & 3 deletions dbt/models/demos/custom_schema/custom_schema.sql

This file was deleted.

9 changes: 9 additions & 0 deletions dbt/models/example/my_first_dbt_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{
config(
materialized='table'
)
}}

select 1 as id
union all
select null as id
3 changes: 2 additions & 1 deletion dbt/models/my_first_model.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{
config(
materialized='table'
materialized='view',
quote=False
)
}}

Expand Down