sqlfluff / sqlfluff

A modular SQL linter and auto-formatter with support for multiple dialects and templated code.

Home Page:https://www.sqlfluff.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Long macro reformatted to repeating, incorrect, value.

jlucas91 opened this issue · comments

Search before asking

  • I searched the issues and found no similar issues.

What Happened

sqlfluff fix on a too long line that contains a macro causes the macro to be reformatted to a repeating, incorrect, value.

Expected Behaviour

sqlfluff fix would not cause the incorrect reformatting and would instead correctly reformat the macro to multiple lines.

Observed Behaviour

Parsed tree:

###
#
# Parsed Tree:
#
###
INFO
[L:  1, P:  1]      |file:
[L:  1, P:  1]      |    statement:
[L:  1, P:  1]      |        with_compound_statement:
[L:  1, P:  1]      |            keyword:                                          'with'
[L:  1, P:  5]      |            whitespace:                                       ' '
[L:  1, P:  6]      |            common_table_expression:
[L:  1, P:  6]      |                naked_identifier:                             'test'
[L:  1, P: 10]      |                whitespace:                                   ' '
[L:  1, P: 11]      |                keyword:                                      'as'
[L:  1, P: 13]      |                whitespace:                                   ' '
[L:  1, P: 14]      |                bracketed:
[L:  1, P: 14]      |                    start_bracket:                            '('
[L:  1, P: 15]      |                    [META] indent:
[L:  1, P: 15]      |                    newline:                                  '\n'
[L:  2, P:  1]      |                    whitespace:                               '    '
[L:  2, P:  5]      |                    select_statement:
[L:  2, P:  5]      |                        select_clause:
[L:  2, P:  5]      |                            keyword:                          'select'
[L:  2, P: 11]      |                            [META] indent:
[L:  2, P: 11]      |                            newline:                          '\n'
[L:  3, P:  1]      |                            whitespace:                       '        '
[L:  3, P:  9]      |                            newline:                          '\n'
[L:  3, P:  9]      |                            whitespace:                       '    '
[L:  3, P:  9]      |                            newline:                          '\n'
[L:  3, P:  9]      |                            whitespace:                       '    '
[L:  3, P:  9]      |                            select_clause_element:
[L:  3, P:  9]      |                                expression:
[L:  3, P:  9]      |                                    case_expression:
[L:  3, P:  9]      |                                        keyword:              'case'
[L:  3, P:  9]      |                                        [META] (implicit) indent:
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '        '
[L:  3, P:  9]      |                                        when_clause:
[L:  3, P:  9]      |                                            keyword:          'when'
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                function:
[L:  3, P:  9]      |                                                    function_name:
[L:  3, P:  9]      |                                                        function_name_identifier:  'is_null_value'
[L:  3, P:  9]      |                                                    bracketed:
[L:  3, P:  9]      |                                                        start_bracket:  '('
[L:  3, P:  9]      |                                                        [META] indent:
[L:  3, P:  9]      |                                                        expression:
[L:  3, P:  9]      |                                                            column_reference:
[L:  3, P:  9]      |                                                                naked_identifier:  'json'
[L:  3, P:  9]      |                                                            semi_structured_expression:
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'source_payload'
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'deliveryAddress'
[L:  3, P:  9]      |                                                        [META] dedent:
[L:  3, P:  9]      |                                                        end_bracket:  ')'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                            [META] indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            keyword:          'then'
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                null_literal:  'null'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '        '
[L:  3, P:  9]      |                                        else_clause:
[L:  3, P:  9]      |                                            keyword:          'else'
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                function:
[L:  3, P:  9]      |                                                    function_name:
[L:  3, P:  9]      |                                                        function_name_identifier:  'cast'
[L:  3, P:  9]      |                                                    bracketed:
[L:  3, P:  9]      |                                                        start_bracket:  '('
[L:  3, P:  9]      |                                                        [META] indent:
[L:  3, P:  9]      |                                                        expression:
[L:  3, P:  9]      |                                                            column_reference:
[L:  3, P:  9]      |                                                                naked_identifier:  'json'
[L:  3, P:  9]      |                                                            semi_structured_expression:
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'source_payload'
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'deliveryAddress'
[L:  3, P:  9]      |                                                        whitespace:  ' '
[L:  3, P:  9]      |                                                        keyword:  'as'
[L:  3, P:  9]      |                                                        whitespace:  ' '
[L:  3, P:  9]      |                                                        data_type:
[L:  3, P:  9]      |                                                            data_type_identifier:  'variant'
[L:  3, P:  9]      |                                                        [META] dedent:
[L:  3, P:  9]      |                                                        end_bracket:  ')'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '    '
[L:  3, P:  9]      |                                        [META] dedent:
[L:  3, P:  9]      |                                        keyword:              'end'
[L:  3, P:  9]      |                                whitespace:                   ' '
[L:  3, P:  9]      |                                alias_expression:
[L:  3, P:  9]      |                                    [META] indent:
[L:  3, P:  9]      |                                    keyword:                  'as'
[L:  3, P:  9]      |                                    whitespace:               ' '
[L:  3, P:  9]      |                                    naked_identifier:         'delivery_address'
[L:  3, P:  9]      |                                    [META] dedent:
[L:  3, P:  9]      |                            [META] dedent:
[L:  3, P:  9]      |                        newline:                              '\n'
[L:  3, P: 92]      |                        newline:                              '\n'
[L:  4, P:  1]      |                        whitespace:                           '    '
[L:  4, P:  5]      |                        from_clause:
[L:  4, P:  5]      |                            keyword:                          'from'
[L:  4, P:  9]      |                            whitespace:                       ' '
[L:  4, P: 10]      |                            from_expression:
[L:  4, P: 10]      |                                [META] indent:
[L:  4, P: 10]      |                                from_expression_element:
[L:  4, P: 10]      |                                    table_expression:
[L:  4, P: 10]      |                                        table_reference:
[L:  4, P: 10]      |                                            naked_identifier:  'source'
[L:  4, P: 16]      |                                [META] dedent:
[L:  4, P: 16]      |                    newline:                                  '\n'
[L:  5, P:  1]      |                    [META] dedent:
[L:  5, P:  1]      |                    end_bracket:                              ')'
[L:  5, P:  2]      |            newline:                                          '\n'
[L:  6, P:  1]      |            select_statement:
[L:  6, P:  1]      |                select_clause:
[L:  6, P:  1]      |                    keyword:                                  'select'
[L:  6, P:  7]      |                    [META] indent:
[L:  6, P:  7]      |                    whitespace:                               ' '
[L:  6, P:  8]      |                    select_clause_element:
[L:  6, P:  8]      |                        wildcard_expression:
[L:  6, P:  8]      |                            wildcard_identifier:
[L:  6, P:  8]      |                                star:                         '*'
[L:  6, P:  9]      |                    [META] dedent:
[L:  6, P:  9]      |                newline:                                      '\n'
[L:  7, P:  1]      |                from_clause:
[L:  7, P:  1]      |                    keyword:                                  'from'
[L:  7, P:  5]      |                    whitespace:                               ' '
[L:  7, P:  6]      |                    from_expression:
[L:  7, P:  6]      |                        [META] indent:
[L:  7, P:  6]      |                        from_expression_element:
[L:  7, P:  6]      |                            table_expression:
[L:  7, P:  6]      |                                table_reference:
[L:  7, P:  6]      |                                    naked_identifier:         'test'
[L:  7, P: 10]      |                        [META] dedent:
[L:  7, P: 10]      |    newline:                                                  '\n'
[L:  8, P:  1]      |    [META] end_of_file:

Logs:

Entering linter phase main, loop 1/10

INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P:  1]) 'with'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P: 11]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  2, P:  5]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'case'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'when'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'then'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'else'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'end'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  4, P:  5]) 'from'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  6, P:  1]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  7, P:  1]) 'from'>, keyword
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  1, P:  6]) 'test'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'delivery_address'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  4, P: 10]) 'source'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  7, P:  6]) 'test'>, naked_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'is_null_value'>, function_name_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'cast'>, function_name_identifier
INFO       [CP04] _handle_segment: <LiteralKeywordSegment: ([L:  3, P:  9]) 'null'>, null_literal
INFO       [CP05] _handle_segment: <CodeSegment: ([L:  3, P:  9]) 'variant'>, data_type_identifier
INFO       # Evaluating line lengths.
INFO           Line #1. Length 14 <= 88. OK.
INFO           Line #2. Length 10 <= 88. OK.
INFO           Line #5. Length 91 > 88. PROBLEM.
INFO           Line #10. Length 15 <= 88. OK.
INFO           Line #11. Length 1 <= 88. OK.
INFO           Line #12. Length 8 <= 88. OK.
INFO           Line #13. Length 9 <= 88. OK.
INFO       [LT05] !! Violation Found: 'Line is too long (91 > 88).'
INFO       [LT05] !! Fix Proposed: <LintFix: replace whitespace@[L:  3, P:  9] edt:' '->'\n            '>
INFO       Applying Fixes [LT05]: [<LintFix: replace whitespace@[L:  3, P:  9] edt:' '->'\n            '>]
INFO

Entering linter phase main, loop 2/10

INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P:  1]) 'with'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P: 11]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  2, P:  5]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'case'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'when'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'then'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'else'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'end'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  4, P:  5]) 'from'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  6, P:  1]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  7, P:  1]) 'from'>, keyword
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  1, P:  6]) 'test'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'delivery_address'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  4, P: 10]) 'source'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  7, P:  6]) 'test'>, naked_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'is_null_value'>, function_name_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'cast'>, function_name_identifier
INFO       [CP04] _handle_segment: <LiteralKeywordSegment: ([L:  3, P:  9]) 'null'>, null_literal
INFO       [CP05] _handle_segment: <CodeSegment: ([L:  3, P:  9]) 'variant'>, data_type_identifier
INFO       # Evaluating line lengths.
INFO           Line #1. Length 14 <= 88. OK.
INFO           Line #2. Length 10 <= 88. OK.
INFO           Line #5. Length 91 > 88. PROBLEM.
INFO           Line #9. Length 95 > 88. PROBLEM.
INFO           Line #11. Length 15 <= 88. OK.
INFO           Line #12. Length 1 <= 88. OK.
INFO           Line #13. Length 8 <= 88. OK.
INFO           Line #14. Length 9 <= 88. OK.
INFO       [LT05] !! Violation Found: 'Line is too long (91 > 88).'
INFO       [LT05] !! Violation Found: 'Line is too long (95 > 88).'
INFO       [LT05] !! Fix Proposed: <LintFix: replace indent@[L:  3, P:  9] edt:''->'            '>
INFO       [LT05] !! Fix Proposed: <LintFix: replace dedent@[L:  3, P:  9] edt:''->'        '>
INFO       Applying Fixes [LT05]: [<LintFix: replace indent@[L:  3, P:  9] edt:''->'            '>, <LintFix: replace dedent@[L:  3, P:  9] edt:''->'        '>]
INFO

Entering linter phase main, loop 3/10

INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P:  1]) 'with'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P: 11]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  2, P:  5]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'case'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'when'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'then'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'else'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'end'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  4, P:  5]) 'from'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  6, P:  1]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  7, P:  1]) 'from'>, keyword
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  1, P:  6]) 'test'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'delivery_address'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  4, P: 10]) 'source'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  7, P:  6]) 'test'>, naked_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'is_null_value'>, function_name_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'cast'>, function_name_identifier
INFO       [CP04] _handle_segment: <LiteralKeywordSegment: ([L:  3, P:  9]) 'null'>, null_literal
INFO       [CP05] _handle_segment: <CodeSegment: ([L:  3, P:  9]) 'variant'>, data_type_identifier
INFO       # Evaluating line lengths.
INFO           Line #1. Length 14 <= 88. OK.
INFO           Line #2. Length 10 <= 88. OK.
INFO           Line #5. Length 111 > 88. PROBLEM.
INFO           Line #9. Length 95 > 88. PROBLEM.
INFO           Line #11. Length 15 <= 88. OK.
INFO           Line #12. Length 1 <= 88. OK.
INFO           Line #13. Length 8 <= 88. OK.
INFO           Line #14. Length 9 <= 88. OK.
INFO       [LT05] !! Violation Found: 'Line is too long (111 > 88).'
INFO       [LT05] !! Violation Found: 'Line is too long (95 > 88).'
INFO       [LT05] !! Fix Proposed: <LintFix: replace indent@[L:  3, P:  9] edt:''->'            '>
INFO       [LT05] !! Fix Proposed: <LintFix: replace dedent@[L:  3, P:  9] edt:''->'        '>
INFO       Applying Fixes [LT05]: [<LintFix: replace indent@[L:  3, P:  9] edt:''->'            '>, <LintFix: replace dedent@[L:  3, P:  9] edt:''->'        '>]
WARNING    One fix for LT05 not applied, it would re-cause the same error.
INFO       Fix loop complete for main phase. Stability achieved after 2/10 loops.
INFO

Entering linter phase post, loop 1/10

INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P:  1]) 'with'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  1, P: 11]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  2, P:  5]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'case'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'when'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'then'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'else'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'end'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  3, P:  9]) 'as'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  4, P:  5]) 'from'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  6, P:  1]) 'select'>, keyword
INFO       [CP01] _handle_segment: <KeywordSegment: ([L:  7, P:  1]) 'from'>, keyword
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  1, P:  6]) 'test'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'json'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  3, P:  9]) 'delivery_address'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  4, P: 10]) 'source'>, naked_identifier
INFO       [CP02] _handle_segment: <IdentifierSegment: ([L:  7, P:  6]) 'test'>, naked_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'is_null_value'>, function_name_identifier
INFO       [CP03] _handle_segment: <WordSegment: ([L:  3, P:  9]) 'cast'>, function_name_identifier
INFO       [CP04] _handle_segment: <LiteralKeywordSegment: ([L:  3, P:  9]) 'null'>, null_literal
INFO       [CP05] _handle_segment: <CodeSegment: ([L:  3, P:  9]) 'variant'>, data_type_identifier
INFO       Fix loop complete for post phase. Stability achieved after 0/10 loops.
INFO

Fixed tree:

###
#
# Fixed Tree:
#
###
INFO
[L:  1, P:  1]      |file:
[L:  1, P:  1]      |    statement:
[L:  1, P:  1]      |        with_compound_statement:
[L:  1, P:  1]      |            keyword:                                          'with'
[L:  1, P:  5]      |            whitespace:                                       ' '
[L:  1, P:  6]      |            common_table_expression:
[L:  1, P:  6]      |                naked_identifier:                             'test'
[L:  1, P: 10]      |                whitespace:                                   ' '
[L:  1, P: 11]      |                keyword:                                      'as'
[L:  1, P: 13]      |                whitespace:                                   ' '
[L:  1, P: 14]      |                bracketed:
[L:  1, P: 14]      |                    start_bracket:                            '('
[L:  1, P: 15]      |                    [META] indent:
[L:  1, P: 15]      |                    newline:                                  '\n'
[L:  2, P:  1]      |                    whitespace:                               '    '
[L:  2, P:  5]      |                    select_statement:
[L:  2, P:  5]      |                        select_clause:
[L:  2, P:  5]      |                            keyword:                          'select'
[L:  2, P: 11]      |                            [META] indent:
[L:  2, P: 11]      |                            newline:                          '\n'
[L:  3, P:  1]      |                            whitespace:                       '        '
[L:  3, P:  9]      |                            newline:                          '\n'
[L:  3, P:  9]      |                            whitespace:                       '    '
[L:  3, P:  9]      |                            newline:                          '\n'
[L:  3, P:  9]      |                            whitespace:                       '    '
[L:  3, P:  9]      |                            select_clause_element:
[L:  3, P:  9]      |                                expression:
[L:  3, P:  9]      |                                    case_expression:
[L:  3, P:  9]      |                                        keyword:              'case'
[L:  3, P:  9]      |                                        [META] (implicit) indent:
[L:  3, P:  9]      |                                        whitespace:           '            '
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '        '
[L:  3, P:  9]      |                                        when_clause:
[L:  3, P:  9]      |                                            keyword:          'when'
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                function:
[L:  3, P:  9]      |                                                    function_name:
[L:  3, P:  9]      |                                                        function_name_identifier:  'is_null_value'
[L:  3, P:  9]      |                                                    bracketed:
[L:  3, P:  9]      |                                                        start_bracket:  '('
[L:  3, P:  9]      |                                                        [META] indent:
[L:  3, P:  9]      |                                                        expression:
[L:  3, P:  9]      |                                                            column_reference:
[L:  3, P:  9]      |                                                                naked_identifier:  'json'
[L:  3, P:  9]      |                                                            semi_structured_expression:
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'source_payload'
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'deliveryAddress'
[L:  3, P:  9]      |                                                        [META] dedent:
[L:  3, P:  9]      |                                                        end_bracket:  ')'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                            [META] indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            keyword:          'then'
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                null_literal:  'null'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '        '
[L:  3, P:  9]      |                                        else_clause:
[L:  3, P:  9]      |                                            keyword:          'else'
[L:  3, P:  9]      |                                            [META] (implicit) indent:
[L:  3, P:  9]      |                                            whitespace:       ' '
[L:  3, P:  9]      |                                            expression:
[L:  3, P:  9]      |                                                function:
[L:  3, P:  9]      |                                                    function_name:
[L:  3, P:  9]      |                                                        function_name_identifier:  'cast'
[L:  3, P:  9]      |                                                    bracketed:
[L:  3, P:  9]      |                                                        start_bracket:  '('
[L:  3, P:  9]      |                                                        [META] indent:
[L:  3, P:  9]      |                                                        expression:
[L:  3, P:  9]      |                                                            column_reference:
[L:  3, P:  9]      |                                                                naked_identifier:  'json'
[L:  3, P:  9]      |                                                            semi_structured_expression:
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'source_payload'
[L:  3, P:  9]      |                                                                colon:  ':'
[L:  3, P:  9]      |                                                                semi_structured_element:  'deliveryAddress'
[L:  3, P:  9]      |                                                        whitespace:  ' '
[L:  3, P:  9]      |                                                        keyword:  'as'
[L:  3, P:  9]      |                                                        whitespace:  ' '
[L:  3, P:  9]      |                                                        data_type:
[L:  3, P:  9]      |                                                            data_type_identifier:  'variant'
[L:  3, P:  9]      |                                                        [META] dedent:
[L:  3, P:  9]      |                                                        end_bracket:  ')'
[L:  3, P:  9]      |                                            [META] dedent:
[L:  3, P:  9]      |                                        whitespace:           '        '
[L:  3, P:  9]      |                                        newline:              '\n'
[L:  3, P:  9]      |                                        whitespace:           '    '
[L:  3, P:  9]      |                                        [META] dedent:
[L:  3, P:  9]      |                                        keyword:              'end'
[L:  3, P: 92]      |                                newline:                      '\n'
[L:  3, P:  9]      |                                whitespace:                   '            '
[L:  3, P:  9]      |                                alias_expression:
[L:  3, P:  9]      |                                    [META] indent:
[L:  3, P:  9]      |                                    keyword:                  'as'
[L:  3, P:  9]      |                                    whitespace:               ' '
[L:  3, P:  9]      |                                    naked_identifier:         'delivery_address'
[L:  3, P:  9]      |                                    [META] dedent:
[L:  3, P:  9]      |                            [META] dedent:
[L:  3, P:  9]      |                        newline:                              '\n'
[L:  3, P: 92]      |                        newline:                              '\n'
[L:  4, P:  1]      |                        whitespace:                           '    '
[L:  4, P:  5]      |                        from_clause:
[L:  4, P:  5]      |                            keyword:                          'from'
[L:  4, P:  9]      |                            whitespace:                       ' '
[L:  4, P: 10]      |                            from_expression:
[L:  4, P: 10]      |                                [META] indent:
[L:  4, P: 10]      |                                from_expression_element:
[L:  4, P: 10]      |                                    table_expression:
[L:  4, P: 10]      |                                        table_reference:
[L:  4, P: 10]      |                                            naked_identifier:  'source'
[L:  4, P: 16]      |                                [META] dedent:
[L:  4, P: 16]      |                    newline:                                  '\n'
[L:  5, P:  1]      |                    [META] dedent:
[L:  5, P:  1]      |                    end_bracket:                              ')'
[L:  5, P:  2]      |            newline:                                          '\n'
[L:  6, P:  1]      |            select_statement:
[L:  6, P:  1]      |                select_clause:
[L:  6, P:  1]      |                    keyword:                                  'select'
[L:  6, P:  7]      |                    [META] indent:
[L:  6, P:  7]      |                    whitespace:                               ' '
[L:  6, P:  8]      |                    select_clause_element:
[L:  6, P:  8]      |                        wildcard_expression:
[L:  6, P:  8]      |                            wildcard_identifier:
[L:  6, P:  8]      |                                star:                         '*'
[L:  6, P:  9]      |                    [META] dedent:
[L:  6, P:  9]      |                newline:                                      '\n'
[L:  7, P:  1]      |                from_clause:
[L:  7, P:  1]      |                    keyword:                                  'from'
[L:  7, P:  5]      |                    whitespace:                               ' '
[L:  7, P:  6]      |                    from_expression:
[L:  7, P:  6]      |                        [META] indent:
[L:  7, P:  6]      |                        from_expression_element:
[L:  7, P:  6]      |                            table_expression:
[L:  7, P:  6]      |                                table_reference:
[L:  7, P:  6]      |                                    naked_identifier:         'test'
[L:  7, P: 10]      |                        [META] dedent:
[L:  7, P: 10]      |    newline:                                                  '\n'
[L:  8, P:  1]      |    [META] end_of_file:

How to reproduce

With the following macro:

{% macro parse_sub_variant(source_column, value_path, name) %}
    {% set full_path = source_column + ":" + value_path %}
    case
        when is_null_value({{full_path}}) then null
        else cast({{full_path}} as variant)
    end as {{name}}
{% endmacro %}

The following snippet:

with test as (
    select
        {{parse_sub_variant('json', 'source_payload:deliveryAddress', 'delivery_address')}}
    from source
)
select *
from test

Is reformatted to:

with test as (
    select
                    {{parse_sub_variant('json', 'source_payload:deliveryAddress', 'delivery_address')}}        {{parse_sub_variant('json', 'source_payload:deliveryAddress', 'delivery_address')}}        {{parse_sub_variant('json', 'source_payload:deliveryAddress', 'delivery_address')}}
    from source
)
select *
from test

With the following rule failure:

L:   3 | P:   9 | LT05 | Line is too long (91 > 88).
                       | [layout.long_lines]

Dialect

Snowflake

Version

sqlfluff, version 2.3.5
sqlfluff-templater-dbt, version 2.3.5
dbt, version 1.7.9

Configuration

[sqlfluff]
dialect = snowflake
templater = dbt
max_line_length = 88
runaway_limit = 10
indent_unit = space
exclude_rules = layout.indent, layout.cte_bracket, layout.cte_newline, layout.select_targets, jinja.padding, references.keywords
processes = -1

[sqlfluff:indentation]
tab_space_size = 4

[sqlfluff:layout:type:comma]
spacing_before = touch
line_position = trailing

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower

[sqlfluff:rules:aliasing.table]
aliasing = explicit

[sqlfluff:rules:aliasing.column]
aliasing = explicit

[sqlfluff:rules:aliasing.expression]
allow_scalar = False

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

[sqlfluff:rules:capitalisation.functions]
capitalisation_policy = lower

[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower

[sqlfluff:rules:ambiguous.column_references] # Number in group by
group_by_and_order_by_style = implicit

[sqlfluff:templater:jinja]
apply_dbt_builtins = True

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

I have the same issue with the following config:

dbt-bigquery==1.6.0
sqlfluff==3.0.5
[sqlfluff]
dialect = bigquery
max_line_length = 120
exclude_rules = aliasing.self_alias.column,structure.column_order

[sqlfluff:layout:type:alias_expression]
spacing_before = align
align_within = select_clause
align_scope = bracketed

[sqlfluff:rules:convention.select_trailing_comma]
select_clause_trailing_comma = require

[sqlfluff:rules:structure.join_condition_order]
preferred_first_table_in_join_clause = later

[sqlfluff:templater:jinja]
apply_dbt_builtins = True
load_macros_from_path = <path>

I've disabled the line length rule as a workaround.

Also seeing the same issue but with dbt + Snowflake combination.

sqlfluff, version 3.0.7
dbt --version
Core:
  - installed: 1.8.2
  - latest:    1.8.2 - Up to date!
Plugins:
  - snowflake: 1.8.2 - Up to date!