Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/getting-started/concepts/feature-retrieval.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ training_df = store.get_historical_features(
If `start_date` is omitted, it defaults to `end_date` minus the feature view TTL. If `end_date` is omitted, it defaults to the current time. Point-in-time correctness is still preserved.

{% hint style="warning" %}
Entity-less retrieval is currently supported for the **Postgres**, **Dask**, **Spark**, **Ray**, and **Trino** offline stores. You cannot mix `entity_df` with `start_date`/`end_date` in the same call.
Entity-less retrieval is currently supported for the **Postgres**, **Dask**, **Spark**, **Ray**, **Trino**, and **MsSQL** offline stores. You cannot mix `entity_df` with `start_date`/`end_date` in the same call.
{% endhint %}

For more details, see the [FAQ](../faq.md#how-do-i-run-get_historical_features-without-providing-an-entity-dataframe) and [this blog post on entity-less historical feature retrieval](https://feast.dev/blog/entity-less-historical-features-retrieval/).
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Yes, this is possible. For example, you can use BigQuery as an offline store and

Feast does support fetching historical features without passing an entity dataframe with the request.

- **Supported offline stores:** Entity-less (entity dataframe–less) retrieval is supported for the **Postgres**, **Dask**, **Spark**, **Ray**, and **Trino** offline stores. Postgres was the first to support it; Dask, Spark, Ray, and Trino have followed. Other offline stores may be added based on priority and community demand.
- **Supported offline stores:** Entity-less (entity dataframe–less) retrieval is supported for the **Postgres**, **Dask**, **Spark**, **Ray**, **Trino**, and **MsSQL** offline stores. Postgres was the first to support it; Dask, Spark, Ray, Trino, and MsSQL have followed. Other offline stores may be added based on priority and community demand.
- **Date range:** Retrieval is controlled by the `start_date` and `end_date` parameters. Supported combinations:
- Both params given → data in the given start-to-end time range.
- Only `start_date` given → data from the start date to now.
Expand Down
1 change: 1 addition & 0 deletions docs/reference/offline-stores/mssql.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The MsSQL offline store provides support for reading [MsSQL Sources](../data-sources/mssql.md). Specifically, it is developed to read from [Synapse SQL](https://docs.microsoft.com/en-us/azure/synapse-analytics/sql/overview-features) on Microsoft Azure

* Entity dataframes can be provided as a SQL query or can be provided as a Pandas dataframe.
* Historical features can also be retrieved without an entity dataframe by passing `start_date` and/or `end_date` to `get_historical_features`. Every entity key with an event between `start_date` and `end_date` is joined as of `end_date`, so each entity gets its latest feature values within the feature view TTL. See [entity-less retrieval](../../getting-started/concepts/feature-retrieval.md) for details.

## Getting started
In order to use this offline store, you'll need to run `pip install 'feast[azure]'`. You can get started by then following this [tutorial](https://github.com/feast-dev/feast/blob/master/docs/tutorials/azure/README.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
MsSqlServerSource,
)
from feast.infra.offline_stores.ibis import (
build_entity_df_for_date_range_ibis,
get_historical_features_ibis,
offline_write_batch_ibis,
pull_all_from_table_or_query_ibis,
Expand All @@ -25,6 +26,7 @@
from feast.infra.offline_stores.offline_store import OfflineStore, RetrievalJob
from feast.infra.registry.base_registry import BaseRegistry
from feast.repo_config import FeastConfigBaseModel, RepoConfig
from feast.utils import compute_non_entity_date_range


def get_ibis_connection(config: RepoConfig):
Expand Down Expand Up @@ -79,7 +81,7 @@ def get_table_column_names_and_types(
def _build_data_source_reader(config: RepoConfig):
con = get_ibis_connection(config)

def _read_data_source(data_source: DataSource) -> Table:
def _read_data_source(data_source: DataSource, repo_path: str = "") -> Table:
assert isinstance(data_source, MsSqlServerSource)
return con.table(data_source.table_ref)

Expand All @@ -92,6 +94,7 @@ def _build_data_source_writer(config: RepoConfig):
def _write_data_source(
table: Table,
data_source: DataSource,
repo_path: str = "",
mode: str = "append",
allow_overwrite: bool = False,
):
Expand Down Expand Up @@ -149,14 +152,30 @@ def get_historical_features(
config: RepoConfig,
feature_views: List[FeatureView],
feature_refs: List[str],
entity_df: Union[pd.DataFrame, str],
entity_df: Optional[Union[pd.DataFrame, str]],
registry: BaseRegistry,
project: str,
full_feature_names: bool = False,
filter_by_created_timestamp: bool = False,
**kwargs: Any,
) -> RetrievalJob:
if entity_df is None:
# Non-entity mode: join every entity key with an event in the time
# range as of end_date, so it gets its latest values within the TTL.
start_date, end_date = compute_non_entity_date_range(
feature_views,
start_date=kwargs.get("start_date"),
end_date=kwargs.get("end_date"),
)
entity_df = build_entity_df_for_date_range_ibis(
config=config,
feature_views=feature_views,
start_date=start_date,
end_date=end_date,
data_source_reader=_build_data_source_reader(config),
)
# TODO avoid this conversion
if type(entity_df) == str:
elif type(entity_df) == str:
con = get_ibis_connection(config)
entity_df = con.sql(entity_df).execute()

Expand Down
90 changes: 90 additions & 0 deletions sdk/python/feast/infra/offline_stores/ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from feast.on_demand_feature_view import OnDemandFeatureView
from feast.repo_config import RepoConfig
from feast.saved_dataset import SavedDatasetStorage
from feast.utils import make_tzaware


def read_mlflow_data_source(data_source: DataSource) -> Optional[Table]:
Expand Down Expand Up @@ -207,6 +208,95 @@ def _generate_row_id(
return entity_table


def build_entity_df_for_date_range_ibis(
config: RepoConfig,
feature_views: List[FeatureView],
start_date: datetime,
end_date: datetime,
data_source_reader: Callable[[DataSource, str], Table],
event_timestamp_col: str = offline_utils.DEFAULT_ENTITY_DF_EVENT_TIMESTAMP_COL,
) -> pd.DataFrame:
"""Build the entity dataframe that stands in for entity_df in non-entity mode.

It holds the distinct join keys of every feature view with entities whose source
has events between start_date and end_date, with NULL for the join keys a feature
view does not have, and end_date as the event timestamp of every row, so each
entity gets its latest feature values within the TTL. Feature views without
entities join on the timestamp alone, so they do not contribute rows. When no
feature view has entities, the dataframe is a single row holding end_date.

The keys are collected in one query, so data_source_reader must read every
source from the same backend.
"""
start_date = make_tzaware(start_date).astimezone(tz=timezone.utc)
end_date = make_tzaware(end_date).astimezone(tz=timezone.utc)
start_literal = ibis.literal(start_date.replace(tzinfo=None))
end_literal = ibis.literal(end_date.replace(tzinfo=None))

key_tables: List[Table] = []
for feature_view in feature_views:
join_key_map = _join_key_map(feature_view)
if not join_key_map:
continue
if feature_view.batch_source is None:
raise ValueError(
f"Feature view '{feature_view.name}' has no batch_source and cannot be queried."
)

table = data_source_reader(feature_view.batch_source, str(config.repo_path))
for old_name, new_name in feature_view.batch_source.field_mapping.items():
if old_name in table.columns:
table = table.rename({new_name: old_name})

timestamp = _comparable_timestamp(
table[feature_view.batch_source.timestamp_field]
)
table = table.filter(timestamp >= start_literal, timestamp <= end_literal)
key_tables.append(
table.select(
**{
entity_column: table[join_key]
for join_key, entity_column in join_key_map.items()
}
)
)

if not key_tables:
return pd.DataFrame({event_timestamp_col: [pd.Timestamp(end_date)]})

# A union needs the same columns and types in every table, so each key table
# gets every join key, cast to the common type of all its occurrences or NULL,
# so the result does not depend on the order of the feature views.
key_types: Dict[str, List[dt.DataType]] = {}
for key_table in key_tables:
for column, column_type in key_table.schema().items():
key_types.setdefault(column, []).append(column_type)
join_key_types: Dict[str, dt.DataType] = {
column: dt.highest_precedence(column_types)
for column, column_types in key_types.items()
}

entity_table = ibis.union(
*[
key_table.select(
**{
column: key_table[column].cast(column_type)
if column in key_table.columns
else ibis.null(column_type)
for column, column_type in join_key_types.items()
}
)
for key_table in key_tables
]
).distinct()

entity_df = entity_table.execute()
entity_df[event_timestamp_col] = pd.Series(
pd.Timestamp(end_date), index=entity_df.index, dtype="datetime64[ns, UTC]"
)
return entity_df


def get_historical_features_ibis(
config: RepoConfig,
feature_views: List[FeatureView],
Expand Down
Loading
Loading