Skip to content

get_historical_features on DuckDB fails for features whose name ends in "_y" #7165

Closed

Description

@iammanoj807

Expected Behavior

get_historical_features returns every requested feature, whatever its name. The file offline store does.

Current Behavior

With the DuckDB offline store, a feature whose output column ends in _y makes get_historical_features fail. For example pos_y, or a feature named y with full_feature_names=True:

IbisTypeError: Column 'pos_y' is not found in table. Existing columns: 'driver_id', 'event_timestamp', 'pos_x', 'event_expire_timestamp', 'entity_row_id'.

Other names fail in the same code:

  • A batch source whose timestamp or created-timestamp column ends in _y fails the same way (Column 'ts_y' is not found in table).
  • A batch source column named after a join key or the timestamp column plus _y (e.g. driver_id_y, event_timestamp_y) fails with IntegrityError: Name collisions: {'event_timestamp_y'}. This happens even when that column is not one of the requested features.

Steps to reproduce

import tempfile
from datetime import timedelta
from pathlib import Path

import pandas as pd

from feast import Entity, FeatureStore, FeatureView, Field, FileSource, RepoConfig
from feast.types import Float64
from feast.value_type import ValueType

repo = Path(tempfile.mkdtemp())
pd.DataFrame(
    {
        "driver_id": [1, 2],
        "event_timestamp": pd.to_datetime(["2024-01-01", "2024-01-01"], utc=True),
        "pos_x": [1.5, 2.5],
        "pos_y": [7.5, 8.5],
    }
).to_parquet(repo / "positions.parquet")

driver = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64)
positions = FeatureView(
    name="driver_positions",
    entities=[driver],
    schema=[Field(name="pos_x", dtype=Float64), Field(name="pos_y", dtype=Float64)],
    source=FileSource(path=str(repo / "positions.parquet"), timestamp_field="event_timestamp"),
    ttl=timedelta(days=1),
)
entity_df = pd.DataFrame(
    {
        "driver_id": [1, 2],
        "event_timestamp": pd.to_datetime(["2024-01-01 12:00", "2024-01-01 12:00"], utc=True),
    }
)

for offline_store in ["file", "duckdb"]:
    store = FeatureStore(
        config=RepoConfig(
            project="repro",
            provider="local",
            registry=str(repo / f"registry_{offline_store}.db"),
            offline_store={"type": offline_store},
            online_store={"type": "sqlite", "path": str(repo / "online.db")},
            entity_key_serialization_version=3,
            repo_path=str(repo),
        )
    )
    store.apply([driver, positions])
    print(f"# {offline_store}")
    try:
        df = store.get_historical_features(
            entity_df=entity_df,
            features=["driver_positions:pos_x", "driver_positions:pos_y"],
        ).to_df()
        print(df[["driver_id", "pos_x", "pos_y"]].to_string(index=False))
    except Exception as e:
        print(f"{type(e).__name__}: {e}")

Output on master (f2991a1) and on 0.68.0 from PyPI:

# file
 driver_id  pos_x  pos_y
         1    1.5    7.5
         2    2.5    8.5
# duckdb
IbisTypeError: Column 'pos_y' is not found in table. Existing columns: 'driver_id', 'event_timestamp', 'pos_x', 'event_expire_timestamp', 'entity_row_id'.

Specifications

  • Version: master (f2991a1) and 0.68.0
  • Platform: macOS, Python 3.12, DuckDB 2.0.0, ibis 12.0.0
  • Subsystem: offline store, ibis point-in-time join (the DuckDB store; the contrib Oracle and MSSQL stores use the same code)

Possible Solution

point_in_time_join in infra/offline_stores/ibis.py joins the feature data with the entity data using rname="{name}_y". Right after the join it drops every column whose name ends in _y:

cols_to_drop_y = [c for c in feature_table.columns if c.endswith("_y")]
feature_table = feature_table.drop(*cols_to_drop_y)

This is meant for the copies the join makes of entity columns that clash with feature-table columns (such as event_timestamp_y). It also drops real features, timestamps and created columns whose names end in _y.

A fix: select entity_row_id from the entity table, and the timestamp, created and feature columns from the feature table, instead of dropping by name. #5847 did the same for the _yyyy copies after the second join. I have a PR ready with a regression test.

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