Skip to content

Commit 9f35706

Browse files
terryyylimwoop
andauthored
Add native types for Python SDK online retrieval (#826)
* Add native types for get_online_features * Address PR comments * Address PR comments * Fix lint * Fix test order * Address PR comments * Address PR comments * Address PR comments * Update docs and example notebooks * Update docs * Fix lint * Address PR comments * Add bugfix * Update wrong import * Move warning into condition check * Params reformatting * Refactor type inference in online retriever * Fix typo in variable name Co-authored-by: Willem Pienaar <git@willem.co>
1 parent 0f5bd69 commit 9f35706

File tree

7 files changed

+762
-262
lines changed

7 files changed

+762
-262
lines changed

examples/basic/basic.ipynb

Lines changed: 115 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -148,48 +148,48 @@
148148
"output_type": "stream",
149149
"text": [
150150
" datetime customer_id daily_transactions \\\n",
151-
"0 2020-06-09 00:00:00+00:00 1001 0.564751 \n",
152-
"1 2020-06-09 00:00:00+00:00 1002 3.945566 \n",
153-
"2 2020-06-09 00:00:00+00:00 1003 7.291928 \n",
154-
"3 2020-06-09 00:00:00+00:00 1004 6.690477 \n",
155-
"4 2020-06-09 00:00:00+00:00 1005 6.415899 \n",
156-
"5 2020-06-10 00:00:00+00:00 1001 0.347294 \n",
157-
"6 2020-06-10 00:00:00+00:00 1002 5.363853 \n",
158-
"7 2020-06-10 00:00:00+00:00 1003 0.538129 \n",
159-
"8 2020-06-10 00:00:00+00:00 1004 4.755425 \n",
160-
"9 2020-06-10 00:00:00+00:00 1005 2.867527 \n",
161-
"10 2020-06-11 00:00:00+00:00 1001 9.493098 \n",
162-
"11 2020-06-11 00:00:00+00:00 1002 5.130665 \n",
163-
"12 2020-06-11 00:00:00+00:00 1003 1.794191 \n",
164-
"13 2020-06-11 00:00:00+00:00 1004 4.698504 \n",
165-
"14 2020-06-11 00:00:00+00:00 1005 2.908603 \n",
166-
"15 2020-06-12 00:00:00+00:00 1001 9.857894 \n",
167-
"16 2020-06-12 00:00:00+00:00 1002 5.416553 \n",
168-
"17 2020-06-12 00:00:00+00:00 1003 5.374058 \n",
169-
"18 2020-06-12 00:00:00+00:00 1004 9.834441 \n",
170-
"19 2020-06-12 00:00:00+00:00 1005 0.480373 \n",
151+
"0 2020-06-17 00:00:00+00:00 1001 4.900417 \n",
152+
"1 2020-06-17 00:00:00+00:00 1002 7.440329 \n",
153+
"2 2020-06-17 00:00:00+00:00 1003 4.224760 \n",
154+
"3 2020-06-17 00:00:00+00:00 1004 5.482722 \n",
155+
"4 2020-06-17 00:00:00+00:00 1005 2.200896 \n",
156+
"5 2020-06-18 00:00:00+00:00 1001 8.173628 \n",
157+
"6 2020-06-18 00:00:00+00:00 1002 3.164327 \n",
158+
"7 2020-06-18 00:00:00+00:00 1003 7.248387 \n",
159+
"8 2020-06-18 00:00:00+00:00 1004 9.274397 \n",
160+
"9 2020-06-18 00:00:00+00:00 1005 7.846449 \n",
161+
"10 2020-06-19 00:00:00+00:00 1001 9.028874 \n",
162+
"11 2020-06-19 00:00:00+00:00 1002 5.140390 \n",
163+
"12 2020-06-19 00:00:00+00:00 1003 4.537877 \n",
164+
"13 2020-06-19 00:00:00+00:00 1004 6.797491 \n",
165+
"14 2020-06-19 00:00:00+00:00 1005 8.234574 \n",
166+
"15 2020-06-20 00:00:00+00:00 1001 8.319164 \n",
167+
"16 2020-06-20 00:00:00+00:00 1002 7.158817 \n",
168+
"17 2020-06-20 00:00:00+00:00 1003 4.920308 \n",
169+
"18 2020-06-20 00:00:00+00:00 1004 7.974404 \n",
170+
"19 2020-06-20 00:00:00+00:00 1005 2.298012 \n",
171171
"\n",
172172
" total_transactions \n",
173-
"0 73 \n",
174-
"1 75 \n",
175-
"2 95 \n",
176-
"3 50 \n",
177-
"4 65 \n",
178-
"5 28 \n",
179-
"6 76 \n",
180-
"7 42 \n",
173+
"0 45 \n",
174+
"1 77 \n",
175+
"2 8 \n",
176+
"3 40 \n",
177+
"4 53 \n",
178+
"5 33 \n",
179+
"6 93 \n",
180+
"7 68 \n",
181181
"8 53 \n",
182-
"9 61 \n",
183-
"10 86 \n",
184-
"11 31 \n",
185-
"12 69 \n",
186-
"13 9 \n",
187-
"14 51 \n",
188-
"15 23 \n",
189-
"16 1 \n",
190-
"17 34 \n",
191-
"18 13 \n",
192-
"19 50 \n"
182+
"9 11 \n",
183+
"10 19 \n",
184+
"11 2 \n",
185+
"12 1 \n",
186+
"13 59 \n",
187+
"14 95 \n",
188+
"15 37 \n",
189+
"16 93 \n",
190+
"17 73 \n",
191+
"18 46 \n",
192+
"19 12 \n"
193193
]
194194
}
195195
],
@@ -282,7 +282,7 @@
282282
"name": "stdout",
283283
"output_type": "stream",
284284
"text": [
285-
"Feature set updated: \"customer_transactions\"\n"
285+
"Feature set created: \"customer_transactions\"\n"
286286
]
287287
}
288288
],
@@ -310,27 +310,26 @@
310310
" ],\n",
311311
" \"features\": [\n",
312312
" {\n",
313-
" \"name\": \"total_transactions\",\n",
314-
" \"valueType\": \"INT64\"\n",
315-
" },\n",
316-
" {\n",
317313
" \"name\": \"daily_transactions\",\n",
318314
" \"valueType\": \"DOUBLE\"\n",
315+
" },\n",
316+
" {\n",
317+
" \"name\": \"total_transactions\",\n",
318+
" \"valueType\": \"INT64\"\n",
319319
" }\n",
320320
" ],\n",
321-
" \"maxAge\": \"0s\",\n",
322321
" \"source\": {\n",
323322
" \"type\": \"KAFKA\",\n",
324323
" \"kafkaSourceConfig\": {\n",
325-
" \"bootstrapServers\": \"kafka:9092,localhost:9094\",\n",
324+
" \"bootstrapServers\": \"localhost:9094\",\n",
326325
" \"topic\": \"feast-features\"\n",
327326
" }\n",
328327
" },\n",
329328
" \"project\": \"default\"\n",
330329
" },\n",
331330
" \"meta\": {\n",
332-
" \"createdTimestamp\": \"2020-06-18T12:04:08Z\",\n",
333-
" \"status\": \"STATUS_READY\"\n",
331+
" \"createdTimestamp\": \"2020-06-26T12:27:17Z\",\n",
332+
" \"status\": \"STATUS_PENDING\"\n",
334333
" }\n",
335334
"}\n"
336335
]
@@ -357,17 +356,9 @@
357356
},
358357
{
359358
"cell_type": "code",
360-
"execution_count": 11,
359+
"execution_count": 10,
361360
"metadata": {},
362361
"outputs": [
363-
{
364-
"name": "stderr",
365-
"output_type": "stream",
366-
"text": [
367-
"\r",
368-
" 0%| | 0/50 [00:00<?, ?rows/s]"
369-
]
370-
},
371362
{
372363
"name": "stdout",
373364
"output_type": "stream",
@@ -379,7 +370,7 @@
379370
"name": "stderr",
380371
"output_type": "stream",
381372
"text": [
382-
"100%|██████████| 50/50 [00:01<00:00, 48.83rows/s]"
373+
"100%|██████████| 50/50 [00:01<00:00, 47.23rows/s]"
383374
]
384375
},
385376
{
@@ -403,10 +394,10 @@
403394
{
404395
"data": {
405396
"text/plain": [
406-
"'8da648b7-d6ac-3970-90c6-cf789078c869'"
397+
"'5e650050-f41d-39fc-bc56-d602c4a478d2'"
407398
]
408399
},
409-
"execution_count": 11,
400+
"execution_count": 10,
410401
"metadata": {},
411402
"output_type": "execute_result"
412403
}
@@ -431,34 +422,44 @@
431422
},
432423
{
433424
"cell_type": "code",
434-
"execution_count": 12,
425+
"execution_count": 11,
435426
"metadata": {},
436427
"outputs": [
437428
{
438429
"name": "stdout",
439430
"output_type": "stream",
440431
"text": [
441-
"field_values {\n",
442-
" fields {\n",
443-
" key: \"customer_id\"\n",
444-
" value {\n",
445-
" int64_val: 1001\n",
446-
" }\n",
432+
"[fields {\n",
433+
" key: \"customer_id\"\n",
434+
" value {\n",
435+
" int64_val: 1001\n",
447436
" }\n",
448-
" fields {\n",
449-
" key: \"daily_transactions\"\n",
450-
" value {\n",
451-
" double_val: 5.1228456657485495\n",
452-
" }\n",
437+
"}\n",
438+
"fields {\n",
439+
" key: \"daily_transactions\"\n",
440+
" value {\n",
441+
" double_val: 0.12021977894872915\n",
453442
" }\n",
454-
" fields {\n",
455-
" key: \"total_transactions\"\n",
456-
" value {\n",
457-
" int64_val: 96\n",
458-
" }\n",
443+
"}\n",
444+
"fields {\n",
445+
" key: \"total_transactions\"\n",
446+
" value {\n",
447+
" int64_val: 0\n",
459448
" }\n",
460449
"}\n",
461-
"\n"
450+
"statuses {\n",
451+
" key: \"customer_id\"\n",
452+
" value: PRESENT\n",
453+
"}\n",
454+
"statuses {\n",
455+
" key: \"daily_transactions\"\n",
456+
" value: PRESENT\n",
457+
"}\n",
458+
"statuses {\n",
459+
" key: \"total_transactions\"\n",
460+
" value: PRESENT\n",
461+
"}\n",
462+
"]\n"
462463
]
463464
}
464465
],
@@ -469,15 +470,41 @@
469470
" f\"total_transactions\",\n",
470471
" ],\n",
471472
" entity_rows=[\n",
472-
" GetOnlineFeaturesRequest.EntityRow(\n",
473-
" fields={\n",
474-
" \"customer_id\": Value(\n",
475-
" int64_val=1001)\n",
476-
" }\n",
477-
" )\n",
473+
" {\n",
474+
" \"customer_id\": 1001\n",
475+
" }\n",
478476
" ],\n",
479477
")\n",
480-
"print(online_features)"
478+
"print(online_features.field_values)"
479+
]
480+
},
481+
{
482+
"cell_type": "markdown",
483+
"metadata": {},
484+
"source": [
485+
"To retrieve the fields in dictionary format, we can utilize `to_dict()` method."
486+
]
487+
},
488+
{
489+
"cell_type": "code",
490+
"execution_count": 12,
491+
"metadata": {},
492+
"outputs": [
493+
{
494+
"data": {
495+
"text/plain": [
496+
"{'daily_transactions': [0.12021977894872915],\n",
497+
" 'total_transactions': [0],\n",
498+
" 'customer_id': [1001]}"
499+
]
500+
},
501+
"execution_count": 12,
502+
"metadata": {},
503+
"output_type": "execute_result"
504+
}
505+
],
506+
"source": [
507+
"online_features.to_dict()"
481508
]
482509
},
483510
{
@@ -708,9 +735,9 @@
708735
],
709736
"metadata": {
710737
"kernelspec": {
711-
"display_name": "Python 3",
738+
"display_name": "local-feast",
712739
"language": "python",
713-
"name": "python3"
740+
"name": "local-feast"
714741
},
715742
"language_info": {
716743
"codemirror_mode": {
@@ -726,5 +753,5 @@
726753
}
727754
},
728755
"nbformat": 4,
729-
"nbformat_minor": 2
756+
"nbformat_minor": 4
730757
}

0 commit comments

Comments
 (0)