Skip to content

Commit b1cc735

Browse files
committed
Nested conditions 👯‍♀️
1 parent b7e0d67 commit b1cc735

File tree

9 files changed

+438
-321
lines changed

9 files changed

+438
-321
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.9.0 : 2021-06-25
4+
5+
- **Fix**: Fixed nested conditions (`Operator` can contain another `Operator`)
6+
- **Change**: Dropped Python 3.6 support
7+
38
## 0.8.2 : 2020-10-15
49

510
- **Fix**: Use `->` instead of `-->`

duckql/cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import click
22

3-
from .structures import Query
3+
from .structures import Query, Operator
44

55

66
@click.group()
@@ -10,12 +10,16 @@ def cli():
1010

1111
@cli.command()
1212
def schema():
13+
Query.update_forward_refs()
14+
Operator.update_forward_refs()
1315
print(Query.schema_json(indent=2))
1416

1517

1618
@cli.command()
1719
@click.argument('filename')
1820
def file(filename):
21+
Query.update_forward_refs()
22+
Operator.update_forward_refs()
1923
my_query = Query.parse_file(filename)
2024
print(my_query)
2125

duckql/structures/operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __str__(self):
4242

4343
obj: Literal['structures.Operator'] = 'structures.Operator'
4444
operation: Operation
45-
properties: List[Union[BaseFunction, Constant, Property, Boolean, Comparision, Interval]]
45+
properties: List[Union[BaseFunction, Constant, Property, Boolean, Comparision, Interval, "Operator"]]
4646
alias: str = None
4747

4848
def to_sql(self) -> str:

duckql/structures/tests/test_query.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
def test_simple():
9+
Query.update_forward_refs()
910
my_query = Query(
1011
entity='users',
1112
properties=[
@@ -104,6 +105,7 @@ def test_simple():
104105

105106

106107
def test_subquery():
108+
Query.update_forward_refs()
107109
my_subquery = Query(
108110
entity='users',
109111
properties=[
@@ -163,6 +165,8 @@ def test_short_example():
163165

164166

165167
def test_example():
168+
Query.update_forward_refs()
169+
Operator.update_forward_refs()
166170
my_query = Query(
167171
entity='users',
168172
properties=[
@@ -218,6 +222,7 @@ def test_example():
218222

219223

220224
def test_having():
225+
Query.update_forward_refs()
221226
my_query = Query(
222227
entity='organisations',
223228
properties=[
@@ -279,6 +284,7 @@ def test_having():
279284

280285

281286
def test_group_by_json():
287+
Query.update_forward_refs()
282288
my_query = Query(
283289
entity='signatories',
284290
properties=[

duckql/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.8.2'
1+
__version__ = '0.9.0'

examples/nested_conditions.json

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
{
2+
"obj": "structures.Query",
3+
"entity": "donations",
4+
"properties": [
5+
{
6+
"obj": "properties.Property",
7+
"name": "donations.periodicity",
8+
"alias": "donations__periodicity"
9+
},
10+
{
11+
"obj": "properties.Property",
12+
"name": "donations.id",
13+
"alias": "donations__id"
14+
},
15+
{
16+
"obj": "properties.Property",
17+
"name": "campaigns__organisations__fk.id",
18+
"alias": "organisations__id"
19+
},
20+
{
21+
"obj": "properties.Property",
22+
"name": "campaigns__organisations__fk.name",
23+
"alias": "organisations__name"
24+
},
25+
{
26+
"obj": "properties.Property",
27+
"name": "donations__campaigns__fk.note",
28+
"alias": "campaigns__note"
29+
},
30+
{
31+
"obj": "properties.Property",
32+
"name": "donations__donors__fk.name",
33+
"alias": "donors__name"
34+
},
35+
{
36+
"obj": "properties.Property",
37+
"name": "donations__donors__fk.surname",
38+
"alias": "donors__surname"
39+
},
40+
{
41+
"obj": "properties.Property",
42+
"name": "donations__payments__fk.value",
43+
"alias": "payments__value"
44+
},
45+
{
46+
"obj": "properties.Property",
47+
"name": "donations__payments__fk.happened_at",
48+
"alias": "payments__happened_at"
49+
},
50+
{
51+
"obj": "properties.Property",
52+
"name": "donations__payments__fk.status",
53+
"alias": "payments__status"
54+
},
55+
{
56+
"obj": "properties.Property",
57+
"name": "donations__payments__fk.variable_symbol",
58+
"alias": "payments__variable_symbol"
59+
}
60+
],
61+
"conditions": {
62+
"obj": "structures.Operator",
63+
"operation": "and",
64+
"properties": [
65+
{
66+
"obj": "structures.Operator",
67+
"operation": "or",
68+
"properties": [
69+
{
70+
"obj": "structures.Comparision",
71+
"properties": [
72+
{
73+
"obj": "properties.Property",
74+
"name": "donations__payments__fk.status"
75+
},
76+
{
77+
"obj": "properties.Array",
78+
"values": [
79+
{
80+
"obj": "properties.Constant",
81+
"value": "successful"
82+
}
83+
]
84+
}
85+
],
86+
"operation": "in"
87+
},
88+
{
89+
"obj": "structures.Comparision",
90+
"properties": [
91+
{
92+
"obj": "properties.Property",
93+
"name": "donations__payments__fk.status"
94+
},
95+
{
96+
"obj": "properties.Array",
97+
"values": [
98+
{
99+
"obj": "properties.Constant",
100+
"value": "fail"
101+
}
102+
]
103+
}
104+
],
105+
"operation": "in"
106+
}
107+
]
108+
},
109+
{
110+
"obj": "structures.Comparision",
111+
"properties": [
112+
{
113+
"obj": "properties.Property",
114+
"name": "donations__payments__fk.value"
115+
},
116+
{
117+
"obj": "properties.Constant",
118+
"value": 100
119+
}
120+
],
121+
"operation": "gt"
122+
}
123+
]
124+
},
125+
"order": [
126+
{
127+
"obj": "structures.Order",
128+
"property": {
129+
"obj": "properties.Property",
130+
"name": "payments__status"
131+
},
132+
"kind": "ASC"
133+
}
134+
],
135+
"limit": {
136+
"obj": "structures.Limit",
137+
"limit": 10,
138+
"offset": 0
139+
},
140+
"joins": [
141+
{
142+
"obj": "structures.Join",
143+
"entity": "donors",
144+
"type": "left",
145+
"on": {
146+
"obj": "structures.Comparision",
147+
"properties": [
148+
{
149+
"obj": "properties.Property",
150+
"name": "donations__donors__fk.id"
151+
},
152+
{
153+
"obj": "properties.Property",
154+
"name": "donations.donor_id"
155+
}
156+
],
157+
"operation": "eq"
158+
},
159+
"alias": "donations__donors__fk"
160+
},
161+
{
162+
"obj": "structures.Join",
163+
"entity": "campaigns",
164+
"type": "left",
165+
"on": {
166+
"obj": "structures.Comparision",
167+
"properties": [
168+
{
169+
"obj": "properties.Property",
170+
"name": "donations__campaigns__fk.id"
171+
},
172+
{
173+
"obj": "properties.Property",
174+
"name": "donations.campaign_id"
175+
}
176+
],
177+
"operation": "eq"
178+
},
179+
"alias": "donations__campaigns__fk"
180+
},
181+
{
182+
"obj": "structures.Join",
183+
"entity": "payments",
184+
"type": "right",
185+
"on": {
186+
"obj": "structures.Comparision",
187+
"properties": [
188+
{
189+
"obj": "properties.Property",
190+
"name": "donations.id"
191+
},
192+
{
193+
"obj": "properties.Property",
194+
"name": "donations__payments__fk.donation_id"
195+
}
196+
],
197+
"operation": "eq"
198+
},
199+
"alias": "donations__payments__fk"
200+
},
201+
{
202+
"obj": "structures.Join",
203+
"entity": "organisations",
204+
"type": "left",
205+
"on": {
206+
"obj": "structures.Comparision",
207+
"properties": [
208+
{
209+
"obj": "properties.Property",
210+
"name": "campaigns__organisations__fk.id"
211+
},
212+
{
213+
"obj": "properties.Property",
214+
"name": "donations__campaigns__fk.organisation_id"
215+
}
216+
],
217+
"operation": "eq"
218+
},
219+
"alias": "campaigns__organisations__fk"
220+
}
221+
]
222+
}

0 commit comments

Comments
 (0)