admin管理员组

文章数量:1203400

I am working on using SQLFluff as a linter for our codebase. Our codebase is a bit complicated with SQL files that have a mix of templates (Jinja + placeholder) For my evaluation I used the following config SQLFluff version: 3.0.7

Config file: .sqlfluff config file

[sqlfluff]
templater = jinja
dialect = redshift
exclude_rules = AL01,AL04,AL05,AL06,AL07,AM01,AM02,AM03,AM04,AM07,CV01,CV02,CV03,CV04,CV05,CV06,CV07,CV08,CV09,CV10,CV11,LT01,LT03,LT05,LT07,LT08,LT12,LT13,RF01,RF02,RF03,RF04,RF05,RF06,ST01,ST02,ST03,ST06,ST07,ST08,TQ01,L009,L032
ignore = templating
large_file_skip_byte_limit = 0
max_line_length = 0
processes = -1

[sqlfluff:templater:jinja:context]
schema_name_d_mart=d_mart
schema_name_b_vault = b_vault

[sqlfluff:templater:jinja]


[sqlfluff:templater:placeholder]
param_style = dollar

[sqlfluff:templater:placeholder:context]
schema_name_b_vault = b_vault
schema_name_d_mart=d_mart

I am unable to find a SQLFluff config that would resolve SQL files with a mix of templates.

Here is the Problematic SQL File that I am trying to lint using the above config

{% set schema_name_b_vault = "test_schema" %}

SELECT
    val,
    val2
FROM ${schema_name_b_vault}.test
;

Issue: If I use jinja as a templater (in the cofig) then line 1 is resolved but line 6 errors out:

== [sqlfiles_foldera/test_a.sql] FAIL
L:   6 | P:   1 |  PRS | Line 6, Position 1: Found unparsable section: 'FROM
                       | ${schema_name_business_vault}.test'
L:   6 | P:   6 |  LXR | Unable to lex characters: '${schema_n...'
WARNING: Parsing errors found and dialect is set to 'redshift'. Have you configured your dialect correctly?

If I use placeholder as a templater then line 6 is resolved but line 1 errors out.

Query: Is there a way to resolve SQL files that have a mix of such templates? Any suggestions or guidance would be great!

本文标签: SQLFluff is unable to resolve SQL files with a mix of different template stylesStack Overflow