diff --git a/mindsdb_sql/parser/dialects/mindsdb/parser.py b/mindsdb_sql/parser/dialects/mindsdb/parser.py index 70e764af..14cdd817 100644 --- a/mindsdb_sql/parser/dialects/mindsdb/parser.py +++ b/mindsdb_sql/parser/dialects/mindsdb/parser.py @@ -1314,6 +1314,10 @@ def expr(self, p): def expr(self, p): return UnaryOperation(op=p[0], args=(p.expr,)) + @_('MINUS constant %prec UMINUS') + def constant(self, p): + return Constant(-p.constant.value) + # update fields list @_('update_parameter', 'update_parameter_list COMMA update_parameter') diff --git a/mindsdb_sql/planner/utils.py b/mindsdb_sql/planner/utils.py index 37788335..637219b0 100644 --- a/mindsdb_sql/planner/utils.py +++ b/mindsdb_sql/planner/utils.py @@ -44,12 +44,12 @@ def recursively_extract_column_values(op, row_dict, predictor): id = op.args[0] value = op.args[1] - if ( - isinstance(value, UnaryOperation) - and value.op == '-' - and isinstance(value.args[0], Constant) - ): - value = Constant(-value.args[0].value) + # if ( + # isinstance(value, UnaryOperation) + # and value.op == '-' + # and isinstance(value.args[0], Constant) + # ): + # value = Constant(-value.args[0].value) if not ( isinstance(id, Identifier) diff --git a/tests/test_parser/test_mindsdb/test_selects.py b/tests/test_parser/test_mindsdb/test_selects.py index b0d98042..a55e858a 100644 --- a/tests/test_parser/test_mindsdb/test_selects.py +++ b/tests/test_parser/test_mindsdb/test_selects.py @@ -109,3 +109,15 @@ def test_join_using(self): assert str(ast) == str(expected_ast) assert ast.to_tree() == expected_ast.to_tree() + + def test_select_limit_negative(self): + sql = """SELECT * FROM t1 LIMIT -1""" + + ast = parse_sql(sql, dialect='mindsdb') + expected_ast = Select(targets=[Star()], + from_table=Identifier(parts=['t1']), + limit=Constant(-1)) + + assert ast.to_tree() == expected_ast.to_tree() + assert str(ast) == str(expected_ast) +