Repository: reata/sqllineage
Pull request #560 (2024-01-19 01:36:25)

fix: issue (#559)
fix: issue (#559)

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/reata/sqllineage/pull/560?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`06a474b`)](https://app.codecov.io/gh/reata/sqllineage/commit/06a474b5e7d6a26994db18f97cf9058246cd24bd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 99.50% compared to head [(`158c10a`)](https://app.codecov.io/gh/reata/sqllineage/pull/560?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) 99.50%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #560   +/-   ##
=======================================
  Coverage   99.50%   99.50%           
=======================================
  Files          41       41           
  Lines        2211     2211           
=======================================
  Hits         2200     2200           
  Misses         11       11           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/reata/sqllineage/pull/560?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/sqllineage/core/parser/sqlfluff/utils.py b/sqllineage/core/parser/sqlfluff/utils.py
index 6092673..2f80106 100644
--- a/sqllineage/core/parser/sqlfluff/utils.py
+++ b/sqllineage/core/parser/sqlfluff/utils.py
@@ -131,7 +131,7 @@ def list_expression_from_when_clause(
 def list_subqueries(segment: BaseSegment) -> List[SubQueryTuple]:
     subquery = []
     if segment.type == "select_clause":
-        if select_clause_element := segment.get_child("select_clause_element"):
+        for select_clause_element in segment.get_children("select_clause_element"):
             if expression := select_clause_element.get_child("expression"):
                 if case_expression := expression.get_child("case_expression"):
                     for when_clause in case_expression.get_children("when_clause"):


Test patch:
diff --git a/tests/sql/table/test_select.py b/tests/sql/table/test_select.py
index d47ee62..ae70a27 100644
--- a/tests/sql/table/test_select.py
+++ b/tests/sql/table/test_select.py
@@ -140,6 +140,18 @@ CASE WHEN (SELECT count(*) FROM tab1 WHERE col1 = 'tab2') = 1 THEN (SELECT count
 CASE WHEN 1 = (SELECT count(*) FROM tab1 WHERE col1 = 'tab2') THEN (SELECT count(*) FROM tab2) ELSE 0 END AS cnt""",
         {"tab1", "tab2"},
     )
+    assert_table_lineage_equal(
+        """
+        select
+            1,
+            case
+                when 1 = ( select count(*) from tab1 where col1 = 'tab2' )
+                    then ( select count(*) from tab2 )
+                else 0
+            end as cnt
+        """,
+        {"tab1", "tab2"},
+    )
 
 
 def test_select_subquery_without_alias():