The sqlfluff utility is a linting tool for SQL files, often used with dbt to enforce SQL code standards.
If you haven't already, follow the initial steps of the Getting Started guide:
Installation and configuration
Add the sqlfluff utility to your project
Configure the sqlfluff settings using
meltano add utility sqlfluff
meltano config sqlfluff set --interactive
Update the pip_url in your meltano.yml by appending your dbt adapter (e.g. dbt-snowflake, etc.).
pip_url: sqlfluff sqlfluff-templater-dbt dbt-core dbt-snowflake
Re-install the plugin with the updated pip_url:
meltano install utility sqlfluff
.sqlflufffile in the root directory of your project using the sample content below. You will need to put your dbt adapter name in for
profiles_dirwithout the dbt prefix (e.g. snowflake). This config file is where you can customize the linting rules to match your team's style guide. SQLFluff comes with logic defaults so you will only need to override configurations you want to change.
[sqlfluff] templater = dbt dialect = <your_dialect_name> [sqlfluff:templater:dbt] project_dir = transform profiles_dir = transform/profiles/<your_dialect_name> profile = meltano
.sqlfluffignorein the root directory of your project using the sample content below. This makes sure SQLFluff ignores auto generated sql or installed packages.
.meltano/ utilities/ transform/dbt_packages/ transform/target/ transform/dbt_modules/ transform/macros/
Depending on your dbt adapter you will need to override your dbt environment variables using the
envkey so when SQLFluff calls dbt your profile.yml env vars are properly set. Refer to the Meltano transformer docs for details on what variables are needed for your adapter. An example for Snowflake is shown below.
utilities: - name: sqlfluff variant: sqlfluff pip_url: sqlfluff sqlfluff-templater-dbt dbt-core dbt-snowflake settings: - name: user env: DBT_SNOWFLAKE_USER - name: password kind: password env: DBT_SNOWFLAKE_PASSWORD - name: role env: DBT_SNOWFLAKE_ROLE - name: account env: DBT_SNOWFLAKE_ACCOUNT - name: warehouse env: DBT_SNOWFLAKE_WAREHOUSE - name: schema env: DBT_SNOWFLAKE_SCHEMA value: foo # This isnt used so we just put a placeholder by default - name: database env: DBT_SNOWFLAKE_DATABASE value: foo # This isnt used so we just put a placeholder by default
SqlFluff does still need access to your warehouse so you have to supply valid credentials similar to your dbt configs which will live under your meltano.yml config and
meltano config sqlfluff set user <your username> meltano config sqlfluff set account <your account> meltano config sqlfluff set role <your role> meltano config sqlfluff set warehouse <your warehouse> meltano config sqlfluff set password <your password>
meltano invoke sqlfluff:lintto lint your SQL files.
meltano invoke sqlfluff:fixto automatically fix your SQL files based on your linting rules.
If you run into any issues, learn how to get help.
CapabilitiesThis plugin currently has no capabilities defined. If you know the capabilities required by this plugin, please contribute!
SettingsThis plugin currently has no settings defined. If you know the settings required by this plugin, please contribute!
CommandsThe sqlfluff utility supports the following commands that can be used with
Automatically fix SQL files according to your defined rules.
meltano invoke sqlfluff:fix [args...]
Automatically fix SQL files according to your defined rules (does not ask for confirmation).
meltano invoke sqlfluff:fix-force [args...]
Lint SQL in transform models.
meltano invoke sqlfluff:lint [args...]
This page is generated from a YAML file that you can contribute changes to.Edit it on GitHub!
Looking for help?
meltano add utility sqlfluff