Skip to content

Commit b280364

Browse files
soooojinleentkathole
authored andcommitted
fix: Convert uuid.UUID to string for Arrow and JSON serialization
Signed-off-by: soojin <soojin@dable.io>
1 parent 1005e12 commit b280364

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
import json
1515
import logging
16+
import uuid as uuid_module
1617
from collections import defaultdict
1718
from datetime import datetime
1819
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple
@@ -38,6 +39,15 @@
3839
logger = logging.getLogger(__name__)
3940

4041

42+
def _json_safe(val: Any) -> Any:
43+
"""Convert uuid.UUID objects to strings for JSON serialization."""
44+
if isinstance(val, uuid_module.UUID):
45+
return str(val)
46+
if isinstance(val, list):
47+
return [str(v) if isinstance(v, uuid_module.UUID) else v for v in val]
48+
return val
49+
50+
4151
class RemoteOnlineStoreConfig(FeastConfigBaseModel):
4252
"""Remote Online store config for remote online store"""
4353

@@ -93,15 +103,13 @@ def online_write_batch(
93103
for join_key, entity_value_proto in zip(
94104
entity_key_proto.join_keys, entity_key_proto.entity_values
95105
):
96-
columnar_data[join_key].append(
97-
feast_value_type_to_python_type(entity_value_proto)
98-
)
106+
val = feast_value_type_to_python_type(entity_value_proto)
107+
columnar_data[join_key].append(_json_safe(val))
99108

100109
# Populate feature values
101110
for feature_name, feature_value_proto in feature_values_proto.items():
102-
columnar_data[feature_name].append(
103-
feast_value_type_to_python_type(feature_value_proto)
104-
)
111+
val = feast_value_type_to_python_type(feature_value_proto)
112+
columnar_data[feature_name].append(_json_safe(val))
105113

106114
# Populate timestamps
107115
columnar_data["event_timestamp"].append(_to_naive_utc(event_ts).isoformat())

sdk/python/feast/online_response.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,26 @@ def to_arrow(self, include_event_timestamps: bool = False) -> pa.Table:
103103
Args:
104104
include_event_timestamps: bool Optionally include feature timestamps in the table
105105
"""
106+
import uuid as uuid_module
106107

107-
return pa.Table.from_pydict(self.to_dict(include_event_timestamps))
108+
result = self.to_dict(include_event_timestamps)
109+
# Convert uuid.UUID objects to strings for PyArrow compatibility
110+
for key, values in result.items():
111+
first_valid = next((v for v in values if v is not None), None)
112+
if isinstance(first_valid, uuid_module.UUID):
113+
result[key] = [
114+
str(v) if isinstance(v, uuid_module.UUID) else v for v in values
115+
]
116+
elif isinstance(first_valid, list):
117+
inner = next((e for e in first_valid if e is not None), None)
118+
if isinstance(inner, uuid_module.UUID):
119+
result[key] = [
120+
[str(e) if isinstance(e, uuid_module.UUID) else e for e in v]
121+
if isinstance(v, list)
122+
else v
123+
for v in values
124+
]
125+
return pa.Table.from_pydict(result)
108126

109127
def to_tensor(
110128
self,

0 commit comments

Comments
 (0)