Skip to content

Commit 0a02b66

Browse files
committed
mixed join support
1 parent 647d887 commit 0a02b66

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

mindsdb_sql_parser/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,8 @@ def join_tables(self, p):
12151215
condition=p.expr)
12161216

12171217
@_('from_table_aliased COMMA from_table_aliased',
1218-
'join_tables_implicit COMMA from_table_aliased')
1218+
'join_tables_implicit COMMA from_table_aliased',
1219+
'join_tables COMMA from_table_aliased')
12191220
def join_tables_implicit(self, p):
12201221
return Join(left=p[0],
12211222
right=p[2],

tests/test_base_sql/test_select_structure.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,3 +1201,38 @@ def test_window_function_mindsdb(self):
12011201
assert str(ast) == str(expected_ast)
12021202
assert ast.to_tree() == expected_ast.to_tree()
12031203

1204+
def test_mixed_join(self):
1205+
1206+
# modifier
1207+
query = '''
1208+
select * from table1 a
1209+
inner join table2 b on a.x = b.y
1210+
and k = p,
1211+
table3,
1212+
table4
1213+
'''
1214+
expected_ast = Select(
1215+
targets=[Star()],
1216+
from_table=Join(
1217+
left=Join(
1218+
left=Join(
1219+
left=Identifier('table1', alias=Identifier('a')),
1220+
right=Identifier('table2', alias=Identifier('b')),
1221+
condition=BinaryOperation(op='and', args=[
1222+
BinaryOperation(op='=', args=[Identifier('a.x'), Identifier('b.y')]),
1223+
BinaryOperation(op='=', args=[Identifier('k'), Identifier('p')])
1224+
]),
1225+
join_type=JoinType.INNER_JOIN,
1226+
),
1227+
right=Identifier('table3'),
1228+
join_type=JoinType.INNER_JOIN,
1229+
implicit=True
1230+
),
1231+
right=Identifier('table4'),
1232+
join_type=JoinType.INNER_JOIN,
1233+
implicit=True
1234+
)
1235+
)
1236+
ast = parse_sql(query)
1237+
assert str(ast) == str(expected_ast)
1238+
assert ast.to_tree() == expected_ast.to_tree()

0 commit comments

Comments
 (0)