Skip to content

Commit 005cbfd

Browse files
authored
Merge pull request #5 from mindsdb/asof-join
Asof join support
2 parents 2e7e24a + 958d0d4 commit 005cbfd

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

mindsdb_sql_parser/lexer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class MindsDBLexer(Lexer):
5353
GROUP_BY, HAVING, ORDER_BY,
5454
STAR, FOR, UPDATE,
5555

56-
JOIN, INNER, OUTER, CROSS, LEFT, RIGHT, ON,
56+
JOIN, INNER, OUTER, CROSS, LEFT, RIGHT, ON, ASOF,
5757

5858
UNION, ALL, INTERSECT, EXCEPT,
5959

@@ -234,6 +234,7 @@ class MindsDBLexer(Lexer):
234234
CROSS = r'\bCROSS\b'
235235
LEFT = r'\bLEFT\b'
236236
RIGHT = r'\bRIGHT\b'
237+
ASOF = r'\bASOF\b'
237238

238239
# UNION
239240

mindsdb_sql_parser/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ def from_table(self, p):
12831283
'OUTER JOIN',
12841284
'LEFT OUTER JOIN',
12851285
'FULL OUTER JOIN',
1286+
'ASOF JOIN',
1287+
'ASOF LEFT JOIN',
1288+
'LEFT ASOF JOIN',
12861289
)
12871290
def join_clause(self, p):
12881291
return ' '.join([x for x in p])

tests/test_base_sql/test_select_structure.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,22 @@ def test_mixed_join(self):
12361236
ast = parse_sql(query)
12371237
assert str(ast) == str(expected_ast)
12381238
assert ast.to_tree() == expected_ast.to_tree()
1239+
1240+
def test_asof_join(self):
1241+
for join_type in ('asof join', 'left asof join', 'asof left join'):
1242+
query = f'''
1243+
select * from table1 a
1244+
{join_type} table2 b on a.x = b.y
1245+
'''
1246+
expected_ast = Select(
1247+
targets=[Star()],
1248+
from_table=Join(
1249+
left=Identifier('table1', alias=Identifier('a')),
1250+
right=Identifier('table2', alias=Identifier('b')),
1251+
condition=BinaryOperation(op='=', args=[Identifier('a.x'), Identifier('b.y')]),
1252+
join_type=join_type,
1253+
)
1254+
)
1255+
ast = parse_sql(query)
1256+
assert str(ast) == str(expected_ast)
1257+
assert ast.to_tree() == expected_ast.to_tree()

0 commit comments

Comments
 (0)