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

Class Struct

sdk/python/feast/types.py:263–307  ·  view source on GitHub ↗

A Struct represents a structured type with named, typed fields. Attributes: fields: A dictionary mapping field names to their FeastTypes.

Source from the content-addressed store, hash-verified

261
262
263class Struct(ComplexFeastType):
264 """
265 A Struct represents a structured type with named, typed fields.
266
267 Attributes:
268 fields: A dictionary mapping field names to their FeastTypes.
269 """
270
271 fields: Dict[str, Union[PrimitiveFeastType, "ComplexFeastType"]]
272
273 def __init__(
274 self, fields: Dict[str, Union[PrimitiveFeastType, "ComplexFeastType"]]
275 ):
276 if not fields:
277 raise ValueError("Struct must have at least one field.")
278 self.fields = fields
279
280 def to_value_type(self) -> ValueType:
281 return ValueType.STRUCT
282
283 def to_pyarrow_type(self) -> pyarrow.DataType:
284 pa_fields = []
285 for name, feast_type in self.fields.items():
286 pa_type = from_feast_to_pyarrow_type(feast_type)
287 pa_fields.append(pyarrow.field(name, pa_type))
288 return pyarrow.struct(pa_fields)
289
290 def __str__(self):
291 field_strs = ", ".join(
292 f"{name}: {ftype}" for name, ftype in self.fields.items()
293 )
294 return f"Struct({{{field_strs}}})"
295
296 def __eq__(self, other):
297 if isinstance(other, Struct):
298 return self.fields == other.fields
299 return False
300
301 def __hash__(self):
302 return hash(
303 (
304 "Struct",
305 tuple((k, hash(v)) for k, v in sorted(self.fields.items())),
306 )
307 )
308
309
310FeastType = Union[ComplexFeastType, PrimitiveFeastType]

Calls

no outgoing calls