Hello Community,
I have the following question:
In a GCP Dataform workspace lets say you have an .sqlx "operations" file
Solved! Go to Solution.
The built-in dataform compile
and dataform run --dry-run
commands in Dataform are excellent for validating your project's overall structure, but they don't inherently catch SQL syntax errors. To proactively find these errors, consider these strategies:
1. External Linting / SQL Validation
GitHub Actions Integration:
- name: SQL Linting
uses: actions/setup-node@v2
with:
node-version: '14' # Use a supported Node version
run: |
npm install -g sqlfluff
sqlfluff lint --dialect bigquery my_dataform_project/definitions/
2. Pre-Commit Hooks
.sqlx
files before a developer can commit their changes.3. Custom Validation Script
Important Considerations:
.sqlx
files.While SQLFluff excels as a SQL linter, its compatibility with Dataform's unique syntax—such as config
blocks, JavaScript (js
) sections, and templating—presents certain challenges. Below, we explore these challenges and propose potential workarounds and strategies for developers.
Limitations of Custom Rules in SQLFluff
Partial Linting: A Limited Solution
Templating: A Cautious Approach
Key Considerations
Additional Strategies for Effective Linting
The integration between Dataform and SQLFluff may improve over time. Stay updated on the latest developments and best practices.
The built-in dataform compile
and dataform run --dry-run
commands in Dataform are excellent for validating your project's overall structure, but they don't inherently catch SQL syntax errors. To proactively find these errors, consider these strategies:
1. External Linting / SQL Validation
GitHub Actions Integration:
- name: SQL Linting
uses: actions/setup-node@v2
with:
node-version: '14' # Use a supported Node version
run: |
npm install -g sqlfluff
sqlfluff lint --dialect bigquery my_dataform_project/definitions/
2. Pre-Commit Hooks
.sqlx
files before a developer can commit their changes.3. Custom Validation Script
Important Considerations:
.sqlx
files.Hello again Community,
I have implemented the proposed solution. Please see the section of the .yml file that does the linting:
- name: Python Setup
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install SQLFluff
run: pip install sqlfluff==0.3.6
- name: SQL Linting
run: sqlfluff lint ././definitions/intermediate/ecbd_bu_address_ml_t.sqlx --dialect bigquery
However it seems that although I give as input parameter the "bigquery" dialect it is not enough.
Please see the errors:
L: 51 | P: 42 | LXR | Unable to lex characters: ''}\n'...'
It looks like "sqlfluff" does not know anything about dataform.
These are the official dialects: https://docs.sqlfluff.com/en/stable/dialects.html
If you have any ideas, please share.
Thank you.
While SQLFluff excels as a SQL linter, its compatibility with Dataform's unique syntax—such as config
blocks, JavaScript (js
) sections, and templating—presents certain challenges. Below, we explore these challenges and propose potential workarounds and strategies for developers.
Limitations of Custom Rules in SQLFluff
Partial Linting: A Limited Solution
Templating: A Cautious Approach
Key Considerations
Additional Strategies for Effective Linting
The integration between Dataform and SQLFluff may improve over time. Stay updated on the latest developments and best practices.
Thank you for your answer.