forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pedro Jacinto
committed
Apr 21, 2020
1 parent
fc45a7b
commit 88b955a
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# install deps\n", | ||
"!pip install pendulum kafka-python\n", | ||
"\n", | ||
"# download feast message contract\n", | ||
"!mkdir -p /home/feast/types\n", | ||
"\n", | ||
"!wget https://raw.githubusercontent.com/gojek/feast/master/protos/feast/types/FeatureRow.proto -P /home/feast/types\n", | ||
"!wget https://raw.githubusercontent.com/gojek/feast/master/protos/feast/types/Field.proto -P /home/feast/types\n", | ||
"!wget https://raw.githubusercontent.com/gojek/feast/master/protos/feast/types/Value.proto -P /home/feast/types\n", | ||
"\n", | ||
"# compile protos\n", | ||
"!protoc -I /home --python_out=/home /home/feast/types/*.proto" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import logging\n", | ||
"import pendulum\n", | ||
"from google.protobuf.timestamp_pb2 import Timestamp\n", | ||
"from kafka import KafkaProducer\n", | ||
"from feast.types.FeatureRow_pb2 import FeatureRow\n", | ||
"from feast.types.Field_pb2 import Field\n", | ||
"from feast.types.Value_pb2 import Value, Int32List, BytesList\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# build message\n", | ||
"row = FeatureRow()\n", | ||
"row.fields.MergeFrom([\n", | ||
" Field(name=\"person_id\", value=Value(int64_val=1234)),\n", | ||
" Field(name=\"gender\", value=Value(string_val=\"M\")),\n", | ||
"])\n", | ||
"ts = Timestamp()\n", | ||
"ts.FromJsonString(pendulum.now(\"UTC\").to_iso8601_string())\n", | ||
"row.event_timestamp.CopyFrom(ts)\n", | ||
"row.feature_set = \"proj_8619/person_info:2\" # [PROJECT_NAME]/[FEATURE_NAME]:[VERSION]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# send to kafka\n", | ||
"producer = KafkaProducer(bootstrap_servers=\"10.163.12.6:9092\")\n", | ||
"producer.send(\"feast-fs-person-predictions\", row.SerializeToString())\n", | ||
"producer.flush()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |