Skip to content

Commit 291a914

Browse files
committed
fix of #48
1 parent fd402aa commit 291a914

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

mindsdb_sql_parser/ast/select/operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, op, args, *args_, **kwargs):
1010
self.op = ' '.join(op.lower().split())
1111
self.args = []
1212
for item in args:
13-
if isinstance(item, ASTNode) and item.parentheses:
13+
if self.op in ("in", "not in") and isinstance(item, ASTNode) and item.parentheses:
1414
item.parentheses = False
1515
item = Tuple([item])
1616
self.args.append(item)

tests/test_base_sql/test_select_structure.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,4 +1363,27 @@ def test_lateral_join(self):
13631363
)
13641364
ast = parse_sql(query)
13651365
assert str(ast) == str(expected_ast)
1366-
assert ast.to_tree() == expected_ast.to_tree()
1366+
assert ast.to_tree() == expected_ast.to_tree()
1367+
1368+
def test_many_conditions(self):
1369+
sql = """
1370+
select * from kb where
1371+
(content like 'white' and size='small')
1372+
or (content = 'big')
1373+
"""
1374+
ast = parse_sql(sql)
1375+
expected_ast = Select(
1376+
targets=[Star()],
1377+
from_table=Identifier(parts=['kb']),
1378+
where=BinaryOperation(op='or', args=[
1379+
BinaryOperation(op='and', args=[
1380+
BinaryOperation(op='like', args=[Identifier('content'), Constant('white')]),
1381+
BinaryOperation(op='=', args=[Identifier('size'), Constant('small')]),
1382+
], parentheses=True),
1383+
BinaryOperation(op='=', args=[Identifier('content'), Constant('big')], parentheses=True),
1384+
]
1385+
)
1386+
)
1387+
assert ast.to_tree() == expected_ast.to_tree()
1388+
assert str(ast) == str(expected_ast)
1389+

0 commit comments

Comments
 (0)