Skip to content

Commit

Permalink
chore: add sqlfluff to lint spark sql queries (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala authored Dec 5, 2024
1 parent 99da937 commit 1f7e282
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ repos:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- id: ruff-format
- repo: https://github.com/sqlfluff/sqlfluff
rev: 3.2.5
hooks:
- id: sqlfluff-lint
- id: sqlfluff-fix
args: [--config, "./pyproject.toml"]
15 changes: 11 additions & 4 deletions examples/airflow/iceberg_query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ CREATE TABLE IF NOT EXISTS prod.db.sample (
data string,
category string
)
USING iceberg
USING ICEBERG
PARTITIONED BY (category);

MERGE INTO prod.db.sample t
USING (SELECT * FROM prod.db.another_sample WHERE category = 'foo') s
ON t.id = s.id
USING (
SELECT
id,
data,
category
FROM prod.db.another_sample
WHERE category = 'foo'
) s
ON t.id = s.id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *
WHEN NOT MATCHED BY SOURCE THEN DELETE;
WHEN NOT MATCHED BY SOURCE THEN DELETE; -- noqa: PRS
6 changes: 3 additions & 3 deletions examples/airflow/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ USING PARQUET
PARTITIONED BY (student_id INT);

INSERT INTO students VALUES
('Amy Smith', '123 Park Ave, San Jose', {{ ts }}, 111111);
('Amy Smith', '123 Park Ave, San Jose', '{{ ts }}', 111111);

INSERT INTO students VALUES
('Bob Brown', '456 Taylor St, Cupertino', {{ ts }}, 222222);,
('Cathy Johnson', '789 Race Ave, Palo Alto', {{ ts}}, 333333);
('Bob Brown', '456 Taylor St, Cupertino', '{{ ts }}', 222222),
('Cathy Johnson', '789 Race Ave, Palo Alto', '{{ ts }}', 333333);
113 changes: 112 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mkdocstrings = {version = "^0.25.1", extras = ["python"]}
mkdocs-gen-files = "^0.5.0"
mkdocs-literate-nav = "^0.6.1"
helm-mkdocs = "^0.0.5"
sqlfluff = "^3.2.5"

[tool.poetry.extras]
api = ["fastapi", "kubernetes-asyncio", "uvicorn", "httpx", "jinja2", "aiohttp", "websockets"]
Expand Down Expand Up @@ -90,3 +91,17 @@ docstring-code-format = true

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.sqlfluff.core]
dialect = "sparksql"
sql_file_exts = ".sql"
ignore = "templating"
exclude_rules="AL01"

[tool.sqlfluff.indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = false

[tool.sqlfluff.rules.capitalisation.keywords]
capitalisation_policy = "upper"

0 comments on commit 1f7e282

Please sign in to comment.