Skip to content

Exception when applying structure.subquery (ST05) to table functions with sub-query arguments #6777

@sebastien-irco

Description

@sebastien-irco

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Applying structure.subquery (ST05) to SQL code involving table functions with sub-query arguments results in the following exception:

AssertionError: table_expression should have a bracketed segment

Minimal example to reproduce:

SELECT *
FROM `func`((
  SELECT 1
));

Unfortunately, even adding -- noqa: ST05 does not prevent the runtime exception, but only suppressed the rule violation:

SELECT * -- noqa: ST05
FROM `func`((
  SELECT 1
));
sqlfluff lint test.sql
CRITICAL   [ST05] Applying rule ST05 to 'test.sql' threw an Exception: table_expression should have a bracketed segment
Traceback (most recent call last):
  File "C:\Python312\Lib\site-packages\sqlfluff\core\rules\base.py", line 524, in crawl
    res = self._eval(context=context)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\site-packages\sqlfluff\rules\structure\ST05.py", line 158, in _eval
    for result in results:
  File "C:\Python312\Lib\site-packages\sqlfluff\rules\structure\ST05.py", line 276, in _lint_query
    assert (
AssertionError: table_expression should have a bracketed segment
All Finished 📜 🎉!

Expected Behaviour

Ideally: support this pattern
Minimal: supress exception through --noqa: ST05

Observed Behaviour

Exception (see above)

How to reproduce

See above

Dialect

BigQuery

Version

SQLFluff version: 3.3.1
Python version: 3.12.2

Configuration

[sqlfluff]
dialect = bigquery
large_file_skip_byte_limit = 50000

logging_level = DEBUG

rules = aliasing.table, aliasing.column, aliasing.unique.table, aliasing.unused, aliasing.unique.column, aliasing.self_alias.column, ambiguous.distinct, ambiguous.union, ambiguous.join, ambiguous.column_references, ambiguous.join_condition, capitalisation.keywords, capitalisation.identifiers, capitalisation.functions, capitalisation.literals, capitalisation.types, convention.not_equal, convention.coalesce, convention.select_trailing_comma, convention.count_rows, convention.is_null, convention.terminator, convention.statement_brackets, convention.left_join, convention.blocked_words, convention.quoted_literals, convention.casting_style, convention.join_condition, layout.spacing, layout.indent, layout.operators, layout.commas, layout.long_lines, layout.functions, layout.cte_bracket, layout.cte_newline, layout.select_targets, layout.select_modifiers, layout.set_operators, layout.end_of_file, layout.start_of_file, layout.keyword_newline, references.special_chars, references.quoting, structure.else_null, structure.simple_case, structure.unused_cte, structure.nested_case, structure.subquery, structure.using, structure.distinct, structure.join_condition_order, structure.constant_expression, structure.unused_join

exclude_rules = None

warnings = None

max_line_length = 100

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

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

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

[sqlfluff:rules:aliasing.unused]
alias_case_check = case_sensitive

[sqlfluff:rules:aliasing.length]
min_alias_length = None
max_alias_length = None

[sqlfluff:rules:aliasing.forbid]
force_enable = False

[sqlfluff:rules:ambiguous.join]
fully_qualify_join_types = inner

[sqlfluff:rules:ambiguous.column_references]
group_by_and_order_by_style = explicit

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper
ignore_words = day

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = snake
ignore_words = INFORMATION_SCHEMA, PARTITIONTIME, TABLE
ignore_words_regex = ^([a-z0-9
]|[A-Z0-9_])$

[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = upper
ignore_words = None
ignore_words_regex = ^(.*)$

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

[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = upper
ignore_words = None

[sqlfluff:rules:convention.not_equal]
preferred_not_equal_style = c_style

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

[sqlfluff:rules:convention.count_rows]
prefer_count_1 = False
prefer_count_0 = False

[sqlfluff:rules:convention.terminator]
multiline_newline = False
require_final_semicolon = True

[sqlfluff:rules:convention.blocked_words]
blocked_words = None
blocked_regex = None
match_source = False

[sqlfluff:rules:convention.quoted_literals]
preferred_quoted_literal_style = double_quotes
force_enable = True

[sqlfluff:rules:convention.casting_style]
preferred_type_casting_style = cast

[sqlfluff:rules:layout.long_lines]
ignore_comment_lines = False
ignore_comment_clauses = False

[sqlfluff:rules:layout.select_targets]
wildcard_policy = single

[sqlfluff:rules:references.from]
force_enable = False

[sqlfluff:rules:references.qualification]
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:references.consistent]
force_enable = False

[sqlfluff:rules:references.keywords]
unquoted_identifiers_policy = all
quoted_identifiers_policy = none
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:references.special_chars]
unquoted_identifiers_policy = all
quoted_identifiers_policy = all
allow_space_in_identifier = False
additional_allowed_characters = None
ignore_words = None
ignore_words_regex = None

[sqlfluff:rules:references.quoting]
prefer_quoted_identifiers = False
prefer_quoted_keywords = False
ignore_words = None
ignore_words_regex = None
case_sensitive = True

[sqlfluff:rules:structure.subquery]
forbid_subquery_in = both

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

[sqlfluff:indentation]
indent_unit = space
tab_space_size = 2
indented_joins = False
indented_ctes = False
indented_using_on = False
indented_on_contents = True
indented_then = False
indented_then_contents = True
allow_implicit_indents = True
skip_indentation_in = script_content
trailing_comments = before
ignore_comment_lines = False

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

[sqlfluff:layout:type:binary_operator]
spacing_within = touch
line_position = leading

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

[sqlfluff:layout:type:end_of_file]
spacing_before = touch

[sqlfluff:layout:type:set_operator]
line_position = alone:strict

[sqlfluff:layout:type:start_bracket]
spacing_before = single
spacing_after = touch

[sqlfluff:layout:type:end_bracket]
spacing_before = touch

[sqlfluff:layout:type:start_square_bracket]
spacing_after = touch

[sqlfluff:layout:type:end_square_bracket]
spacing_before = touch

[sqlfluff:layout:type:start_angle_bracket]
spacing_after = touch

[sqlfluff:layout:type:end_angle_bracket]
spacing_before = touch

[sqlfluff:layout:type:casting_operator]
spacing_before = touch
spacing_after = touch:inline

[sqlfluff:layout:type:slice]
spacing_before = touch
spacing_after = touch

[sqlfluff:layout:type:dot]
spacing_before = touch
spacing_after = touch

[sqlfluff:layout:type:comparison_operator]
spacing_within = touch
line_position = leading

[sqlfluff:layout:type:assignment_operator]
spacing_within = touch
line_position = leading

[sqlfluff:layout:type:object_reference]
spacing_within = touch:inline

[sqlfluff:layout:type:numeric_literal]
spacing_within = touch:inline

[sqlfluff:layout:type:sign_indicator]
spacing_after = touch:inline

[sqlfluff:layout:type:tilde]
spacing_after = touch:inline

[sqlfluff:layout:type:function_name]
spacing_within = touch:inline
spacing_after = touch:inline

[sqlfluff:layout:type:function_contents]
spacing_before = touch:inline

[sqlfluff:layout:type:function_parameter_list]
spacing_before = touch:inline

[sqlfluff:layout:type:procedure_name]
spacing_before = single:inline
spacing_after = touch:inline

[sqlfluff:layout:type:array_type]
spacing_within = touch:inline

[sqlfluff:layout:type:typed_array_literal]
spacing_within = touch

[sqlfluff:layout:type:sized_array_type]
spacing_within = touch

[sqlfluff:layout:type:struct_type]
spacing_within = touch:inline

[sqlfluff:layout:type:bracketed_arguments]
spacing_before = touch:inline

[sqlfluff:layout:type:typed_struct_literal]
spacing_within = touch

[sqlfluff:layout:type:semi_structured_expression]
spacing_within = touch:inline
spacing_before = touch:inline

[sqlfluff:layout:type:array_accessor]
spacing_before = touch:inline

[sqlfluff:layout:type:colon]
spacing_before = touch

[sqlfluff:layout:type:colon_delimiter]
spacing_before = touch
spacing_after = touch

[sqlfluff:layout:type:path_segment]
spacing_within = touch

[sqlfluff:layout:type:sql_conf_option]
spacing_within = touch

[sqlfluff:layout:type:sqlcmd_operator]
spacing_before = touch

[sqlfluff:layout:type:comment]
spacing_before = single
spacing_after = any

[sqlfluff:layout:type:pattern_expression]
spacing_within = any

[sqlfluff:layout:type:placeholder]
spacing_before = any
spacing_after = any

[sqlfluff:layout:type:common_table_expression]
spacing_within = single:inline

[sqlfluff:layout:type:select_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:where_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:from_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:join_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:join_on_condition]
keyword_line_position = leading:strict

[sqlfluff:layout:type:groupby_clause]
keyword_line_position = leading:strict
spacing_within = single:inline

[sqlfluff:layout:type:having_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:limit_clause]
keyword_line_position = leading:strict
spacing_within = single:inline

[sqlfluff:layout:type:partitionby_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:orderby_clause]
keyword_line_position = leading:strict

[sqlfluff:layout:type:template_loop]
spacing_before = any
spacing_after = any

[sqlfluff:layout:type:select_modifiers]
spacing_within = single
line_position = leading

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions