@@ -107,6 +107,20 @@ def tear_down():
107
107
}
108
108
]
109
109
110
+ latest_attribute_definitions = [
111
+ {
112
+ 'AttributeName' : 'what_where_key' ,
113
+ 'AttributeType' : 'S'
114
+ }
115
+ ]
116
+
117
+ latest_key_schema = [
118
+ {
119
+ 'AttributeName' : 'what_where_key' ,
120
+ 'KeyType' : 'HASH'
121
+ }
122
+ ]
123
+
110
124
global_secondary = [{
111
125
'IndexName' : 'work-id-index' ,
112
126
'KeySchema' : [
@@ -140,55 +154,80 @@ def _delete_table(table):
140
154
raise e
141
155
142
156
143
- def _create_table (dynamodb , table_name ):
157
+ def _create_table (dynamodb ,
158
+ table_name ,
159
+ attribute_definitions ,
160
+ key_schema ,
161
+ global_secondary = None ):
144
162
table = dynamodb .Table (table_name )
145
163
_delete_table (table )
146
164
kwargs = dict (
147
165
TableName = table_name ,
148
166
AttributeDefinitions = attribute_definitions ,
149
167
KeySchema = key_schema ,
150
- GlobalSecondaryIndexes = global_secondary ,
151
168
ProvisionedThroughput = {
152
169
'ReadCapacityUnits' : 5 ,
153
170
'WriteCapacityUnits' : 5
154
171
}
155
172
)
173
+ if global_secondary :
174
+ kwargs ['GlobalSecondaryIndexes' ] = global_secondary
156
175
dynamodb .create_table (** kwargs )
157
176
return dynamodb .Table (table_name )
158
177
159
178
160
179
def _populate_table (table , records ):
180
+ print (f'attempting to populate { table } ' )
161
181
with table .batch_writer () as batch :
162
182
for r in records :
163
183
batch .put_item (Item = r )
164
184
165
-
185
+ # Adding latest table logic so latest table will be created and records will populate it
186
+ # Once that's possible, we will simply query the latest_table for what:where, no bucket logic
166
187
@pytest .fixture
167
188
def table_maker (request , dynamodb ):
168
189
169
- def maker (records ):
170
- table_name = 'test'
171
- table = _create_table (dynamodb , table_name )
172
- _populate_table (table , records )
190
+ def maker (records , include_latest_key = False ):
191
+ old_table_name = 'test'
192
+ latest_table_name = 'test_latest'
193
+ latest_table = None
194
+
195
+ old_table = _create_table (dynamodb , old_table_name , attribute_definitions , key_schema , global_secondary )
196
+ _populate_table (old_table , records )
197
+
198
+ if include_latest_key :
199
+ latest_table = _create_table (dynamodb , latest_table_name , latest_attribute_definitions , latest_key_schema )
200
+ _populate_table (latest_table , records )
173
201
174
202
def tear_down ():
175
- _delete_table (table )
203
+ _delete_table (old_table )
204
+ if include_latest_key :
205
+ _delete_table (latest_table )
206
+
176
207
request .addfinalizer (tear_down )
177
208
178
- return table
209
+ return old_table , latest_table
179
210
180
211
return maker
181
212
182
213
183
214
@pytest .fixture
184
215
def record_maker (s3_file_from_metadata ):
185
216
186
- def maker (** kwargs ):
217
+ def maker (include_latest_key = False , ** kwargs ):
187
218
m = generate_random_metadata ()
188
219
m .update (** kwargs )
189
220
key = '/' .join ([str (v ) for v in kwargs .values ()])
190
221
url = 's3://datalake-test/' + key
191
222
s3_file_from_metadata (url , m )
192
- return DatalakeRecord .list_from_metadata (url , m )
223
+ records = DatalakeRecord .list_from_metadata (url , m )
224
+
225
+ if include_latest_key :
226
+ what = kwargs .get ('what' )
227
+ where = kwargs .get ('where' )
228
+ for record in records :
229
+ record ['what_where_key' ] = f"{ what } :{ where } "
230
+
231
+ return records
193
232
194
233
return maker
0 commit comments