MCPcopy Index your code
hub / github.com/feast-dev/feast / serialize_entity_key_prefix

Function serialize_entity_key_prefix

sdk/python/feast/infra/key_encoding_utils.py:50–74  ·  view source on GitHub ↗

Serialize keys to a bytestring, so it can be used to prefix-scan through items stored in the online store using serialize_entity_key. This encoding is a partial implementation of serialize_entity_key, only operating on the keys of entities, and not the values.

(
    entity_keys: List[str], entity_key_serialization_version: int = 3
)

Source from the content-addressed store, hash-verified

48
49
50def serialize_entity_key_prefix(
51 entity_keys: List[str], entity_key_serialization_version: int = 3
52) -> bytes:
53 """
54 Serialize keys to a bytestring, so it can be used to prefix-scan through items stored in the online store
55 using serialize_entity_key.
56
57 This encoding is a partial implementation of serialize_entity_key, only operating on the keys of entities,
58 and not the values.
59 """
60 # Fast path optimization for single entity
61 if len(entity_keys) == 1:
62 sorted_keys = [entity_keys[0]]
63 else:
64 sorted_keys = sorted(entity_keys)
65 output: List[bytes] = []
66 if entity_key_serialization_version > 2:
67 output.append(struct.pack("<I", len(sorted_keys)))
68 for k in sorted_keys:
69 k_encoded = k.encode("utf8")
70 output.append(struct.pack("<I", ValueType.STRING))
71 if entity_key_serialization_version > 2:
72 output.append(struct.pack("<I", len(k_encoded)))
73 output.append(k_encoded)
74 return b"".join(output)
75
76
77def reserialize_entity_v2_key_to_v3(

Calls 2

encodeMethod · 0.80
joinMethod · 0.45