Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mindsdb_sql_parser/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MindsDBLexer(Lexer):
GROUP_BY, HAVING, ORDER_BY,
STAR, FOR, UPDATE,

JOIN, INNER, OUTER, CROSS, LEFT, RIGHT, ON,
JOIN, INNER, OUTER, CROSS, LEFT, RIGHT, ON, ASOF,

UNION, ALL, INTERSECT, EXCEPT,

Expand Down Expand Up @@ -234,6 +234,7 @@ class MindsDBLexer(Lexer):
CROSS = r'\bCROSS\b'
LEFT = r'\bLEFT\b'
RIGHT = r'\bRIGHT\b'
ASOF = r'\bASOF\b'

# UNION

Expand Down
3 changes: 3 additions & 0 deletions mindsdb_sql_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,9 @@ def from_table(self, p):
'OUTER JOIN',
'LEFT OUTER JOIN',
'FULL OUTER JOIN',
'ASOF JOIN',
'ASOF LEFT JOIN',
'LEFT ASOF JOIN',
)
def join_clause(self, p):
return ' '.join([x for x in p])
Expand Down
19 changes: 19 additions & 0 deletions tests/test_base_sql/test_select_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,3 +1236,22 @@ def test_mixed_join(self):
ast = parse_sql(query)
assert str(ast) == str(expected_ast)
assert ast.to_tree() == expected_ast.to_tree()

def test_asof_join(self):
for join_type in ('asof join', 'left asof join', 'asof left join'):
query = f'''
select * from table1 a
{join_type} table2 b on a.x = b.y
'''
expected_ast = Select(
targets=[Star()],
from_table=Join(
left=Identifier('table1', alias=Identifier('a')),
right=Identifier('table2', alias=Identifier('b')),
condition=BinaryOperation(op='=', args=[Identifier('a.x'), Identifier('b.y')]),
join_type=join_type,
)
)
ast = parse_sql(query)
assert str(ast) == str(expected_ast)
assert ast.to_tree() == expected_ast.to_tree()
Loading