Skip to content

Commit b22d716

Browse files
committed
BUG: Fix bug where you couldn't multiply or perform math operations on the right side of a column
1 parent 6f49e9f commit b22d716

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

dataframe_sql/grammar/sql.grammar

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ order: expression_math ["ASC"i] -> order_asc
5656
column_name: [NAME "."] NAME
5757
?expression_product: expression
5858
| expression_product "*" expression -> expression_mul
59+
| expression "*" expression -> expression_mul
5960
| expression_product "/" expression -> expression_div
6061

6162
?expression: [NAME "."] (NAME | STAR) -> column_name
@@ -104,12 +105,8 @@ not_in_expr: expression_math "NOT"i "IN"i "(" [expression_math ","] expression_m
104105
boolean: "true"i -> true
105106
| "false"i -> false
106107
?number_expr: product
107-
| number_expr "+" product -> add
108-
| number_expr "-" product -> sub
109108

110109
?product: NUMBER
111-
| product "*" NUMBER -> mul
112-
| product "/" NUMBER -> div
113110

114111
integer: /[1-9][0-9]*/
115112
STAR: "*"

dataframe_sql/sql_select_query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def __init__(self, sql: str, show_exececution_plan: bool = False):
123123
def parse_sql(self):
124124
try:
125125
tree = self.parser.parse(self.sql)
126+
print(tree.pretty())
126127

127128
table_info = TableInfo()
128129

dataframe_sql/tests/pandas_sql_functionality_test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,20 @@ def test_sql_data_types():
13941394
tm.assert_frame_equal(pandas_frame, my_frame)
13951395

13961396

1397+
def test_math_parentheses():
1398+
"""
1399+
Test math parentheses
1400+
:return:
1401+
"""
1402+
1403+
my_frame = query("select 20 * avocado_id from avocado")
1404+
1405+
print(my_frame)
1406+
1407+
13971408
if __name__ == "__main__":
13981409
register_env_tables()
13991410

1400-
test_sql_data_types()
1411+
test_right_left_math()
14011412

14021413
remove_env_tables()

0 commit comments

Comments
 (0)