Skip to content

Commit df4c62b

Browse files
soooojinleeclaude
authored 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]>
1 parent 0f77135 commit df4c62b

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
@@ -2597,7 +2597,11 @@ def _doc_feature(x):
25972597
online_features_response=online_features_response,
25982598
data=requested_features_data,
25992599
)
2600-
return OnlineResponse(online_features_response)
2600+
feature_types = {
2601+
f.name: f.dtype.to_value_type()
2602+
for f in requested_feature_view.features
2603+
}
2604+
return OnlineResponse(online_features_response, feature_types=feature_types)
26012605

26022606
def retrieve_online_documents_v2(
26032607
self,
@@ -2881,7 +2885,11 @@ def _retrieve_from_online_store_v2(
28812885
online_features_response.metadata.feature_names.val.extend(
28822886
features_to_request
28832887
)
2884-
return OnlineResponse(online_features_response)
2888+
feature_types = {
2889+
f.name: f.dtype.to_value_type()
2890+
for f in table.features
2891+
}
2892+
return OnlineResponse(online_features_response, feature_types=feature_types)
28852893

28862894
table_entity_values, idxs, output_len = utils._get_unique_entities_from_values(
28872895
entity_key_dict,
@@ -2908,7 +2916,11 @@ def _retrieve_from_online_store_v2(
29082916
data=entity_key_dict,
29092917
)
29102918

2911-
return OnlineResponse(online_features_response)
2919+
feature_types = {
2920+
f.name: f.dtype.to_value_type()
2921+
for f in table.features
2922+
}
2923+
return OnlineResponse(online_features_response, feature_types=feature_types)
29122924

29132925
def serve(
29142926
self,

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,21 @@ def get_online_features(
218218
output_len,
219219
)
220220

221+
feature_types = self._build_feature_types(grouped_refs)
222+
221223
if requested_on_demand_feature_views:
222224
utils._augment_response_with_on_demand_transforms(
223225
online_features_response,
224226
feature_refs,
225227
requested_on_demand_feature_views,
226228
full_feature_names,
229+
feature_types=feature_types,
227230
)
228231

229232
utils._drop_unneeded_columns(
230233
online_features_response, requested_result_row_names
231234
)
232-
return OnlineResponse(online_features_response)
235+
return OnlineResponse(online_features_response, feature_types=feature_types)
233236

234237
async def get_online_features_async(
235238
self,
@@ -318,18 +321,35 @@ async def query_table(table, requested_features):
318321
output_len,
319322
)
320323

324+
feature_types = self._build_feature_types(grouped_refs)
325+
321326
if requested_on_demand_feature_views:
322327
utils._augment_response_with_on_demand_transforms(
323328
online_features_response,
324329
feature_refs,
325330
requested_on_demand_feature_views,
326331
full_feature_names,
332+
feature_types=feature_types,
327333
)
328334

329335
utils._drop_unneeded_columns(
330336
online_features_response, requested_result_row_names
331337
)
332-
return OnlineResponse(online_features_response)
338+
return OnlineResponse(online_features_response, feature_types=feature_types)
339+
340+
@staticmethod
341+
def _build_feature_types(
342+
grouped_refs: List,
343+
) -> Dict[str, "ValueType"]:
344+
"""Build a mapping of feature names to ValueType from grouped feature view refs."""
345+
from feast.value_type import ValueType as VT
346+
347+
feature_types: Dict[str, VT] = {}
348+
for table, requested_features in grouped_refs:
349+
for field in table.features:
350+
if field.name in requested_features:
351+
feature_types[field.name] = field.dtype.to_value_type()
352+
return feature_types
333353

334354
@abstractmethod
335355
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
@@ -1093,6 +1094,9 @@ def _get_sample_values_by_type(self) -> dict[ValueType, list[Any]]:
10931094
# Special binary types
10941095
ValueType.PDF_BYTES: [pdf_sample],
10951096
ValueType.IMAGE_BYTES: [image_sample],
1097+
# UUID types
1098+
ValueType.UUID: [str(uuid.uuid4())],
1099+
ValueType.TIME_UUID: [str(uuid.uuid1())],
10961100
# List types
10971101
ValueType.BYTES_LIST: [[b"hello world"]],
10981102
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.
@@ -124,6 +128,9 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
124128
elif val_attr.endswith("_set_val") and val_attr != "unix_timestamp_set_val":
125129
val = set(val)
126130

131+
if feature_type in (ValueType.UUID, ValueType.TIME_UUID) and isinstance(val, str):
132+
return uuid_module.UUID(val)
133+
127134
return val
128135

129136

@@ -160,6 +167,8 @@ def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:
160167
ValueType.BYTES: "bytes",
161168
ValueType.BOOL: "bool",
162169
ValueType.UNIX_TIMESTAMP: "datetime64[ns]",
170+
ValueType.UUID: "str",
171+
ValueType.TIME_UUID: "str",
163172
}
164173
if (
165174
value_type.name == "MAP"
@@ -223,6 +232,7 @@ def python_type_to_feast_value_type(
223232
"datetime64[ns, utc]": ValueType.UNIX_TIMESTAMP,
224233
"date": ValueType.UNIX_TIMESTAMP,
225234
"category": ValueType.STRING,
235+
"uuid": ValueType.UUID,
226236
}
227237

228238
if type_name in type_map:
@@ -375,6 +385,10 @@ def _convert_value_type_str_to_value_type(type_str: str) -> ValueType:
375385
"FLOAT_LIST": ValueType.FLOAT_LIST,
376386
"BOOL_LIST": ValueType.BOOL_LIST,
377387
"UNIX_TIMESTAMP_LIST": ValueType.UNIX_TIMESTAMP_LIST,
388+
"UUID": ValueType.UUID,
389+
"TIME_UUID": ValueType.TIME_UUID,
390+
"UUID_LIST": ValueType.UUID_LIST,
391+
"TIME_UUID_LIST": ValueType.TIME_UUID_LIST,
378392
}
379393
return type_map.get(type_str, ValueType.STRING)
380394

@@ -406,6 +420,8 @@ def _type_err(item, dtype):
406420
ValueType.STRING_LIST: (StringList, "string_list_val", [np.str_, str]),
407421
ValueType.BOOL_LIST: (BoolList, "bool_list_val", [np.bool_, bool]),
408422
ValueType.BYTES_LIST: (BytesList, "bytes_list_val", [np.bytes_, bytes]),
423+
ValueType.UUID_LIST: (StringList, "string_list_val", [np.str_, str, uuid_module.UUID]),
424+
ValueType.TIME_UUID_LIST: (StringList, "string_list_val", [np.str_, str, uuid_module.UUID]),
409425
}
410426

411427
PYTHON_SET_VALUE_TYPE_TO_PROTO_VALUE: Dict[
@@ -456,6 +472,8 @@ def _type_err(item, dtype):
456472
ValueType.BYTES: ("bytes_val", lambda x: x, {bytes}),
457473
ValueType.IMAGE_BYTES: ("bytes_val", lambda x: x, {bytes}),
458474
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_, int, np.int_}),
475+
ValueType.UUID: ("string_val", lambda x: str(x), {str, uuid_module.UUID}),
476+
ValueType.TIME_UUID: ("string_val", lambda x: str(x), {str, uuid_module.UUID}),
459477
}
460478

461479

@@ -1086,6 +1104,8 @@ def _convert_value_name_to_snowflake_udf(value_name: str, project_name: str) ->
10861104
"FLOAT_LIST": f"feast_{project_name}_snowflake_array_float_to_list_double_proto",
10871105
"BOOL_LIST": f"feast_{project_name}_snowflake_array_boolean_to_list_bool_proto",
10881106
"UNIX_TIMESTAMP_LIST": f"feast_{project_name}_snowflake_array_timestamp_to_list_unix_timestamp_proto",
1107+
"UUID": f"feast_{project_name}_snowflake_varchar_to_string_proto",
1108+
"TIME_UUID": f"feast_{project_name}_snowflake_varchar_to_string_proto",
10891109
}
10901110
return name_map[value_name].upper()
10911111

@@ -1265,8 +1285,8 @@ def pg_type_to_feast_value_type(type_str: str) -> ValueType:
12651285
"timestamp with time zone[]": ValueType.UNIX_TIMESTAMP_LIST,
12661286
"numeric[]": ValueType.DOUBLE_LIST,
12671287
"numeric": ValueType.DOUBLE,
1268-
"uuid": ValueType.STRING,
1269-
"uuid[]": ValueType.STRING_LIST,
1288+
"uuid": ValueType.UUID,
1289+
"uuid[]": ValueType.UUID_LIST,
12701290
}
12711291
value = (
12721292
type_map[type_str.lower()]
@@ -1301,6 +1321,10 @@ def feast_value_type_to_pa(
13011321
ValueType.BOOL_LIST: pyarrow.list_(pyarrow.bool_()),
13021322
ValueType.UNIX_TIMESTAMP_LIST: pyarrow.list_(pyarrow.timestamp(timestamp_unit)),
13031323
ValueType.NULL: pyarrow.null(),
1324+
ValueType.UUID: pyarrow.string(),
1325+
ValueType.TIME_UUID: pyarrow.string(),
1326+
ValueType.UUID_LIST: pyarrow.list_(pyarrow.string()),
1327+
ValueType.TIME_UUID_LIST: pyarrow.list_(pyarrow.string()),
13041328
}
13051329
return type_map[feast_type]
13061330

@@ -1439,7 +1463,7 @@ def cb_columnar_type_to_feast_value_type(type_str: str) -> ValueType:
14391463
"object": ValueType.UNKNOWN,
14401464
"array": ValueType.UNKNOWN,
14411465
"multiset": ValueType.UNKNOWN,
1442-
"uuid": ValueType.STRING,
1466+
"uuid": ValueType.UUID,
14431467
}
14441468
value = (
14451469
type_map[type_str.lower()]
@@ -1465,6 +1489,8 @@ def convert_scalar_column(
14651489
return series.astype("boolean")
14661490
elif value_type == ValueType.STRING:
14671491
return series.astype("string")
1492+
elif value_type in [ValueType.UUID, ValueType.TIME_UUID]:
1493+
return series.astype("string")
14681494
elif value_type == ValueType.UNIX_TIMESTAMP:
14691495
return pd.to_datetime(series, unit="s", errors="coerce")
14701496
else:

‎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",
@@ -85,6 +87,8 @@ class PrimitiveFeastType(Enum):
8587
PDF_BYTES = 9
8688
IMAGE_BYTES = 10
8789
MAP = 11
90+
UUID = 12
91+
TIME_UUID = 13
8892

8993
def to_value_type(self) -> ValueType:
9094
"""
@@ -118,6 +122,8 @@ def __hash__(self):
118122
Float64 = PrimitiveFeastType.FLOAT64
119123
UnixTimestamp = PrimitiveFeastType.UNIX_TIMESTAMP
120124
Map = PrimitiveFeastType.MAP
125+
Uuid = PrimitiveFeastType.UUID
126+
TimeUuid = PrimitiveFeastType.TIME_UUID
121127

122128
SUPPORTED_BASE_TYPES = [
123129
Invalid,
@@ -132,6 +138,8 @@ def __hash__(self):
132138
Float64,
133139
UnixTimestamp,
134140
Map,
141+
Uuid,
142+
TimeUuid,
135143
]
136144

137145
PRIMITIVE_FEAST_TYPES_TO_STRING = {
@@ -147,6 +155,8 @@ def __hash__(self):
147155
"FLOAT64": "Float64",
148156
"UNIX_TIMESTAMP": "UnixTimestamp",
149157
"MAP": "Map",
158+
"UUID": "Uuid",
159+
"TIME_UUID": "TimeUuid",
150160
}
151161

152162

@@ -240,6 +250,10 @@ def __str__(self):
240250
ValueType.FLOAT_SET: Set(Float32),
241251
ValueType.BOOL_SET: Set(Bool),
242252
ValueType.UNIX_TIMESTAMP_SET: Set(UnixTimestamp),
253+
ValueType.UUID: Uuid,
254+
ValueType.TIME_UUID: TimeUuid,
255+
ValueType.UUID_LIST: Array(Uuid),
256+
ValueType.TIME_UUID_LIST: Array(TimeUuid),
243257
}
244258

245259
FEAST_TYPES_TO_PYARROW_TYPES = {
@@ -251,6 +265,8 @@ def __str__(self):
251265
Float64: pyarrow.float64(),
252266
# Note: datetime only supports microseconds https://github.com/python/cpython/blob/3.8/Lib/datetime.py#L1559
253267
UnixTimestamp: pyarrow.timestamp("us", tz=_utc_now().tzname()),
268+
Uuid: pyarrow.string(),
269+
TimeUuid: pyarrow.string(),
254270
}
255271

256272
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
@@ -636,6 +636,7 @@ def _augment_response_with_on_demand_transforms(
636636
feature_refs: List[str],
637637
requested_on_demand_feature_views: List["OnDemandFeatureView"],
638638
full_feature_names: bool,
639+
feature_types: Optional[Dict[str, "ValueType"]] = None,
639640
):
640641
"""Computes on demand feature values and adds them to the result rows.
641642
@@ -666,7 +667,7 @@ def _augment_response_with_on_demand_transforms(
666667
else feature_name
667668
)
668669

669-
initial_response = OnlineResponse(online_features_response)
670+
initial_response = OnlineResponse(online_features_response, feature_types=feature_types)
670671
initial_response_arrow: Optional[pyarrow.Table] = None
671672
initial_response_dict: Optional[Dict[str, List[Any]]] = None
672673

‎sdk/python/feast/value_type.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ValueType(enum.Enum):
6767
UNIX_TIMESTAMP_SET = 29
6868
PDF_BYTES = 30
6969
IMAGE_BYTES = 31
70+
UUID = 32
71+
TIME_UUID = 33
72+
UUID_LIST = 34
73+
TIME_UUID_LIST = 35
7074

7175

7276
ListType = Union[

0 commit comments

Comments
 (0)