Skip to content

Commit 2adf8c8

Browse files
authored
Merge pull request #3 from mindsdb/mixed-join
Mixed join support
2 parents 647d887 + f62e593 commit 2adf8c8

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

mindsdb_sql_parser/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'mindsdb_sql_parser'
22
__package_name__ = 'mindsdb_sql_parser'
3-
__version__ = '0.0.2'
3+
__version__ = '0.1.0'
44
__description__ = "Mindsdb SQL parser"
55
__email__ = "[email protected]"
66
__author__ = 'MindsDB Inc'

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)