Converts a Field object to its protobuf representation.
(self)
| 118 | return f"Field(name={self.name}, dtype={self.dtype}, tags={self.tags})" |
| 119 | |
| 120 | def to_proto(self) -> FieldProto: |
| 121 | """Converts a Field object to its protobuf representation.""" |
| 122 | from feast.types import Array, Set |
| 123 | |
| 124 | value_type = self.dtype.to_value_type() |
| 125 | vector_search_metric = self.vector_search_metric or "" |
| 126 | tags = dict(self.tags) |
| 127 | # Persist Struct field schema in tags |
| 128 | if isinstance(self.dtype, Struct): |
| 129 | tags[STRUCT_SCHEMA_TAG] = _serialize_struct_schema(self.dtype) |
| 130 | elif isinstance(self.dtype, Array) and isinstance(self.dtype.base_type, Struct): |
| 131 | tags[STRUCT_SCHEMA_TAG] = _serialize_struct_schema(self.dtype.base_type) |
| 132 | # Persist nested collection type info in tags |
| 133 | if isinstance(self.dtype, (Array, Set)) and isinstance( |
| 134 | self.dtype.base_type, (Array, Set) |
| 135 | ): |
| 136 | tags[NESTED_COLLECTION_INNER_TYPE_TAG] = _feast_type_to_str(self.dtype) |
| 137 | return FieldProto( |
| 138 | name=self.name, |
| 139 | value_type=value_type.value, # type: ignore[arg-type] |
| 140 | description=self.description, |
| 141 | tags=tags, |
| 142 | vector_index=self.vector_index, |
| 143 | vector_length=self.vector_length, |
| 144 | vector_search_metric=vector_search_metric, |
| 145 | ) |
| 146 | |
| 147 | @classmethod |
| 148 | def from_proto(cls, field_proto: FieldProto): |