Skip to content

Commit ac6d968

Browse files
committed
add operations: & | ^
1 parent d718ebf commit ac6d968

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

mindsdb_sql_parser/lexer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MindsDBLexer(Lexer):
7171
LBRACE, RBRACE, LBRACKET, RBRACKET, COLON, SEMICOLON,
7272

7373
# Operators
74-
PLUS, MINUS, MATCH, NOT_MATCH, DIVIDE, MODULO,
74+
PLUS, MINUS, MATCH, NOT_MATCH, DIVIDE, MODULO, BIT_AND, BIT_OR, BIT_XOR,
7575
ASSIGN_COLON, RIGHT_SHIFT, LEFT_SHIFT, EQUALS, NEQUALS, GREATER, GEQ, LESS, LEQ,
7676
AND, OR, NOT, IS, IS_NOT, TYPECAST,
7777
IN, NOT_IN, LIKE, NOT_LIKE, CONCAT, BETWEEN, WINDOW, OVER, PARTITION_BY,
@@ -296,6 +296,9 @@ class MindsDBLexer(Lexer):
296296
NOT_MATCH = r'!~'
297297
DIVIDE = r'/'
298298
MODULO = r'%'
299+
BIT_AND = r'&'
300+
BIT_OR = r'\|'
301+
BIT_XOR = r'\^'
299302
ASSIGN_COLON = r':='
300303
RIGHT_SHIFT = r'>>'
301304
LEFT_SHIFT = r'<<'

mindsdb_sql_parser/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class MindsDBParser(Parser):
5050
('nonassoc', LESS, LEQ, GREATER, GEQ, IN, NOT_IN, BETWEEN, IS, IS_NOT, NOT_LIKE, LIKE, RIGHT_SHIFT, LEFT_SHIFT),
5151
('left', JSON_GET),
5252
('left', PLUS, MINUS),
53+
('left', BIT_AND, BIT_XOR, BIT_OR),
5354
('left', STAR, DIVIDE, TYPECAST, MODULO),
5455
('right', UMINUS), # Unary minus operator, unary not
5556

@@ -1631,6 +1632,9 @@ def star(self, p):
16311632
'expr STAR expr',
16321633
'expr DIVIDE expr',
16331634
'expr MODULO expr',
1635+
'expr BIT_AND expr',
1636+
'expr BIT_XOR expr',
1637+
'expr BIT_OR expr',
16341638
'expr ASSIGN_COLON expr',
16351639
'expr EQUALS expr',
16361640
'expr NEQUALS expr',

tests/test_base_sql/test_base_lexer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ def test_binary_ops(self):
122122
('<=', 'LEQ'),
123123
('>>', 'RIGHT_SHIFT'),
124124
('<<', 'LEFT_SHIFT'),
125+
(':=', 'ASSIGN_COLON'),
126+
('&', 'BIT_AND'),
127+
('|', 'BIT_OR'),
128+
('^', 'BIT_XOR'),
125129
('AND', 'AND'),
126130
('OR', 'OR'),
127131
('IS', 'IS'),

tests/test_base_sql/test_select_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class TestOperations:
88
def test_select_binary_operations(self):
99
for op in ['+', '-', '/', '*', '%', '=', '!=', '>', '<', '>=', '<=', '>>', '<<',
10-
'is', 'IS NOT', 'like', 'in', 'and', 'or', '||']:
10+
'is', 'IS NOT', 'like', 'in', 'and', 'or', '||', '&', '|', '^']:
1111
sql = f'SELECT column1 {op.upper()} column2 FROM tab'
1212
ast = parse_sql(sql)
1313

0 commit comments

Comments
 (0)