Skip to content

Commit 266011c

Browse files
soooojinleeclaude
andcommitted
feat: Add UUID and TIME_UUID as feature types (feast-dev#5885)
Signed-off-by: soojin <[email protected]> Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: soojin <[email protected]>
1 parent effa9ca commit 266011c

8 files changed

Lines changed: 105 additions & 13 deletions

File tree

‎sdk/python/feast/feature_store.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,11 @@ def _doc_feature(x):
27682768
online_features_response=online_features_response,
27692769
data=requested_features_data,
27702770
)
2771-
return OnlineResponse(online_features_response)
2771+
feature_types = {
2772+
f.name: f.dtype.to_value_type()
2773+
for f in requested_feature_view.features
2774+
}
2775+
return OnlineResponse(online_features_response, feature_types=feature_types)
27722776

27732777
def retrieve_online_documents_v2(
27742778
self,
@@ -3058,7 +3062,11 @@ def _retrieve_from_online_store_v2(
30583062
online_features_response.metadata.feature_names.val.extend(
30593063
features_to_request
30603064
)
3061-
return OnlineResponse(online_features_response)
3065+
feature_types = {
3066+
f.name: f.dtype.to_value_type()
3067+
for f in table.features
3068+
}
3069+
return OnlineResponse(online_features_response, feature_types=feature_types)
30623070

30633071
table_entity_values, idxs, output_len = utils._get_unique_entities_from_values(
30643072
entity_key_dict,
@@ -3086,7 +3094,11 @@ def _retrieve_from_online_store_v2(
30863094
data=entity_key_dict,
30873095
)
30883096

3089-
return OnlineResponse(online_features_response)
3097+
feature_types = {
3098+
f.name: f.dtype.to_value_type()
3099+
for f in table.features
3100+
}
3101+
return OnlineResponse(online_features_response, feature_types=feature_types)
30903102

30913103
def serve(
30923104
self,

‎sdk/python/feast/infra/online_stores/online_store.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,21 @@ def get_online_features(
241241

242242
track_online_store_read(_time.monotonic() - _read_start)
243243

244+
feature_types = self._build_feature_types(grouped_refs)
245+
244246
if requested_on_demand_feature_views:
245247
utils._augment_response_with_on_demand_transforms(
246248
online_features_response,
247249
feature_refs,
248250
requested_on_demand_feature_views,
249251
full_feature_names,
252+
feature_types=feature_types,
250253
)
251254

252255
utils._drop_unneeded_columns(
253256
online_features_response, requested_result_row_names
254257
)
255-
return OnlineResponse(online_features_response)
258+
return OnlineResponse(online_features_response, feature_types=feature_types)
256259

257260
def _check_versioned_read_support(self, grouped_refs):
258261
"""Raise an error if versioned reads are attempted on unsupported stores."""
@@ -377,18 +380,35 @@ async def query_table(table, requested_features):
377380

378381
track_online_store_read(_time.monotonic() - _read_start)
379382

383+
feature_types = self._build_feature_types(grouped_refs)
384+
380385
if requested_on_demand_feature_views:
381386
utils._augment_response_with_on_demand_transforms(
382387
online_features_response,
383388
feature_refs,
384389
requested_on_demand_feature_views,
385390
full_feature_names,
391+
feature_types=feature_types,
386392
)
387393

388394
utils._drop_unneeded_columns(
389395
online_features_response, requested_result_row_names
390396
)
391-
return OnlineResponse(online_features_response)
397+
return OnlineResponse(online_features_response, feature_types=feature_types)
398+
399+
@staticmethod
400+
def _build_feature_types(
401+
grouped_refs: List,
402+
) -> Dict[str, "ValueType"]:
403+
"""Build a mapping of feature names to ValueType from grouped feature view refs."""
404+
from feast.value_type import ValueType as VT
405+
406+
feature_types: Dict[str, VT] = {}
407+
for table, requested_features in grouped_refs:
408+
for field in table.features:
409+
if field.name in requested_features:
410+
feature_types[field.name] = field.dtype.to_value_type()
411+
return feature_types
392412

393413
@abstractmethod
394414
def update(

‎sdk/python/feast/on_demand_feature_view.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import functools
3+
import uuid
34
import warnings
45
from types import FunctionType
56
from typing import Any, List, Optional, Union, cast
@@ -1162,6 +1163,9 @@ def _get_sample_values_by_type(self) -> dict[ValueType, list[Any]]:
11621163
# Special binary types
11631164
ValueType.PDF_BYTES: [pdf_sample],
11641165
ValueType.IMAGE_BYTES: [image_sample],
1166+
# UUID types
1167+
ValueType.UUID: [str(uuid.uuid4())],
1168+
ValueType.TIME_UUID: [str(uuid.uuid1())],
11651169
# List types
11661170
ValueType.BYTES_LIST: [[b"hello world"]],
11671171
ValueType.STRING_LIST: [["hello world"]],

‎sdk/python/feast/online_response.py‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import TYPE_CHECKING, Any, Dict, List, TypeAlias, Union
15+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, TypeAlias, Union
1616

1717
import pandas as pd
1818
import pyarrow as pa
@@ -21,6 +21,7 @@
2121
from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesResponse
2222
from feast.torch_wrapper import get_torch
2323
from feast.type_map import feast_value_type_to_python_type
24+
from feast.value_type import ValueType
2425

2526
if TYPE_CHECKING:
2627
import torch
@@ -37,14 +38,20 @@ class OnlineResponse:
3738
Defines an online response in feast.
3839
"""
3940

40-
def __init__(self, online_response_proto: GetOnlineFeaturesResponse):
41+
def __init__(
42+
self,
43+
online_response_proto: GetOnlineFeaturesResponse,
44+
feature_types: Optional[Dict[str, ValueType]] = None,
45+
):
4146
"""
4247
Construct a native online response from its protobuf version.
4348
4449
Args:
4550
online_response_proto: GetOnlineResponse proto object to construct from.
51+
feature_types: Optional mapping of feature names to ValueType for type-aware deserialization.
4652
"""
4753
self.proto = online_response_proto
54+
self._feature_types = feature_types or {}
4855
# Delete DUMMY_ENTITY_ID from proto if it exists
4956
for idx, val in enumerate(self.proto.metadata.feature_names.val):
5057
if val == DUMMY_ENTITY_ID:
@@ -65,8 +72,10 @@ def to_dict(self, include_event_timestamps: bool = False) -> Dict[str, Any]:
6572
for feature_ref, feature_vector in zip(
6673
self.proto.metadata.feature_names.val, self.proto.results
6774
):
75+
feature_type = self._feature_types.get(feature_ref)
6876
response[feature_ref] = [
69-
feast_value_type_to_python_type(v) for v in feature_vector.values
77+
feast_value_type_to_python_type(v, feature_type)
78+
for v in feature_vector.values
7079
]
7180

7281
if include_event_timestamps:

‎sdk/python/feast/type_map.py‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import decimal
1616
import json
1717
import logging
18+
import uuid as uuid_module
1819
from collections import defaultdict
1920
from datetime import datetime, timezone
2021
from typing import (
@@ -67,7 +68,10 @@
6768
logger = logging.getLogger(__name__)
6869

6970

70-
def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
71+
def feast_value_type_to_python_type(
72+
field_value_proto: ProtoValue,
73+
feature_type: Optional[ValueType] = None,
74+
) -> Any:
7175
"""
7276
Converts field value Proto to Dict and returns each field's Feast Value Type value
7377
in their respective Python value.
@@ -148,6 +152,9 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
148152
elif val_attr.endswith("_set_val") and val_attr != "unix_timestamp_set_val":
149153
val = set(val)
150154

155+
if feature_type in (ValueType.UUID, ValueType.TIME_UUID) and isinstance(val, str):
156+
return uuid_module.UUID(val)
157+
151158
return val
152159

153160

@@ -184,6 +191,8 @@ def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:
184191
ValueType.BYTES: "bytes",
185192
ValueType.BOOL: "bool",
186193
ValueType.UNIX_TIMESTAMP: "datetime64[ns]",
194+
ValueType.UUID: "str",
195+
ValueType.TIME_UUID: "str",
187196
}
188197
if (
189198
value_type.name in ("MAP", "JSON", "STRUCT")
@@ -247,6 +256,7 @@ def python_type_to_feast_value_type(
247256
"datetime64[ns, utc]": ValueType.UNIX_TIMESTAMP,
248257
"date": ValueType.UNIX_TIMESTAMP,
249258
"category": ValueType.STRING,
259+
"uuid": ValueType.UUID,
250260
}
251261

252262
if type_name in type_map:
@@ -405,6 +415,10 @@ def _convert_value_type_str_to_value_type(type_str: str) -> ValueType:
405415
"JSON_LIST": ValueType.JSON_LIST,
406416
"STRUCT": ValueType.STRUCT,
407417
"STRUCT_LIST": ValueType.STRUCT_LIST,
418+
"UUID": ValueType.UUID,
419+
"TIME_UUID": ValueType.TIME_UUID,
420+
"UUID_LIST": ValueType.UUID_LIST,
421+
"TIME_UUID_LIST": ValueType.TIME_UUID_LIST,
408422
}
409423
return type_map.get(type_str, ValueType.STRING)
410424

@@ -436,6 +450,8 @@ def _type_err(item, dtype):
436450
ValueType.STRING_LIST: (StringList, "string_list_val", [np.str_, str]),
437451
ValueType.BOOL_LIST: (BoolList, "bool_list_val", [np.bool_, bool]),
438452
ValueType.BYTES_LIST: (BytesList, "bytes_list_val", [np.bytes_, bytes]),
453+
ValueType.UUID_LIST: (StringList, "string_list_val", [np.str_, str, uuid_module.UUID]),
454+
ValueType.TIME_UUID_LIST: (StringList, "string_list_val", [np.str_, str, uuid_module.UUID]),
439455
}
440456

441457
PYTHON_SET_VALUE_TYPE_TO_PROTO_VALUE: Dict[
@@ -486,6 +502,8 @@ def _type_err(item, dtype):
486502
ValueType.BYTES: ("bytes_val", lambda x: x, {bytes}),
487503
ValueType.IMAGE_BYTES: ("bytes_val", lambda x: x, {bytes}),
488504
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_, int, np.int_}),
505+
ValueType.UUID: ("string_val", lambda x: str(x), {str, uuid_module.UUID}),
506+
ValueType.TIME_UUID: ("string_val", lambda x: str(x), {str, uuid_module.UUID}),
489507
}
490508

491509

@@ -1347,6 +1365,8 @@ def _convert_value_name_to_snowflake_udf(value_name: str, project_name: str) ->
13471365
"FLOAT_LIST": f"feast_{project_name}_snowflake_array_float_to_list_double_proto",
13481366
"BOOL_LIST": f"feast_{project_name}_snowflake_array_boolean_to_list_bool_proto",
13491367
"UNIX_TIMESTAMP_LIST": f"feast_{project_name}_snowflake_array_timestamp_to_list_unix_timestamp_proto",
1368+
"UUID": f"feast_{project_name}_snowflake_varchar_to_string_proto",
1369+
"TIME_UUID": f"feast_{project_name}_snowflake_varchar_to_string_proto",
13501370
}
13511371
return name_map[value_name].upper()
13521372

@@ -1550,8 +1570,8 @@ def pg_type_to_feast_value_type(type_str: str) -> ValueType:
15501570
"timestamp with time zone[]": ValueType.UNIX_TIMESTAMP_LIST,
15511571
"numeric[]": ValueType.DOUBLE_LIST,
15521572
"numeric": ValueType.DOUBLE,
1553-
"uuid": ValueType.STRING,
1554-
"uuid[]": ValueType.STRING_LIST,
1573+
"uuid": ValueType.UUID,
1574+
"uuid[]": ValueType.UUID_LIST,
15551575
"json": ValueType.MAP,
15561576
"jsonb": ValueType.MAP,
15571577
"json[]": ValueType.MAP_LIST,
@@ -1598,6 +1618,10 @@ def feast_value_type_to_pa(
15981618
ValueType.STRUCT: pyarrow.struct([]),
15991619
ValueType.STRUCT_LIST: pyarrow.list_(pyarrow.struct([])),
16001620
ValueType.NULL: pyarrow.null(),
1621+
ValueType.UUID: pyarrow.string(),
1622+
ValueType.TIME_UUID: pyarrow.string(),
1623+
ValueType.UUID_LIST: pyarrow.list_(pyarrow.string()),
1624+
ValueType.TIME_UUID_LIST: pyarrow.list_(pyarrow.string()),
16011625
}
16021626
return type_map[feast_type]
16031627

@@ -1750,7 +1774,7 @@ def cb_columnar_type_to_feast_value_type(type_str: str) -> ValueType:
17501774
"object": ValueType.UNKNOWN,
17511775
"array": ValueType.UNKNOWN,
17521776
"multiset": ValueType.UNKNOWN,
1753-
"uuid": ValueType.STRING,
1777+
"uuid": ValueType.UUID,
17541778
}
17551779
value = (
17561780
type_map[type_str.lower()]
@@ -1776,6 +1800,8 @@ def convert_scalar_column(
17761800
return series.astype("boolean")
17771801
elif value_type == ValueType.STRING:
17781802
return series.astype("string")
1803+
elif value_type in [ValueType.UUID, ValueType.TIME_UUID]:
1804+
return series.astype("string")
17791805
elif value_type == ValueType.UNIX_TIMESTAMP:
17801806
return pd.to_datetime(series, unit="s", errors="coerce")
17811807
elif value_type in (ValueType.JSON, ValueType.STRUCT, ValueType.MAP):

‎sdk/python/feast/types.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
"BYTES": "BYTES",
2626
"PDF_BYTES": "PDF_BYTES",
2727
"IMAGE_BYTES": "IMAGE_BYTES",
28+
"UUID": "UUID",
29+
"TIME_UUID": "TIME_UUID",
2830
"STRING": "STRING",
2931
"INT32": "INT32",
3032
"INT64": "INT64",
@@ -87,6 +89,8 @@ class PrimitiveFeastType(Enum):
8789
IMAGE_BYTES = 10
8890
MAP = 11
8991
JSON = 12
92+
UUID = 13
93+
TIME_UUID = 14
9094

9195
def to_value_type(self) -> ValueType:
9296
"""
@@ -121,6 +125,8 @@ def __hash__(self):
121125
UnixTimestamp = PrimitiveFeastType.UNIX_TIMESTAMP
122126
Map = PrimitiveFeastType.MAP
123127
Json = PrimitiveFeastType.JSON
128+
Uuid = PrimitiveFeastType.UUID
129+
TimeUuid = PrimitiveFeastType.TIME_UUID
124130

125131
SUPPORTED_BASE_TYPES = [
126132
Invalid,
@@ -136,6 +142,8 @@ def __hash__(self):
136142
UnixTimestamp,
137143
Map,
138144
Json,
145+
Uuid,
146+
TimeUuid,
139147
]
140148

141149
PRIMITIVE_FEAST_TYPES_TO_STRING = {
@@ -152,6 +160,8 @@ def __hash__(self):
152160
"UNIX_TIMESTAMP": "UnixTimestamp",
153161
"MAP": "Map",
154162
"JSON": "Json",
163+
"UUID": "Uuid",
164+
"TIME_UUID": "TimeUuid",
155165
}
156166

157167

@@ -297,6 +307,10 @@ def __hash__(self):
297307
ValueType.FLOAT_SET: Set(Float32),
298308
ValueType.BOOL_SET: Set(Bool),
299309
ValueType.UNIX_TIMESTAMP_SET: Set(UnixTimestamp),
310+
ValueType.UUID: Uuid,
311+
ValueType.TIME_UUID: TimeUuid,
312+
ValueType.UUID_LIST: Array(Uuid),
313+
ValueType.TIME_UUID_LIST: Array(TimeUuid),
300314
}
301315

302316
FEAST_TYPES_TO_PYARROW_TYPES = {
@@ -310,6 +324,8 @@ def __hash__(self):
310324
UnixTimestamp: pyarrow.timestamp("us", tz=_utc_now().tzname()),
311325
Map: pyarrow.map_(pyarrow.string(), pyarrow.string()),
312326
Json: pyarrow.large_string(),
327+
Uuid: pyarrow.string(),
328+
TimeUuid: pyarrow.string(),
313329
}
314330

315331
FEAST_VECTOR_TYPES: List[Union[ValueType, PrimitiveFeastType, ComplexFeastType]] = [

‎sdk/python/feast/utils.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ def _augment_response_with_on_demand_transforms(
751751
feature_refs: List[str],
752752
requested_on_demand_feature_views: List["OnDemandFeatureView"],
753753
full_feature_names: bool,
754+
feature_types: Optional[Dict[str, "ValueType"]] = None,
754755
):
755756
"""Computes on demand feature values and adds them to the result rows.
756757
@@ -781,7 +782,7 @@ def _augment_response_with_on_demand_transforms(
781782
else feature_name
782783
)
783784

784-
initial_response = OnlineResponse(online_features_response)
785+
initial_response = OnlineResponse(online_features_response, feature_types=feature_types)
785786
initial_response_arrow: Optional[pyarrow.Table] = None
786787
initial_response_dict: Optional[Dict[str, List[Any]]] = None
787788

‎sdk/python/feast/value_type.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class ValueType(enum.Enum):
7171
JSON_LIST = 33
7272
STRUCT = 34
7373
STRUCT_LIST = 35
74+
UUID = 36
75+
TIME_UUID = 37
76+
UUID_LIST = 38
77+
TIME_UUID_LIST = 39
7478

7579

7680
ListType = Union[

0 commit comments

Comments
 (0)