Skip to content

Commit 782c759

Browse files
chore: Clean up entity key serialization (feast-dev#3199)
* Clean up entity key serialization Signed-off-by: Felix Wang <[email protected]> * Remove incorrect docs Signed-off-by: Felix Wang <[email protected]> * Format Signed-off-by: Felix Wang <[email protected]> Signed-off-by: Felix Wang <[email protected]>
1 parent 2535024 commit 782c759

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

docs/how-to-guides/customizing-feast/adding-support-for-a-new-online-store.md

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ def online_write_batch(
154154
project = config.project
155155

156156
for entity_key, values, timestamp, created_ts in data:
157-
entity_key_bin = serialize_entity_key(entity_key).hex()
157+
entity_key_bin = serialize_entity_key(
158+
entity_key,
159+
entity_key_serialization_version=config.entity_key_serialization_version,
160+
).hex()
158161
timestamp = _to_naive_utc(timestamp)
159162
if created_ts is not None:
160163
created_ts = _to_naive_utc(created_ts)
@@ -184,7 +187,10 @@ def online_read(
184187

185188
project = config.project
186189
for entity_key in entity_keys:
187-
entity_key_bin = serialize_entity_key(entity_key).hex()
190+
entity_key_bin = serialize_entity_key(
191+
entity_key,
192+
entity_key_serialization_version=config.entity_key_serialization_version,
193+
).hex()
188194
print(f"entity_key_bin: {entity_key_bin}")
189195

190196
cur.execute(
@@ -208,18 +214,6 @@ def online_read(
208214
```
209215
{% endcode %}
210216

211-
### 1.3 Type Mapping
212-
213-
Most online stores will have to perform some custom mapping of online store datatypes to feast value types.
214-
215-
* The function to implement here are `source_datatype_to_feast_value_type` and `get_column_names_and_types` in your `DataSource` class.
216-
* `source_datatype_to_feast_value_type` is used to convert your DataSource's datatypes to feast value types.
217-
* `get_column_names_and_types` retrieves the column names and corresponding datasource types.
218-
219-
Add any helper functions for type conversion to `sdk/python/feast/type_map.py`.
220-
221-
* Be sure to implement correct type mapping so that Feast can process your feature columns without casting incorrectly that can potentially cause loss of information or incorrect data.
222-
223217
## 2. Defining an OnlineStoreConfig class
224218

225219
Additional configuration may be needed to allow the OnlineStore to talk to the backing store. For example, MySQL may need configuration information like the host at which the MySQL instance is running, credentials for connecting to the database, etc.

sdk/python/feast/infra/online_stores/contrib/cassandra_online_store/cassandra_online_store.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ def online_write_batch(
314314
project = config.project
315315
for entity_key, values, timestamp, created_ts in data:
316316
entity_key_bin = serialize_entity_key(
317-
entity_key, entity_key_serialization_version=2
317+
entity_key,
318+
entity_key_serialization_version=config.entity_key_serialization_version,
318319
).hex()
319320
with tracing_span(name="remote_call"):
320321
self._write_rows(
@@ -353,7 +354,8 @@ def online_read(
353354

354355
for entity_key in entity_keys:
355356
entity_key_bin = serialize_entity_key(
356-
entity_key, entity_key_serialization_version=2
357+
entity_key,
358+
entity_key_serialization_version=config.entity_key_serialization_version,
357359
).hex()
358360

359361
with tracing_span(name="remote_call"):

sdk/python/feast/infra/online_stores/snowflake.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ def online_write_batch(
9494

9595
for j, (feature_name, val) in enumerate(values.items()):
9696
df.loc[j, "entity_feature_key"] = serialize_entity_key(
97-
entity_key, 2
97+
entity_key,
98+
entity_key_serialization_version=config.entity_key_serialization_version,
9899
) + bytes(feature_name, encoding="utf-8")
99-
df.loc[j, "entity_key"] = serialize_entity_key(entity_key, 2)
100+
df.loc[j, "entity_key"] = serialize_entity_key(
101+
entity_key,
102+
entity_key_serialization_version=config.entity_key_serialization_version,
103+
)
100104
df.loc[j, "feature_name"] = feature_name
101105
df.loc[j, "value"] = val.SerializeToString()
102106
df.loc[j, "event_ts"] = timestamp
@@ -162,7 +166,10 @@ def online_read(
162166
(
163167
"TO_BINARY("
164168
+ hexlify(
165-
serialize_entity_key(combo[0], 2)
169+
serialize_entity_key(
170+
combo[0],
171+
entity_key_serialization_version=config.entity_key_serialization_version,
172+
)
166173
+ bytes(combo[1], encoding="utf-8")
167174
).__str__()[1:]
168175
+ ")"
@@ -184,7 +191,10 @@ def online_read(
184191
df = execute_snowflake_statement(conn, query).fetch_pandas_all()
185192

186193
for entity_key in entity_keys:
187-
entity_key_bin = serialize_entity_key(entity_key, 2)
194+
entity_key_bin = serialize_entity_key(
195+
entity_key,
196+
entity_key_serialization_version=config.entity_key_serialization_version,
197+
)
188198
res = {}
189199
res_ts = None
190200
for index, row in df[df["entity_key"] == entity_key_bin].iterrows():

0 commit comments

Comments
 (0)