Skip to content

Commit f279a7d

Browse files
authored
Improve online deserialization latency (feast-dev#2164)
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent fd64654 commit f279a7d

1 file changed

Lines changed: 7 additions & 40 deletions

File tree

sdk/python/feast/type_map.py

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

15-
import base64
1615
import re
1716
from datetime import datetime
1817
from typing import Any, Dict, List, Optional, Set, Tuple, Type
1918

2019
import numpy as np
2120
import pandas as pd
2221
import pyarrow
23-
from google.protobuf.json_format import MessageToDict
2422
from google.protobuf.pyext.cpp_message import GeneratedProtocolMessageType
2523
from google.protobuf.timestamp_pb2 import Timestamp
2624

@@ -48,44 +46,13 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
4846
Returns:
4947
Python native type representation/version of the given field_value_proto
5048
"""
51-
field_value_dict = MessageToDict(field_value_proto, float_precision=18) # type: ignore
52-
53-
# This can happen when proto_json.patch() has been called before this call, which is true for a feature server
54-
if not isinstance(field_value_dict, dict):
55-
return field_value_dict
56-
57-
for k, v in field_value_dict.items():
58-
if "List" in k:
59-
val = v.get("val", [])
60-
else:
61-
val = v
62-
63-
if k == "int64Val":
64-
return int(val)
65-
if k == "bytesVal":
66-
# MessageToDict converts the bytes object to base64 encoded string:
67-
# https://developers.google.com/protocol-buffers/docs/proto3#json
68-
return base64.b64decode(val)
69-
if (k == "int64ListVal") or (k == "int32ListVal"):
70-
return [int(item) for item in val]
71-
if (k == "floatListVal") or (k == "doubleListVal"):
72-
return [float(item) for item in val]
73-
if k == "stringListVal":
74-
return [str(item) for item in val]
75-
if k == "bytesListVal":
76-
# MessageToDict converts the bytes object to base64 encoded string:
77-
# https://developers.google.com/protocol-buffers/docs/proto3#json
78-
return [base64.b64decode(val) for item in val]
79-
if k == "boolListVal":
80-
return [bool(item) for item in val]
81-
82-
if k in ["int32Val", "floatVal", "doubleVal", "stringVal", "boolVal"]:
83-
return val
84-
else:
85-
raise TypeError(
86-
f"Casting to Python native type for type {k} failed. "
87-
f"Type {k} not found"
88-
)
49+
val_attr = field_value_proto.WhichOneof("val")
50+
if val_attr is None:
51+
return None
52+
val = getattr(field_value_proto, val_attr)
53+
if hasattr(val, "val"):
54+
val = list(val.val)
55+
return val
8956

9057

9158
def feast_value_type_to_pandas_type(value_type: ValueType) -> Any:

0 commit comments

Comments
 (0)