Skip to content

Commit

Permalink
Update optimization examples and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
snower committed Jan 19, 2024
1 parent b1c38a8 commit 6ca6055
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/logic_operation/data/orders.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
{
"order_id": 4,
"uid": 1,
"uid": 3,
"goods_id": 1,
"amount": 8,
"status": 0
Expand All @@ -36,7 +36,7 @@
},
{
"order_id": 6,
"uid": 2,
"uid": 4,
"goods_id": 2,
"amount": 7,
"status": 0
Expand Down
6 changes: 5 additions & 1 deletion examples/logic_operation/logic_operation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ select 'a' not in ('a', 'b', 'c') as a, 1 not in ('a', 'b', 'c') as b, 1 not in

select if(amount > 0 and status=0, 1, 0) as a, case when amount <= 0 then 'A' when amount > 0 and amount < 1 then 'B' when amount between 1 and 10 'C' else 'D' end as b from `data/orders.json` where uid=1;

select sum(amount) as a, if(sum(amount) > 0, 1, 0) as b, case when sum(amount) <= 0 then 'A' when sum(amount) > 0 and sum(amount) < 1 then 'B' when sum(amount) between 1 and 100 'C' else 'D' end as c from `data/orders.json`;
select sum(amount) as a, if(sum(amount) > 0, 1, 0) as b, case when sum(amount) <= 0 then 'A' when sum(amount) > 0 and sum(amount) < 1 then 'B' when sum(amount) between 1 and 100 'C' else 'D' end as c from `data/orders.json`;

select order_id, uid, goods_id, amount from `data/orders.json` where uid != 3 and uid != 4 and uid > 0 and uid < 10 order by order_id desc limit 2, 1;

select * from `data/orders.json` where uid != 3 and uid != 4 and uid > 0 and uid < 10 and status=0 order by order_id desc limit 1 offset 2;
4 changes: 2 additions & 2 deletions syncanysql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def build_query_condition(condition_column, condition_exp, condition_calculater)
if condition_column["typing_name"] not in config["querys"]:
config["querys"][condition_column["typing_name"]] = {}
condition_querys = config["querys"][condition_column["typing_name"]]
if (condition_querys, dict):
if isinstance(condition_querys, dict):
if condition_exp not in condition_querys:
condition_querys[condition_exp] = condition_calculater
return None
Expand Down Expand Up @@ -2025,7 +2025,7 @@ def build_query_condition(condition_column, condition_exp, condition_calculater)
if condition_column["typing_name"] not in join_table["querys"]:
join_table["querys"][condition_column["typing_name"]] = {}
condition_querys = join_table["querys"][condition_column["typing_name"]]
if (condition_querys, dict):
if isinstance(condition_querys, dict):
if condition_exp not in condition_querys:
condition_querys[condition_exp] = condition_calculater
return None
Expand Down
8 changes: 6 additions & 2 deletions tests/test_example_logic_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def test_logic_operation(self):

self.assert_data(18, [{'a': 0, 'b': 1, 'c': 0, 'd': 1}], "data error")

self.assert_data(20, [{'a': 1, 'b': 'B'}, {'a': 1, 'b': 'C'}], "data error")
self.assert_data(20, [{'a': 1, 'b': 'B'}], "data error")

self.assert_data(22, [{'a': 36.2, 'b': 1, 'c': 'C'}], "data error")
self.assert_data(22, [{'a': 36.2, 'b': 1, 'c': 'C'}], "data error")

self.assert_data(24, [{'order_id': 2, 'uid': 1, 'goods_id': 1, 'amount': 0.6}], "data error")

self.assert_data(26, [{'order_id': 2, 'uid': 1, 'goods_id': 1, 'amount': 0.6, 'status': 0}], "data error")

0 comments on commit 6ca6055

Please sign in to comment.