mirror of
https://github.com/sqlfluff/sqlfluff
synced 2025-12-17 19:31:32 +00:00
Disregard CV12 when UNNEST is detected in from_expression_element (#7211)
This commit is contained in:
committed by
GitHub
parent
367611d707
commit
b1a9d8a436
@@ -108,9 +108,17 @@ class Rule_CV12(BaseRule):
|
|||||||
no_recursive_seg_type=["select_statement"],
|
no_recursive_seg_type=["select_statement"],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
encountered_function = self._get_from_expression_element_function(
|
||||||
|
join_table_reference
|
||||||
|
)
|
||||||
|
if encountered_function in ("UNNEST",):
|
||||||
|
# If UNNEST function is used, disregard lack of condition
|
||||||
|
continue
|
||||||
|
|
||||||
encountered_references.add(
|
encountered_references.add(
|
||||||
self._get_from_expression_element_alias(join_table_reference)
|
self._get_from_expression_element_alias(join_table_reference)
|
||||||
)
|
)
|
||||||
|
|
||||||
join_clause_keywords = [
|
join_clause_keywords = [
|
||||||
seg for seg in join_clause.segments if seg.type == "keyword"
|
seg for seg in join_clause.segments if seg.type == "keyword"
|
||||||
]
|
]
|
||||||
@@ -262,6 +270,32 @@ class Rule_CV12(BaseRule):
|
|||||||
|
|
||||||
return alias_str
|
return alias_str
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_from_expression_element_function(from_expr_element: BaseSegment) -> str:
|
||||||
|
"""Extract the function name from a from_expression_element if present."""
|
||||||
|
|
||||||
|
def get_segment_or_default(
|
||||||
|
segment: BaseSegment, child_type: str, default: BaseSegment
|
||||||
|
) -> BaseSegment:
|
||||||
|
"""Helper to safely get a child segment or return a default."""
|
||||||
|
child = segment.get_child(child_type)
|
||||||
|
return child if child else default
|
||||||
|
|
||||||
|
table_expr = get_segment_or_default(
|
||||||
|
from_expr_element, "table_expression", from_expr_element
|
||||||
|
)
|
||||||
|
|
||||||
|
if "function" not in table_expr.direct_descendant_type_set:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
function = get_segment_or_default(table_expr, "function", table_expr)
|
||||||
|
function_name = get_segment_or_default(function, "function_name", table_expr)
|
||||||
|
function_id = get_segment_or_default(
|
||||||
|
function_name, "function_name_identifier", table_expr
|
||||||
|
)
|
||||||
|
|
||||||
|
return function_id.raw_upper
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_where_clause_simplifable(where_clause: BaseSegment) -> bool:
|
def _is_where_clause_simplifable(where_clause: BaseSegment) -> bool:
|
||||||
assert where_clause.is_type("where_clause")
|
assert where_clause.is_type("where_clause")
|
||||||
|
|||||||
@@ -109,3 +109,26 @@ test_fail_join_with_bracketed_join:
|
|||||||
)
|
)
|
||||||
WHERE
|
WHERE
|
||||||
bar.id = foo1.id;
|
bar.id = foo1.id;
|
||||||
|
|
||||||
|
test_pass_left_join_unnest_where_aliased:
|
||||||
|
pass_str: |
|
||||||
|
SELECT
|
||||||
|
t.user_id,
|
||||||
|
unnested_value AS purchased_product
|
||||||
|
FROM
|
||||||
|
t
|
||||||
|
LEFT JOIN
|
||||||
|
UNNEST(t.purchases) AS unnested_value
|
||||||
|
WHERE
|
||||||
|
unnested_value = 'laptop'
|
||||||
|
|
||||||
|
test_pass_left_join_unnest_where_unaliased:
|
||||||
|
pass_str: |
|
||||||
|
SELECT
|
||||||
|
t.user_id
|
||||||
|
FROM
|
||||||
|
t
|
||||||
|
LEFT JOIN
|
||||||
|
UNNEST(t.purchases)
|
||||||
|
WHERE
|
||||||
|
t.user_id != 1
|
||||||
|
|||||||
Reference in New Issue
Block a user