Repository navigation
Open
Description
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 raisesValueError: If using all scalar values, you must pass an index; two or more rows raiseAttributeError: '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 contain0raisesTypeError: 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]) # ValueErrorSpecifications
- 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.
Metadata
Metadata
Assignees
Labels
No labels
Activity