Skip to content

Commit f718f3c

Browse files
committed
add additional test for next already solved issue
1 parent 67725cd commit f718f3c

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

test/test_getting_tables.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ def test_presto_unnest_not_table():
877877
assert "col_" in parser.columns
878878

879879

880+
def test_bigquery_unnest_not_table():
881+
# Solved: https://github.com/macbre/sql-metadata/issues/352
882+
p = Parser(
883+
"SELECT A, B, metrics.C, metrics.D "
884+
"FROM table1, UNNEST(metrics) as metrics"
885+
)
886+
assert p.tables == ["table1"]
887+
assert "metrics" in p.columns
888+
889+
880890
def test_from_order_does_not_affect_tables():
881891
# solved: https://github.com/macbre/sql-metadata/issues/335
882892
query1 = "SELECT aa FROM (SELECT bb FROM bbb GROUP BY bb) AS a, omg"

test/test_with_statements.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,34 @@ def test_nested_resolver_unresolvable_reference():
675675
assert "nonexistent.col" in p.columns
676676

677677

678+
def test_cte_with_subquery_and_star_alias():
679+
# Solved: https://github.com/macbre/sql-metadata/issues/392
680+
p = Parser("""with x as (select d.nbr, d.af_pk
681+
from test_db.test_table3 d)
682+
select q.hx_id, q.text
683+
from (select prod_code, s.*
684+
from testdb.test_table s
685+
inner join testdb.test_table2 p on s.s1_fk = p.p1_sk
686+
) q
687+
inner join x on q.s2_fk = x.af_pk""")
688+
assert p.tables == [
689+
"test_db.test_table3", "testdb.test_table", "testdb.test_table2"
690+
]
691+
assert p.with_names == ["x"]
692+
assert "testdb.test_table.*" in p.columns
693+
694+
695+
def test_bracketed_select_with_cte_and_column_alias():
696+
# Solved: https://github.com/macbre/sql-metadata/issues/326
697+
p = Parser("""with a as (select id, a from tbl1),
698+
with b as (select id, b from tbl2)
699+
(select a.id, a.a + b.b as t
700+
from a left join b on a.id = b.id)""")
701+
assert p.tables == ["tbl1", "tbl2"]
702+
assert p.with_names == ["a", "b"]
703+
assert p.columns == ["id", "a", "b"]
704+
705+
678706
def test_with_queries_empty_when_no_cte():
679707
"""A query with no CTEs returns empty with_queries."""
680708
p = Parser("SELECT * FROM t")

0 commit comments

Comments
 (0)