-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Use C-type long long (8 bytes) type format to pack int64 values #2609
Changes from all commits
5e5e58a
64fd62f
097da5c
4d8cdb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,9 @@ message FeatureViewSpec { | |
|
||
// Whether these features should be served online or not | ||
bool online = 8; | ||
|
||
// Needed for backwards compatible behaviour when fixing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update comment after |
||
int32 entity_key_serialization_version = 13; | ||
} | ||
|
||
message FeatureViewMeta { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,17 @@ | |
from feast.protos.feast.types.Value_pb2 import ValueType | ||
|
||
|
||
def _serialize_val(value_type, v: ValueProto) -> Tuple[bytes, int]: | ||
def _serialize_val( | ||
value_type, v: ValueProto, entity_key_serialization_version=1 | ||
) -> Tuple[bytes, int]: | ||
if value_type == "string_val": | ||
return v.string_val.encode("utf8"), ValueType.STRING | ||
elif value_type == "bytes_val": | ||
return v.bytes_val, ValueType.BYTES | ||
elif value_type == "int32_val": | ||
return struct.pack("<i", v.int32_val), ValueType.INT32 | ||
elif value_type == "int64_val": | ||
return struct.pack("<l", v.int64_val), ValueType.INT64 | ||
return struct.pack("<q", v.int64_val), ValueType.INT64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I understand the compatibility approach you're taking here - can you explain? what do the various values of I was imagining we should do something like the following:
|
||
else: | ||
raise ValueError(f"Value type not supported for Firestore: {v}") | ||
|
||
|
@@ -35,7 +37,9 @@ def serialize_entity_key_prefix(entity_keys: List[str]) -> bytes: | |
return b"".join(output) | ||
|
||
|
||
def serialize_entity_key(entity_key: EntityKeyProto) -> bytes: | ||
def serialize_entity_key( | ||
entity_key: EntityKeyProto, entity_key_serialization_version=1 | ||
) -> bytes: | ||
""" | ||
Serialize entity key to a bytestring so it can be used as a lookup key in a hash table. | ||
|
||
|
@@ -54,7 +58,11 @@ def serialize_entity_key(entity_key: EntityKeyProto) -> bytes: | |
output.append(struct.pack("<I", ValueType.STRING)) | ||
output.append(k.encode("utf8")) | ||
for v in sorted_values: | ||
val_bytes, value_type = _serialize_val(v.WhichOneof("val"), v) | ||
val_bytes, value_type = _serialize_val( | ||
v.WhichOneof("val"), | ||
v, | ||
entity_key_serialization_version=entity_key_serialization_version, | ||
) | ||
|
||
output.append(struct.pack("<I", value_type)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
from feast.infra.key_encoding_utils import serialize_entity_key | ||
from feast.protos.feast.types.EntityKey_pb2 import EntityKey as EntityKeyProto | ||
from feast.protos.feast.types.Value_pb2 import Value as ValueProto | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"entity_key,expected_contains", | ||
[ | ||
( | ||
EntityKeyProto( | ||
join_keys=["customer"], | ||
entity_values=[ValueProto(int64_val=int(2 ** 31))], | ||
), | ||
b"customer", | ||
), | ||
( | ||
EntityKeyProto( | ||
join_keys=["user"], entity_values=[ValueProto(int32_val=int(2 ** 15))] | ||
), | ||
b"user", | ||
), | ||
], | ||
) | ||
def test_serialize_entity_key(entity_key, expected_contains): | ||
output = serialize_entity_key(entity_key) | ||
assert output.find(expected_contains) >= 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this stuff