Skip to content

Commit 00c77cd

Browse files
m
1 parent 0892864 commit 00c77cd

File tree

1 file changed

+10
-48
lines changed
  • Examples/runtimes/python/DynamoDBEncryption/src/searchable_encryption/complex_example/table

1 file changed

+10
-48
lines changed

Examples/runtimes/python/DynamoDBEncryption/src/searchable_encryption/complex_example/table/query_requests.py

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import boto3
21
from boto3.dynamodb.conditions import Key, Attr
32

43
def run_queries(table):
@@ -29,14 +28,12 @@ def run_queries(table):
2928
def run_query_1(table):
3029
"""
3130
Query 1: Get meetings by date and email
32-
- Key condition: PK1 = email AND SK1 BETWEEN date1 AND date2
33-
- Filter condition: Duration > 0
31+
Key condition: PK1 = email AND SK1 BETWEEN date1 AND date2
32+
Filter condition: Duration > 0
3433
"""
35-
# Define query conditions using boto3 Key() and Attr()
3634
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").between("MS-2022-07-02", "MS-2022-07-08")
3735
filter_condition = Attr("Duration").gt("0")
3836

39-
# Execute query
4037
response = table.query(
4138
IndexName="GSI-1",
4239
KeyConditionExpression=key_condition,
@@ -67,11 +64,9 @@ def run_query_2(table):
6764
Key condition: PK=employeeID SK between(date1, date2)
6865
Filter condition: duration > 0
6966
"""
70-
# Define query conditions using boto3 Key() and Attr()
7167
key_condition = Key("PK").eq("E-emp_001") & Key("SK").between("MS-2022-07-02", "MS-2022-07-08")
7268
filter_condition = Attr("Duration").gt("0")
7369

74-
# Execute query
7570
response = table.query(
7671
IndexName="GSI-0",
7772
KeyConditionExpression=key_condition,
@@ -95,6 +90,7 @@ def run_query_2(table):
9590

9691
assert found_known_value_item
9792

93+
9894
def run_query_3(table):
9995
"""
10096
Query 3: Get meetings by date and building/floor/room
@@ -105,12 +101,11 @@ def run_query_3(table):
105101
However, one cannot use primary keys (partition nor sort) in a filter expression.
106102
Instead, this query filters on the individual beacon attributes: building, floor, and room.
107103
"""
108-
# Define query conditions using boto3 Key() and Attr()
109104
key_condition = Key("PK").eq("B-SEA33") & Key("SK").between("MS-2022-07-02", "MS-2022-07-08")
110105
filter_condition = (Attr("Building").eq("SEA33") &
111106
Attr("Floor").eq("12") &
112107
Attr("Room").eq("403"))
113-
# Execute query
108+
114109
response = table.query(
115110
IndexName="GSI-0",
116111
KeyConditionExpression=key_condition,
@@ -132,15 +127,14 @@ def run_query_3(table):
132127

133128
assert found_known_value_item
134129

130+
135131
def run_query_4(table):
136132
"""
137133
Query 4: Get employee data by email
138134
Key condition: PK1=email SK1=employee ID
139135
"""
140-
# Define query conditions using boto3 Key()
141136
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").eq("E-emp_001")
142137

143-
# Execute query
144138
response = table.query(
145139
IndexName="GSI-1",
146140
KeyConditionExpression=key_condition
@@ -162,15 +156,14 @@ def run_query_4(table):
162156

163157
assert found_known_value_item
164158

159+
165160
def run_query_5(table):
166161
"""
167162
Query 5: Get meetings by email
168163
Key condition: PK1=email SK1 > 30 days ago
169164
"""
170-
# Define query conditions using boto3 Key()
171165
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").between("MS-", "MS-2023-03-20")
172166

173-
# Execute query
174167
response = table.query(
175168
IndexName="GSI-1",
176169
KeyConditionExpression=key_condition
@@ -193,15 +186,14 @@ def run_query_5(table):
193186

194187
assert found_known_value_item
195188

189+
196190
def run_query_6(table):
197191
"""
198192
Query 6: Get tickets by email
199193
Key condition: PK1=email SK1 > 30 days ago
200194
"""
201-
# Define query conditions using boto3 Key()
202195
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").lt("MS-2023-03-20")
203196

204-
# Execute query
205197
response = table.query(
206198
IndexName="GSI-1",
207199
KeyConditionExpression=key_condition
@@ -223,15 +215,14 @@ def run_query_6(table):
223215

224216
assert found_known_value_item
225217

218+
226219
def run_query_7(table):
227220
"""
228221
Query 7: Get reservations by email
229222
Key condition: PK1=organizeremail SK1 > 30 days ago
230223
"""
231-
# Define query conditions using boto3 Key()
232224
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").lt("MS-2023-03-20")
233225

234-
# Execute query
235226
response = table.query(
236227
IndexName="GSI-1",
237228
KeyConditionExpression=key_condition
@@ -260,10 +251,8 @@ def run_query_8(table):
260251
Query 8: Get time cards by email
261252
Key condition: PK1=employeeemail SK1 > 30 days ago
262253
"""
263-
# Define query conditions using boto3 Key()
264254
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").between("TC-", "TC-2023-03-20")
265255

266-
# Execute query
267256
response = table.query(
268257
IndexName="GSI-1",
269258
KeyConditionExpression=key_condition
@@ -290,10 +279,8 @@ def run_query_9(table):
290279
Query 9: Get employee info by employee ID
291280
Key condition: PK1=employeeID SK starts with "E-"
292281
"""
293-
# Define query conditions using boto3 Key()
294282
key_condition = Key("PK").eq("E-emp_001") & Key("SK").begins_with("E-")
295283

296-
# Execute query
297284
response = table.query(
298285
IndexName="GSI-0",
299286
KeyConditionExpression=key_condition
@@ -314,16 +301,15 @@ def run_query_9(table):
314301

315302
assert found_known_value_item
316303

304+
317305
def run_query_10(table):
318306
"""
319307
Query 10: Get employee info by email
320308
Key condition: PK1=email
321309
Filter condition: SK starts with "E-"
322310
"""
323-
# Define query conditions using boto3 Key()
324311
key_condition = Key("PK1").eq("[email protected]") & Key("SK1").begins_with("E-")
325312

326-
# Execute query
327313
response = table.query(
328314
IndexName="GSI-1",
329315
KeyConditionExpression=key_condition
@@ -350,10 +336,8 @@ def run_query_11(table):
350336
Query 11: Get ticket history by ticket number
351337
Key condition: PK=TicketNumber
352338
"""
353-
# Define query conditions using boto3 Key()
354339
key_condition = Key("PK").eq("T-ticket_001")
355340

356-
# Execute query
357341
response = table.query(
358342
IndexName="GSI-0",
359343
KeyConditionExpression=key_condition
@@ -382,11 +366,9 @@ def run_query_12(table):
382366
Key condition: PK1=CreatorEmail
383367
Filter condition: PK=TicketNumber
384368
"""
385-
# Define query conditions using boto3 Key() and Attr()
386369
key_condition = Key("PK1").eq("[email protected]")
387370
filter_condition = Attr("PK").eq("T-ticket_001")
388371

389-
# Execute query
390372
response = table.query(
391373
IndexName="GSI-1",
392374
KeyConditionExpression=key_condition,
@@ -415,11 +397,9 @@ def run_query_13(table):
415397
Key condition: PK=AssigneeEmail
416398
Filter condition: PK=ticketNumber
417399
"""
418-
# Define query conditions using boto3 Key() and Attr()
419400
key_condition = Key("PK2").eq("[email protected]")
420401
filter_condition = Attr("PK").eq("T-ticket_001")
421402

422-
# Execute query
423403
response = table.query(
424404
IndexName="GSI-2",
425405
KeyConditionExpression=key_condition,
@@ -447,7 +427,6 @@ def run_query_14(table):
447427
Query 14: Get employees by city.building.floor.desk
448428
Key condition: PK3=city SK3 begins_with(building.floor.desk)
449429
"""
450-
# Define query conditions using boto3 Key()
451430
key_condition = Key("PK3").eq("C-Seattle") & Key("SK3").begins_with("B-44~F-12~D-3")
452431

453432
# Execute query with retries since GSIs don't update instantly
@@ -483,15 +462,14 @@ def run_query_14(table):
483462
# Assert the value was found inside the loop
484463
assert found_known_value_item
485464

465+
486466
def run_query_15(table):
487467
"""
488468
Query 15: Get employees by manager email
489469
Key condition: PK2 = ManagerEmail
490470
"""
491-
# Define query conditions using boto3 Key()
492471
key_condition = Key("PK2").eq("[email protected]")
493472

494-
# Execute query
495473
response = table.query(
496474
IndexName="GSI-2",
497475
KeyConditionExpression=key_condition
@@ -520,10 +498,8 @@ def run_query_16(table):
520498
Query 16: Get assigned tickets by assignee email
521499
Key condition: PK2 = AssigneeEmail
522500
"""
523-
# Define query conditions using boto3 Key()
524501
key_condition = Key("PK2").eq("[email protected]")
525502

526-
# Execute query
527503
response = table.query(
528504
IndexName="GSI-2",
529505
KeyConditionExpression=key_condition
@@ -555,10 +531,8 @@ def run_query_17(table):
555531
is 2022-10-07T09:30:00, and that our sample ticket record
556532
with TicketModTime=2022-10-07T14:32:25 will be returned.)
557533
"""
558-
# Define query conditions using boto3 Key()
559534
key_condition = Key("PK3").eq("S-3") & Key("SK3").gt("M-2022-10-07T09:30:00")
560535

561-
# Execute query
562536
response = table.query(
563537
IndexName="GSI-3",
564538
KeyConditionExpression=key_condition
@@ -587,11 +561,9 @@ def run_query_18(table):
587561
Key condition: PK1 = Status, SK1 > StartDate
588562
Filter condition: TargetDelivery < TargetDate
589563
"""
590-
# Define query conditions using boto3 Key() and Attr()
591564
key_condition = Key("PK1").eq("PSts-Pending") & Key("SK1").gt("PS-2022-01-01")
592565
filter_condition = Attr("ProjectTarget").lt("2025-01-01")
593566

594-
# Execute query
595567
response = table.query(
596568
IndexName="GSI-1",
597569
KeyConditionExpression=key_condition,
@@ -619,10 +591,8 @@ def run_query_19(table):
619591
Query 19: Get projects by name
620592
Key condition: PK = ProjectName, SK = ProjectName
621593
"""
622-
# Define query conditions using boto3 Key()
623594
key_condition = Key("PK").eq("P-project_001") & Key("SK").eq("P-project_001")
624595

625-
# Execute query
626596
response = table.query(
627597
IndexName="GSI-0",
628598
KeyConditionExpression=key_condition
@@ -649,10 +619,8 @@ def run_query_20(table):
649619
Query 20: Get Project History by date range (against timecard record)
650620
Key condition: PK = ProjectName, SK between(date1, date2)
651621
"""
652-
# Define query conditions using boto3 Key()
653622
key_condition = Key("PK").eq("P-project_002") & Key("SK").between("TC-2022-01-01", "TC-2023-01-01")
654623

655-
# Execute query
656624
response = table.query(
657625
IndexName="GSI-0",
658626
KeyConditionExpression=key_condition
@@ -681,11 +649,9 @@ def run_query_21(table):
681649
Key condition: PK = ProjectName
682650
Filter condition: role=rolename
683651
"""
684-
# Define query conditions using boto3 Key() and Attr()
685652
key_condition = Key("PK").eq("P-project_002")
686653
filter_condition = Attr("Role").eq("SDE3")
687654

688-
# Execute query
689655
response = table.query(
690656
IndexName="GSI-0",
691657
KeyConditionExpression=key_condition,
@@ -713,10 +679,8 @@ def run_query_22(table):
713679
Query 22: Get reservations by building ID
714680
Key condition: PK = Building ID
715681
"""
716-
# Define query conditions using boto3 Key()
717682
key_condition = Key("PK").eq("B-SEA33")
718683

719-
# Execute query
720684
response = table.query(
721685
IndexName="GSI-0",
722686
KeyConditionExpression=key_condition
@@ -745,11 +709,9 @@ def run_query_23(table):
745709
Key condition: PK = Building ID, SK between(date1, date2)
746710
Filter condition: Duration > 0
747711
"""
748-
# Define query conditions using boto3 Key() and Attr()
749712
key_condition = Key("PK").eq("B-SEA33") & Key("SK").between("MS-2022-07-01", "MS-2022-07-08")
750713
filter_condition = Attr("Duration").gt("0")
751714

752-
# Execute query
753715
response = table.query(
754716
IndexName="GSI-0",
755717
KeyConditionExpression=key_condition,

0 commit comments

Comments
 (0)