Skip to content

Commit 4df6a52

Browse files
committed
Add regression test for issue #253
Resolves #253.
1 parent 9af6df2 commit 4df6a52

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

test/test_getting_tables.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,28 @@ def test_unmatched_parentheses_graceful():
948948
assert isinstance(tables, list)
949949

950950

951+
def test_mysql_view_definition_with_bracketed_join():
952+
# solved: https://github.com/macbre/sql-metadata/issues/253
953+
# MySQL view definitions wrap the FROM source in parentheses and
954+
# double-bracket the ON clause; used to crash with AttributeError.
955+
query = (
956+
"select `t`.`symbol` AS `symbol` "
957+
"from (`stock`.`top_momentum_sector` `s` "
958+
"join `stock`.`daily_companies` `t` "
959+
"on((`s`.`symbol` = `t`.`symbol`)))"
960+
)
961+
parser = Parser(query)
962+
assert parser.tables == ["stock.top_momentum_sector", "stock.daily_companies"]
963+
assert parser.columns == [
964+
"stock.daily_companies.symbol",
965+
"stock.top_momentum_sector.symbol",
966+
]
967+
assert parser.tables_aliases == {
968+
"s": "stock.top_momentum_sector",
969+
"t": "stock.daily_companies",
970+
}
971+
972+
951973
def test_degraded_parse_falls_through_to_last_dialect():
952974
"""SELECT UNIQUE triggers multi-dialect retry."""
953975
p = Parser("SELECT UNIQUE col FROM t")

0 commit comments

Comments
 (0)