Skip to content

Writing to a singleton Python ODFV with write_to_online_store=True fails for scalar outputs and filtered dataframes #7204

Open

Description

@MaiAditya

Expected behavior

store.write_to_online_store(...) (and push with transform_on_write) for an on demand feature view with mode="python", singleton=True and write_to_online_store=True runs the UDF once per input row and writes the result for every row. #7151 fixed the same first-row-only behaviour for online reads; this is the write side.

Current behavior

FeatureStore._transform_on_demand_feature_view_df keeps the first UDF output as-is and appends the later outputs to it:

  • A UDF that returns scalars (the UDF shape of the singleton example in docs/reference/beta-on-demand-feature-view.md, there used at read time) fails on every write. One row raises ValueError: If using all scalar values, you must pass an index; two or more rows raise AttributeError: 'float' object has no attribute 'append'.
  • The first row is chosen by index label (if i == 0), so a filtered dataframe whose index does not contain 0 raises TypeError: list indices must be integers or slices, not str, even for UDFs that return lists (the docling/PDF chunking pattern).
  • Input columns are taken from the first input row only (df.to_dict(orient="records")[0]), and dropped entirely when the UDF returns more than one row.

Steps to reproduce

import os, tempfile
from typing import Any
import pandas as pd
from feast import Entity, FeatureStore, Field, RepoConfig, RequestSource
from feast.on_demand_feature_view import on_demand_feature_view
from feast.types import Float64, Int64
from feast.value_type import ValueType

d = tempfile.mkdtemp()
store = FeatureStore(config=RepoConfig(
    project="p", registry=os.path.join(d, "reg.db"), provider="local",
    online_store={"type": "sqlite", "path": os.path.join(d, "o.db")},
    entity_key_serialization_version=3))
driver = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64)
req = RequestSource(name="req", schema=[
    Field(name="driver_id", dtype=Int64),
    Field(name="conv_rate", dtype=Float64),
    Field(name="acc_rate", dtype=Float64)])

@on_demand_feature_view(
    entities=[driver], sources=[req],
    schema=[Field(name="driver_id", dtype=Int64), Field(name="score", dtype=Float64)],
    mode="python", write_to_online_store=True, singleton=True)
def score_view(inputs: dict[str, Any]) -> dict[str, Any]:
    return {"score": inputs["conv_rate"] + inputs["acc_rate"]}

store.apply([driver, score_view])
df = pd.DataFrame({"driver_id": [1, 2, 3], "conv_rate": [0.1, 0.2, 0.3], "acc_rate": [1.0, 2.0, 3.0]})
store.write_to_online_store("score_view", df)            # AttributeError
store.write_to_online_store("score_view", df.iloc[1:])   # TypeError
store.write_to_online_store("score_view", df.iloc[:1])   # ValueError

Specifications

  • Version: master (39598f5)
  • Platform: macOS, Python 3.11
  • Subsystem: on demand feature views, transform on write

I have a fix with tests ready and will open a PR.

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