Skip to content

OnlineResponse.to_arrow() returns a null-typed column when a feature is missing for every requested entity #7248

Backlog

Description

@mansur-akhmadi

Expected Behavior

OnlineResponse.to_arrow() returns the same Arrow type for a feature on every call, whether or not the requested entities have a value for it.

Current Behavior

to_arrow() is pa.Table.from_pydict(self.to_dict()), so the column type is inferred from the returned values. When none of the requested entities has the feature in the online store (or the request has zero rows), every value is None and the column comes back as Arrow null:

# entity 1001 is materialized, 9999 is not
store.get_online_features(features=["driver_hourly_stats:conv_rate", "driver_hourly_stats:avg_daily_trips"],
                          entity_rows=[{"driver_id": 1001}]).to_arrow().schema
driver_id: int64
avg_daily_trips: int64
conv_rate: double

store.get_online_features(features=[...same...], entity_rows=[{"driver_id": 9999}]).to_arrow().schema
driver_id: int64
avg_daily_trips: null
conv_rate: null

So the schema of a serving batch depends on the data in it. Concatenating batches (pa.concat_tables) fails with a schema mismatch, and code that casts or validates the Arrow schema before feeding a model breaks on the batches where a feature happens to be missing for everyone, typically small batches of new entities.

Steps to reproduce

feast init demo && cd demo/feature_repo && feast apply && feast materialize-incremental <now>, then run the two calls above (any driver_id that is not in the data gives the null columns).

Specifications

  • Version: master (f2abc7c)
  • Platform: macOS, Python 3.12
  • Subsystem: Python SDK, OnlineResponse.to_arrow()

Possible Solution

OnlineResponse already gets the requested features' value types (feature_types). When every value of a feature is missing, the column can be built with the Arrow type that to_arrow() infers for that value type when values are present (Int32/Int64 -> int64, Float32/Float64 -> double, String -> string, lists likewise), so the schema stays the same and columns with values are not affected. I have a PR for this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions