Type System
Motivation
Feast uses an internal type system to provide guarantees on training and serving data. Feast supports primitive types, array types, and map types for feature values. Null types are not supported, although the UNIX_TIMESTAMP type is nullable. The type system is controlled by Value.proto in protobuf and by types.py in Python. Type conversion logic can be found in type_map.py.
Supported Types
Feast supports the following data types:
Primitive Types
Int32
int
32-bit signed integer
Int64
int
64-bit signed integer
Float32
float
32-bit floating point
Float64
float
64-bit floating point
String
str
String/text value
Bytes
bytes
Binary data
Bool
bool
Boolean value
UnixTimestamp
datetime
Unix timestamp (nullable)
Array Types
All primitive types have corresponding array (list) types:
Array(Int32)
List[int]
List of 32-bit integers
Array(Int64)
List[int]
List of 64-bit integers
Array(Float32)
List[float]
List of 32-bit floats
Array(Float64)
List[float]
List of 64-bit floats
Array(String)
List[str]
List of strings
Array(Bytes)
List[bytes]
List of binary data
Array(Bool)
List[bool]
List of booleans
Array(UnixTimestamp)
List[datetime]
List of timestamps
Map Types
Map types allow storing dictionary-like data structures:
Map
Dict[str, Any]
Dictionary with string keys and any supported Feast type as values (including nested maps)
Array(Map)
List[Dict[str, Any]]
List of dictionaries
Note: Map keys must always be strings. Map values can be any supported Feast type, including primitives, arrays, or nested maps.
Complete Feature View Example
Below is a complete example showing how to define a feature view with all supported types:
Map Type Usage Examples
Maps can store complex nested data structures:
Type System in Practice
The sections below explain how Feast uses its type system in different contexts.
Feature inference
During feast apply, Feast runs schema inference on the data sources underlying feature views. For example, if the schema parameter is not specified for a feature view, Feast will examine the schema of the underlying data source to determine the event timestamp column, feature columns, and entity columns. Each of these columns must be associated with a Feast type, which requires conversion from the data source type system to the Feast type system.
The feature inference logic calls
_infer_features_and_entities._infer_features_and_entitiescallssource_datatype_to_feast_value_type.source_datatype_to_feast_value_typecals the appropriate method intype_map.py. For example, if aSnowflakeSourceis being examined,snowflake_python_type_to_feast_value_typefromtype_map.pywill be called.
Materialization
Feast serves feature values as Value proto objects, which have a type corresponding to Feast types. Thus Feast must materialize feature values into the online store as Value proto objects.
The local materialization engine first pulls the latest historical features and converts it to pyarrow.
Then it calls
_convert_arrow_to_prototo convert the pyarrow table to proto format.This calls
python_values_to_proto_valuesintype_map.pyto perform the type conversion.
Historical feature retrieval
The Feast type system is typically not necessary when retrieving historical features. A call to get_historical_features will return a RetrievalJob object, which allows the user to export the results to one of several possible locations: a Pandas dataframe, a pyarrow table, a data lake (e.g. S3 or GCS), or the offline store (e.g. a Snowflake table). In all of these cases, the type conversion is handled natively by the offline store. For example, a BigQuery query exposes a to_dataframe method that will automatically convert the result to a dataframe, without requiring any conversions within Feast.
Feature serving
As mentioned above in the section on materialization, Feast persists feature values into the online store as Value proto objects. A call to get_online_features will return an OnlineResponse object, which essentially wraps a bunch of Value protos with some metadata. The OnlineResponse object can then be converted into a Python dictionary, which calls feast_value_type_to_python_type from type_map.py, a utility that converts the Feast internal types to Python native types.
Last updated
Was this helpful?