File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
951973def test_degraded_parse_falls_through_to_last_dialect ():
952974 """SELECT UNIQUE triggers multi-dialect retry."""
953975 p = Parser ("SELECT UNIQUE col FROM t" )
You can’t perform that action at this time.
0 commit comments