diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index d3338d797fa..a76f593b643 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -166,6 +166,7 @@ * [\[Alpha\] Vector Database](reference/alpha-vector-database.md) * [\[Alpha\] Data quality monitoring](reference/dqm.md) * [\[Alpha\] Streaming feature computation with Denormalized](reference/denormalized.md) +* [\[Alpha\] Feature View Versioning](reference/alpha-feature-view-versioning.md) * [OpenLineage Integration](reference/openlineage.md) * [Feast CLI reference](reference/feast-cli-commands.md) * [Python API reference](http://rtd.feast.dev) diff --git a/docs/getting-started/concepts/feature-retrieval.md b/docs/getting-started/concepts/feature-retrieval.md index 867e17848b0..4ed310e2572 100644 --- a/docs/getting-started/concepts/feature-retrieval.md +++ b/docs/getting-started/concepts/feature-retrieval.md @@ -78,15 +78,19 @@ feature_store.get_historical_features(features=feature_service, entity_df=entity This mechanism of retrieving features is only recommended as you're experimenting. Once you want to launch experiments or serve models, feature services are recommended. -Feature references uniquely identify feature values in Feast. The structure of a feature reference in string form is as follows: `:` +Feature references uniquely identify feature values in Feast. The structure of a feature reference in string form is as follows: `[@version]:` + +The `@version` part is optional. When omitted, the latest (active) version is used. You can specify a version like `@v2` to read from a specific historical version snapshot. Feature references are used for the retrieval of features from Feast: ```python online_features = fs.get_online_features( features=[ - 'driver_locations:lon', - 'drivers_activity:trips_today' + 'driver_locations:lon', # latest version (default) + 'drivers_activity:trips_today', # latest version (default) + 'drivers_activity@v2:trips_today', # specific version + 'drivers_activity@latest:trips_today', # explicit latest ], entity_rows=[ # {join_key: entity_value} @@ -95,6 +99,10 @@ online_features = fs.get_online_features( ) ``` +{% hint style="info" %} +Version-qualified reads (`@v`) require `enable_online_feature_view_versioning: true` in your registry config and are currently supported only on the SQLite online store. See the [feature view versioning docs](feature-view.md#version-qualified-feature-references) for details. +{% endhint %} + It is possible to retrieve features from multiple feature views with a single request, and Feast is able to join features from multiple tables in order to build a training dataset. However, it is not possible to reference (or retrieve) features from multiple projects at the same time. {% hint style="info" %} diff --git a/docs/getting-started/concepts/feature-view.md b/docs/getting-started/concepts/feature-view.md index 4ea007a1f91..ee70d5024dd 100644 --- a/docs/getting-started/concepts/feature-view.md +++ b/docs/getting-started/concepts/feature-view.md @@ -160,6 +160,25 @@ Feature names must be unique within a [feature view](feature-view.md#feature-vie Each field can have additional metadata associated with it, specified as key-value [tags](https://rtd.feast.dev/en/master/feast.html#feast.field.Field). +## \[Alpha\] Versioning + +Feature views support automatic version tracking. Every time `feast apply` detects a schema or UDF change, a versioned snapshot is saved to the registry. This enables auditing what changed, reverting to a prior version, querying specific versions via `@v` syntax, and staging new versions without promoting them. + +Version history tracking is **always active** with no configuration needed. The `version` parameter is fully optional — omitting it preserves existing behavior. + +```python +# Pin to a specific version (reverts the active definition to v2's snapshot) +driver_stats = FeatureView( + name="driver_stats", + entities=[driver], + schema=[...], + source=my_source, + version="v2", +) +``` + +For full details on version pinning, version-qualified reads, staged publishing (`--no-promote`), online store support, and known limitations, see the **[\[Alpha\] Feature View Versioning](../../reference/alpha-feature-view-versioning.md)** reference page. + ## Schema Validation Feature views support an optional `enable_validation` parameter that enables schema validation during materialization and historical feature retrieval. When enabled, Feast verifies that: diff --git a/docs/how-to-guides/feast-snowflake-gcp-aws/build-a-training-dataset.md b/docs/how-to-guides/feast-snowflake-gcp-aws/build-a-training-dataset.md index 97b3ad2cf5e..6cee21ecaf6 100644 --- a/docs/how-to-guides/feast-snowflake-gcp-aws/build-a-training-dataset.md +++ b/docs/how-to-guides/feast-snowflake-gcp-aws/build-a-training-dataset.md @@ -20,6 +20,7 @@ feature_refs = [ "driver_trips:maximum_daily_rides", "driver_trips:rating", "driver_trips:rating:trip_completed", + # Optionally, reference a specific version: "driver_trips@v2:average_daily_rides" ] ``` diff --git a/docs/how-to-guides/feast-snowflake-gcp-aws/read-features-from-the-online-store.md b/docs/how-to-guides/feast-snowflake-gcp-aws/read-features-from-the-online-store.md index 7b0a46239b2..f8c492e4ae8 100644 --- a/docs/how-to-guides/feast-snowflake-gcp-aws/read-features-from-the-online-store.md +++ b/docs/how-to-guides/feast-snowflake-gcp-aws/read-features-from-the-online-store.md @@ -21,7 +21,9 @@ Create a list of features that you would like to retrieve. This list typically c ```python features = [ "driver_hourly_stats:conv_rate", - "driver_hourly_stats:acc_rate" + "driver_hourly_stats:acc_rate", + # Optionally, reference a specific version (requires enable_online_feature_view_versioning): + # "driver_hourly_stats@v2:conv_rate" ] ``` diff --git a/docs/reference/alpha-feature-view-versioning.md b/docs/reference/alpha-feature-view-versioning.md new file mode 100644 index 00000000000..fbfc733afc6 --- /dev/null +++ b/docs/reference/alpha-feature-view-versioning.md @@ -0,0 +1,229 @@ +# \[Alpha\] Feature View Versioning + +{% hint style="warning" %} +**Warning**: This is an _experimental_ feature. It is stable but there are still rough edges. Contributions are welcome! +{% endhint %} + +## Overview + +Feature view versioning automatically tracks schema and UDF changes to feature views. Every time `feast apply` detects a change, a versioned snapshot is saved to the registry. This enables: + +- **Audit trail** — see what a feature view looked like at any point in time +- **Safe rollback** — pin serving to a prior version with `version="v0"` in your definition +- **Multi-version serving** — serve both old and new schemas simultaneously using `@v` syntax +- **Staged publishing** — use `feast apply --no-promote` to publish a new version without making it the default + +## How It Works + +Version tracking is fully automatic. You don't need to set any version parameter — just use `feast apply` as usual: + +1. **First apply** — Your feature view definition is saved as **v0**. +2. **Change something and re-apply** — Feast detects the change, saves the old definition as a snapshot, and saves the new one as **v1**. The version number auto-increments on each real change. +3. **Re-apply without changes** — Nothing happens. Feast compares the new definition against the active one and skips creating a version if they're identical (idempotent). +4. **Another change** — Creates **v2**, and so on. + +``` +feast apply # First apply → v0 +# ... edit schema ... +feast apply # Detects change → v1 +feast apply # No change detected → still v1 (no new version) +# ... edit source ... +feast apply # Detects change → v2 +``` + +**Key details:** + +* **Automatic snapshots**: Versions are created only when Feast detects an actual change to the feature view definition (schema or UDF). Metadata-only changes (description, tags, TTL) update in place without creating a new version. +* **Separate history storage**: Version history is stored separately from the active feature view definition, keeping the main registry lightweight. +* **Backward compatible**: The `version` parameter is fully optional. Omitting it (or setting `version="latest"`) preserves existing behavior — you get automatic versioning with zero changes to your code. + +## Configuration + +{% hint style="info" %} +Version history tracking is **always active** — no configuration needed. Every `feast apply` that changes a feature view automatically records a version snapshot. + +To enable **versioned online reads** (e.g., `fv@v2:feature`), add `enable_online_feature_view_versioning: true` to your registry config in `feature_store.yaml`: + +```yaml +registry: + path: data/registry.db + enable_online_feature_view_versioning: true +``` + +When this flag is off, version-qualified refs (e.g., `fv@v2:feature`) in online reads will raise errors, but version history, version listing, version pinning, and version lookups all work normally. +{% endhint %} + +## Pinning to a Specific Version + +You can pin a feature view to a specific historical version by setting the `version` parameter. When pinned, `feast apply` replaces the active feature view with the snapshot from that version. This is useful for reverting to a known-good definition. + +```python +from feast import FeatureView + +# Default behavior: always use the latest version (auto-increments on changes) +driver_stats = FeatureView( + name="driver_stats", + entities=[driver], + schema=[...], + source=my_source, +) + +# Pin to a specific version (reverts the active definition to v2's snapshot) +driver_stats = FeatureView( + name="driver_stats", + entities=[driver], + schema=[...], + source=my_source, + version="v2", # also accepts "version2" +) +``` + +When pinning, the feature view definition (schema, source, transformations, etc.) must match the currently active definition. If you've also modified the definition alongside the pin, `feast apply` will raise a `FeatureViewPinConflict` error. To apply changes, use `version="latest"`. To revert, only change the `version` parameter. + +The snapshot's content replaces the active feature view. Version history is not modified by a pin; the existing v0, v1, v2, etc. snapshots remain intact. + +After reverting with a pin, you can go back to normal auto-incrementing behavior by removing the `version` parameter (or setting it to `"latest"`) and running `feast apply` again. If the restored definition differs from the pinned snapshot, a new version will be created. + +### Version string formats + +| Format | Meaning | +|--------|---------| +| `"latest"` (or omitted) | Always use the latest version (auto-increments on changes) | +| `"v0"`, `"v1"`, `"v2"`, ... | Pin to a specific version number | +| `"version0"`, `"version1"`, ... | Equivalent long form (case-insensitive) | + +## Staged Publishing (`--no-promote`) + +By default, `feast apply` atomically saves a version snapshot **and** promotes it to the active definition. For breaking schema changes, you may want to stage the new version without disrupting unversioned consumers. + +The `--no-promote` flag saves the version snapshot without updating the active feature view definition. The new version is accessible only via explicit `@v` reads and `--version` materialization. + +**CLI usage:** + +```bash +feast apply --no-promote +``` + +**Python SDK equivalent:** + +```python +store.apply([entity, feature_view], no_promote=True) +``` + +### Phased rollout workflow + +1. **Stage the new version:** + ```bash + feast apply --no-promote + ``` + This publishes v2 without promoting it. All unversioned consumers continue using v1. + +2. **Populate the v2 online table:** + ```bash + feast materialize --views driver_stats --version v2 ... + ``` + +3. **Migrate consumers one at a time:** + - Consumer A switches to `driver_stats@v2:trips_today` + - Consumer B switches to `driver_stats@v2:avg_rating` + +4. **Promote v2 as the default:** + ```bash + feast apply + ``` + Or pin to v2: set `version="v2"` in the definition and run `feast apply`. + +## Listing Version History + +Use the CLI to inspect version history: + +```bash +feast feature-views list-versions driver_stats +``` + +```text +VERSION TYPE CREATED VERSION_ID +v0 feature_view 2024-01-15 10:30:00 a1b2c3d4-... +v1 feature_view 2024-01-16 14:22:00 e5f6g7h8-... +v2 feature_view 2024-01-20 09:15:00 i9j0k1l2-... +``` + +Or programmatically via the Python SDK: + +```python +store = FeatureStore(repo_path=".") +versions = store.list_feature_view_versions("driver_stats") +for v in versions: + print(f"{v['version']} created at {v['created_timestamp']}") +``` + +## Version-Qualified Feature References + +You can read features from a **specific version** of a feature view by using version-qualified feature references with the `@v` syntax: + +```python +online_features = store.get_online_features( + features=[ + "driver_stats:trips_today", # latest version (default) + "driver_stats@v2:trips_today", # specific version + "driver_stats@latest:trips_today", # explicit latest + ], + entity_rows=[{"driver_id": 1001}], +) +``` + +**How it works:** + +* `driver_stats:trips_today` is equivalent to `driver_stats@latest:trips_today` — it reads from the currently active version +* `driver_stats@v2:trips_today` reads from the v2 snapshot stored in version history, using a version-specific online store table +* Multiple versions of the same feature view can be queried in a single request (e.g., `driver_stats@v1:trips` and `driver_stats@v2:trips_daily`) + +**Backward compatibility:** + +* The unversioned online store table (e.g., `project_driver_stats`) is treated as v0 +* Only versions >= 1 get `_v{N}` suffixed tables (e.g., `project_driver_stats_v1`) +* Pre-versioning users' existing data continues to work without changes — `@latest` resolves to the active version, which for existing unversioned FVs is v0 + +**Materialization:** Each version requires its own materialization. After applying a new version, run `feast materialize` to populate the versioned table before querying it with `@v`. + +## Supported Feature View Types + +Versioning is supported on all three feature view types: + +* `FeatureView` (and `BatchFeatureView`) +* `StreamFeatureView` +* `OnDemandFeatureView` + +## Online Store Support + +{% hint style="info" %} +**Currently, version-qualified online reads (`@v`) are only supported with the SQLite online store.** Support for additional online stores (Redis, DynamoDB, Bigtable, Postgres, etc.) will be added based on community priority. + +If you need versioned online reads for a specific online store, please [open a GitHub issue](https://github.com/feast-dev/feast/issues/new) describing your use case and which store you need. This helps us prioritize development. +{% endhint %} + +Version history tracking in the registry (listing versions, pinning, `--no-promote`) works with **all** registry backends (file, SQL, Snowflake). + +## Full Details + +For the complete design, concurrency semantics, and feature service interactions, see the [Feature View Versioning RFC](../rfcs/feature-view-versioning.md). + +## Naming Restrictions + +Feature references use a structured format: `feature_view_name@v:feature_name`. To avoid +ambiguity, the following characters are reserved and must not appear in feature view or feature names: + +- **`@`** — Reserved as the version delimiter (e.g., `driver_stats@v2:trips_today`). `feast apply` + will reject feature views with `@` in their name. If you have existing feature views with `@` in + their names, they will continue to work for unversioned reads, but we recommend renaming them to + avoid ambiguity with the `@v` syntax. +- **`:`** — Reserved as the separator between feature view name and feature name in fully qualified + feature references (e.g., `driver_stats:trips_today`). + +## Known Limitations + +- **Online store coverage** — Version-qualified reads (`@v`) are SQLite-only today. Other online stores are follow-up work. +- **Offline store versioning** — Versioned historical retrieval is not yet supported. +- **Version deletion** — There is no mechanism to prune old versions from the registry. +- **Cross-version joins** — Joining features from different versions of the same feature view in `get_historical_features` is not supported. +- **Feature services** — Feature services always resolve to the active (promoted) version. `--no-promote` versions are not served until promoted. diff --git a/docs/reference/feast-cli-commands.md b/docs/reference/feast-cli-commands.md index eb6fa90d280..535065b5a98 100644 --- a/docs/reference/feast-cli-commands.md +++ b/docs/reference/feast-cli-commands.md @@ -176,6 +176,18 @@ NAME ENTITIES TYPE driver_hourly_stats {'driver'} FeatureView ``` +List version history for a feature view + +```text +feast feature-views list-versions FEATURE_VIEW_NAME +``` + +```text +VERSION TYPE CREATED VERSION_ID +v0 feature_view 2024-01-15 10:30:00 a1b2c3d4-... +v1 feature_view 2024-01-16 14:22:00 e5f6g7h8-... +``` + ## Init Creates a new feature repository diff --git a/docs/reference/registries/metadata.md b/docs/reference/registries/metadata.md index 575f2a5c8b7..371be9b5289 100644 --- a/docs/reference/registries/metadata.md +++ b/docs/reference/registries/metadata.md @@ -20,6 +20,7 @@ The metadata info of Feast `feature_store.yaml` is: | registry.warehouse | N | string | snowflake warehouse name | | registry.database | N | string | snowflake db name | | registry.schema | N | string | snowflake schema name | +| registry.enable_online_feature_view_versioning | N | boolean | enable versioned online store tables and version-qualified reads (default: false). Version history tracking is always active. | | online_store | Y | | | | offline_store | Y | NA | | | | offline_store.type | Y | string | storage type | diff --git a/docs/rfcs/feature-view-versioning.md b/docs/rfcs/feature-view-versioning.md new file mode 100644 index 00000000000..cb79c4dd265 --- /dev/null +++ b/docs/rfcs/feature-view-versioning.md @@ -0,0 +1,452 @@ +# RFC: Feature View Versioning + +**Status:** In Review +**Authors:** @farceo +**Branch:** `featureview-versioning` +**Date:** 2026-03-17 + +## Summary + +This RFC proposes adding automatic version tracking to Feast feature views. Every time `feast apply` detects a schema or UDF change to a feature view, a versioned snapshot is saved to the registry. Users can list version history, pin serving to a prior version, and optionally query specific versions at read time using `@v` syntax. + +## Motivation + +Today, when a feature view's schema changes, the old definition is silently overwritten. This creates several problems: + +1. **No audit trail.** Teams can't answer "what did this feature view look like last week?" or "who changed the schema and when?" +2. **No safe rollback.** If a schema change breaks a downstream model, there's no way to revert to the previous definition without manually reconstructing it. +3. **No multi-version serving.** During migrations, teams often need to serve both the old and new schema simultaneously (e.g., model A uses v1 features, model B uses v2 features). This is currently impossible without creating entirely separate feature views. + +## Diagrams + +### Lifecycle Flow + +Shows what happens during `feast apply` and `get_online_features`, and how version +history, pinning, and version-qualified reads fit together. + +``` + feast apply + | + v + +------------------------+ + | Compare new definition | + | against active FV | + +------------------------+ + | | + schema/UDF metadata only + changed changed + | | + v v + +--------------+ +------------------+ + | Save old as | | Update in place, | + | version N | | no new version | + | Save new as | +------------------+ + | version N+1 | + +--------------+ + | + +------------+------------+ + | | + v v + +----------------+ +-------------------+ + | Registry | | Online Store | + | (version | | (only if flag on) | + | history) | +-------------------+ + +----------------+ | + | +------+------+ + | | | + v v v + +----------------+ +--------+ +-----------+ + | feast versions | | proj_ | | proj_ | + | feast pin v2 | | fv | | fv_v1 | + | list / get | | (v0) | | fv_v2 ... | + +----------------+ +--------+ +-----------+ + Always available Unversioned Versioned + table tables + + + get_online_features + | + v + +---------------------+ + | Parse feature refs | + +---------------------+ + | | + "fv:feature" "fv@v2:feature" + (no version) (version-qualified) + | | + v v + +------------+ +------------------+ + | Read from | | flag enabled? | + | active FV | +------------------+ + | table | | | + +------------+ yes no + | | + v v + +------------+ +-------+ + | Look up v2 | | raise | + | snapshot, | | error | + | read from | +-------+ + | proj_fv_v2 | + +------------+ +``` + +### Architecture / Storage + +Shows how version data is stored in the registry and online store, and the +relationship between the active definition and historical snapshots. + +``` ++--feature_store.yaml------------------------------------------+ +| registry: | +| path: data/registry.db | +| enable_online_feature_view_versioning: true (optional) | ++--------------------------------------------------------------+ + | | + v v ++--Registry (file or SQL)--+ +--Online Store (SQLite, ...)---+ +| | | | +| Active Feature Views | | Unversioned tables (v0) | +| +--------------------+ | | +-------------------------+ | +| | driver_stats | | | | proj_driver_stats | | +| | version: latest | | | | driver_id | trips | . | | +| | current_ver: 2 | | | +-------------------------+ | +| | schema: [...] | | | | +| +--------------------+ | | Versioned tables (v1+) | +| | | +-------------------------+ | +| Version History | | | proj_driver_stats_v1 | | +| +--------------------+ | | | driver_id | trips | . | | +| | v0: proto snapshot | | | +-------------------------+ | +| | created: Jan 15 | | | +-------------------------+ | +| | v1: proto snapshot | | | | proj_driver_stats_v2 | | +| | created: Jan 16 | | | | driver_id | trips | . | | +| | v2: proto snapshot | | | +-------------------------+ | +| | created: Jan 20 | | | | +| +--------------------+ | +-------------------------------+ +| | +| Always active. | Only created when flag is on +| No flag needed. | and feast materialize is run. ++--------------------------+ +``` + +## Design + +### Core Concepts + +- **Version number**: An auto-incrementing integer (v0, v1, v2, ...) assigned to each schema-significant change. +- **Version snapshot**: A serialized copy of the full feature view proto at that version, stored in the registry's version history table. +- **Version pin**: Setting `version="v2"` on a feature view replaces the active definition with the v2 snapshot — essentially a revert. +- **Version-qualified ref**: The `@v` syntax in feature references (e.g., `driver_stats@v2:trips_today`) for reading from a specific version's online store table. + +### What Triggers a New Version + +Only **schema and UDF changes** create new versions. Metadata-only changes (description, tags, owner, TTL, online/offline flags) update the active definition in place without creating a version. + +Schema-significant changes include: +- Adding, removing, or retyping feature columns +- Changing entities or entity columns +- Changing the UDF code (StreamFeatureView, OnDemandFeatureView) + +This keeps version history meaningful — a new version number always means a real structural change. + +### What Does NOT Trigger a New Version + +- Re-applying an identical definition (idempotent) +- Changing `description`, `tags`, `owner` +- Changing `ttl`, `online`, `offline` flags +- Changing data source paths/locations (treated as deployment config) + +### Version History Is Always-On + +Version history tracking is lightweight registry metadata — just a serialized proto snapshot per version. There is no performance cost to the online path and no additional infrastructure required. For this reason, version history is **always active** with no opt-in flag needed. + +Out of the box, every `feast apply` that changes a feature view will: +- Record a version snapshot +- Support `feast feature-views list-versions ` to list history +- Support `registry.list_feature_view_versions(name, project)` programmatically +- Support `registry.get_feature_view_by_version(name, project, version_number)` for snapshot retrieval +- Support version pinning via `version="v2"` in feature view definitions + +### Online Versioning Is Opt-In + +The expensive/risky part of versioning is creating **separate online store tables per version** and routing reads to them. This is gated behind a config flag: + +```yaml +registry: + path: data/registry.db + enable_online_feature_view_versioning: true +``` + +When enabled, version-qualified refs like `driver_stats@v2:trips_today` in `get_online_features()` will: +1. Look up the v2 snapshot from version history +2. Read from a version-specific online store table (`project_driver_stats_v2`) + +When disabled (the default), using `@v` refs raises a clear error. All other versioning features (history, listing, pinning, snapshot retrieval) work regardless. + +### Storage + +**File-based registry**: Version history is stored as a repeated `FeatureViewVersionRecord` message in the registry proto, alongside the existing feature view definitions. + +**SQL registry**: A dedicated `feature_view_version_history` table with columns for name, project, version number, type, proto bytes, and creation timestamp. + +### Version Pinning + +Pinning replaces the active feature view with a historical snapshot: + +```python +driver_stats = FeatureView( + name="driver_stats", + entities=[driver], + schema=[...], + source=my_source, + version="v2", # revert to v2's definition +) +``` + +Safety constraints: +- The user's feature view definition (minus the version field) must match the currently active definition. If the user changed both the schema and the version pin simultaneously, `feast apply` raises `FeatureViewPinConflict`. This prevents accidental "I thought I was reverting but I also changed things." +- Pinning does not modify version history — v0, v1, v2 snapshots remain intact. +- After a pin, removing the version field (or setting `version="latest"`) returns to auto-incrementing behavior. If the next `feast apply` detects a schema change, a new version is created. + +### Version-Qualified Feature References + +The `@v` syntax extends the existing `feature_view:feature` reference format: + +```python +features = store.get_online_features( + features=[ + "driver_stats:trips_today", # latest (default) + "driver_stats@v2:trips_today", # read from v2 + "driver_stats@v1:avg_rating", # read from v1 + ], + entity_rows=[{"driver_id": 1001}], +) +``` + +Online store table naming: +- v0 uses the existing unversioned table (`project_driver_stats`) for backward compatibility +- v1+ use suffixed tables (`project_driver_stats_v1`, `project_driver_stats_v2`) + +Each version requires its own materialization. `@latest` always resolves to the active version. + +### Supported Feature View Types + +Versioning works on all three feature view types: +- `FeatureView` / `BatchFeatureView` +- `StreamFeatureView` +- `OnDemandFeatureView` + +### Online Store Support + +Version-qualified reads (`@v`) are currently implemented for the **SQLite** online store. Other online stores will raise a clear error. Expanding to additional stores is follow-up work. + +### Materialization + +Each version's data lives in its own online store table (e.g., `project_fv_v1`, `project_fv_v2`). By default, `feast materialize` and `feast materialize-incremental` populate the **active (latest)** version's table. To populate a specific version's table, pass the `--version` flag along with a single `--views` target: + +```bash +# Materialize v1 of driver_stats +feast materialize --views driver_stats --version v1 2024-01-01T00:00:00 2024-01-15T00:00:00 + +# Incrementally materialize v2 of driver_stats +feast materialize-incremental --views driver_stats --version v2 2024-01-15T00:00:00 +``` + +Python SDK equivalent: + +```python +store.materialize( + feature_views=["driver_stats"], + version="v2", + start_date=start, + end_date=end, +) +``` + +**Requirements:** +- `enable_online_feature_view_versioning: true` must be set in `feature_store.yaml` +- `--version` requires `--views` with exactly one feature view name +- The specified version must exist in the registry (created by a prior `feast apply`) +- Without `--version`, materialization targets the active version's table (existing behavior) + +**Multi-version workflow example:** + +```bash +# Model A uses v1, Model B uses v2 — populate both tables +feast materialize --views driver_stats --version v1 2024-01-01T00:00:00 2024-02-01T00:00:00 +feast materialize --views driver_stats --version v2 2024-01-01T00:00:00 2024-02-01T00:00:00 + +# Models can now query their respective versions online +# Model A: store.get_online_features(features=["driver_stats@v1:trips_today"], ...) +# Model B: store.get_online_features(features=["driver_stats@v2:trips_today"], ...) +``` + +## API Surface + +### Python SDK + +```python +# List version history +versions = store.list_feature_view_versions("driver_stats") +# [{"version": "v0", "version_number": 0, "created_timestamp": ..., ...}, ...] + +# Get a specific version's definition +fv_v1 = store.registry.get_feature_view_by_version("driver_stats", project, 1) + +# Pin to a version +FeatureView(name="driver_stats", ..., version="v2") + +# Version-qualified online read (requires enable_online_feature_view_versioning) +store.get_online_features(features=["driver_stats@v2:trips_today"], ...) + +# Materialize a specific version +store.materialize(feature_views=["driver_stats"], version="v2", start_date=start, end_date=end) +store.materialize_incremental(feature_views=["driver_stats"], version="v2", end_date=end) +``` + +### CLI + +```bash +# List versions +feast feature-views list-versions driver_stats + +# Output: +# VERSION TYPE CREATED VERSION_ID +# v0 feature_view 2024-01-15 10:30:00 a1b2c3d4-... +# v1 feature_view 2024-01-16 14:22:00 e5f6g7h8-... + +# Materialize a specific version +feast materialize --views driver_stats --version v2 2024-01-01T00:00:00 2024-02-01T00:00:00 +feast materialize-incremental --views driver_stats --version v2 2024-02-01T00:00:00 +``` + +### Configuration + +```yaml +# feature_store.yaml +registry: + path: data/registry.db + # Optional: enable versioned online tables and @v reads (default: false) + enable_online_feature_view_versioning: true +``` + +## Migration & Backward Compatibility + +- **Zero breaking changes.** All existing feature views continue to work. The `version` parameter defaults to `"latest"` and `current_version_number` defaults to `None`. +- **Existing online data is preserved.** The unversioned online store table is treated as v0. No data migration needed. +- **Version history starts on first apply.** Pre-existing feature views get a v0 snapshot on their next `feast apply`. +- **Proto backward compatibility.** The new `version` and `current_version_number` fields use proto defaults (empty string and 0) so old protos deserialize correctly. + +## Concurrency + +Two concurrent `feast apply` calls on the same feature view can race on version number assignment. The behavior depends on the version mode and registry backend. + +### `version="latest"` (auto-increment) + +The registry computes `MAX(version_number) + 1` and saves the new snapshot. If two concurrent applies race on the same version number: + +- **SQL registry**: The unique constraint on `(feature_view_name, project_id, version_number)` causes an `IntegrityError`. The registry catches this and retries up to 3 times, re-reading `MAX + 1` each time. Since the client said "latest", the exact version number doesn't matter. +- **File registry**: Last-write-wins. The file registry uses an in-memory proto with no database-level constraints, so concurrent writes may overwrite each other. This is a pre-existing limitation for all file registry operations. + +### `version="v"` (explicit version) + +The registry checks whether version N already exists: + +- **Exists** → pin/revert to that version's snapshot (unchanged behavior) +- **Doesn't exist** → forward declaration: create version N with the provided definition + +If two concurrent applies both try to forward-declare the same version: + +- **SQL registry**: The first one succeeds; the second gets a `ConcurrentVersionConflict` error with a clear message to pull latest and retry. +- **File registry**: Last-write-wins (same pre-existing limitation). + +### Recommendations + +- For single-developer or CI/CD workflows, the file registry works fine. +- For multi-client environments with concurrent applies, use the SQL registry for proper conflict detection. + +## Staged Publishing (`--no-promote`) + +By default, `feast apply` atomically saves a version snapshot **and** promotes it to the active definition. This works well for additive changes, but for breaking schema changes you may want to stage the new version without disrupting unversioned consumers. + +### The Problem + +Without `--no-promote`, a phased rollout looks like: + +1. `feast apply` — saves v2 and promotes it (all unversioned consumers now hit v2) +2. Immediately pin back to v1 — `version="v1"` in the definition, then `feast apply` again + +This leaves a transition window where unversioned consumers briefly see the new schema. Authors can also forget the pin-back step. + +### The Solution + +The `--no-promote` flag saves the version snapshot without updating the active feature view definition. The new version is accessible only via explicit `@v` reads and `--version` materialization. + +**CLI usage:** + +```bash +feast apply --no-promote +``` + +**Python SDK equivalent:** + +```python +store.apply([entity, feature_view], no_promote=True) +``` + +### Phased Rollout Workflow + +1. **Stage the new version:** + ```bash + feast apply --no-promote + ``` + This publishes v2 without promoting it. All unversioned consumers continue using v1. + +2. **Populate the v2 online table:** + ```bash + feast materialize --views driver_stats --version v2 ... + ``` + +3. **Migrate consumers one at a time:** + - Consumer A switches to `driver_stats@v2:trips_today` + - Consumer B switches to `driver_stats@v2:avg_rating` + +4. **Promote v2 as the default:** + ```bash + feast apply + ``` + Or pin to v2: set `version="v2"` in the definition and run `feast apply`. + +> **Note:** By default, `feast apply` (without `--no-promote`) promotes the new version immediately. Use `--no-promote` only when you need a controlled, phased rollout. + +## Feature Services + +Feature services work with versioned feature views when the online versioning flag is enabled: + +- **Automatic version resolution.** When `enable_online_feature_view_versioning` is `true` and a feature service references a versioned feature view (`current_version_number > 0`), the serving path automatically sets `version_tag` on the projection. This ensures `get_online_features()` reads from the correct versioned online store table (e.g., `project_driver_stats_v1`) instead of the unversioned table. +- **Version-qualified feature refs.** Both `_get_features()` and `_get_feature_views_to_use()` produce version-qualified keys (e.g., `driver_stats@v1:trips_today`) for feature services referencing versioned FVs, keeping the feature ref index and the FV lookup index in sync. +- **Gated by flag.** If any feature view referenced by a feature service has been versioned (`current_version_number > 0`) but `enable_online_feature_view_versioning` is `false`: + - `feast apply` will reject the feature service with a clear error. + - `get_online_features()` will fail at retrieval time with a descriptive error message. +- **No `@v` syntax in feature services.** Version-qualified reads (`driver_stats@v2:trips_today`) using the `@v` syntax require string-based feature references passed directly to `get_online_features()`. Feature services always resolve to the active (latest) version of each referenced feature view. +- **Future work: per-reference version pinning.** A future enhancement could allow feature services to pin individual feature view references to specific versions (e.g., `FeatureService(features=[driver_stats["v2"]])`). +- **`--no-promote` versions are not served.** Feature services always resolve to the active (promoted) version. Versions published with `--no-promote` are not visible to feature services until promoted via a regular `feast apply` or explicit pin. + +## Limitations & Future Work + +- **Online store coverage.** Version-qualified reads are only on SQLite today. Redis, DynamoDB, Bigtable, Postgres, etc. are follow-up work. +- **Offline store versioning.** This RFC covers online reads only. Versioned historical retrieval is out of scope. +- **Version deletion.** There is no mechanism to prune old versions. This could be added later if registries grow large. +- **Cross-version joins.** Joining features from different versions of the same feature view in `get_historical_features` is not supported. +- **Naming restrictions.** Feature view names must not contain `@` or `:` since these characters are reserved for version-qualified references (`fv@v2:feature`). `feast apply` rejects new feature views with these characters. The parser falls back gracefully for legacy feature views that already contain `@` in their names — unrecognized `@` suffixes are treated as part of the name rather than raising errors. + +## Open Questions + +1. **Should version history have a retention policy?** For long-lived feature views with frequent schema changes, version history could grow unbounded. A `max_versions` config or TTL-based pruning could help. +2. **Should version-qualified refs work in `get_historical_features`?** The current implementation is online-only. Offline versioned reads would require point-in-time-correct version resolution. +3. **Should we support version aliases?** e.g., `driver_stats@stable:trips` mapping to a pinned version number via config. + +## References + +- Branch: `featureview-versioning` +- Documentation: `docs/getting-started/concepts/feature-view.md` (Versioning section) +- Tests: `sdk/python/tests/integration/registration/test_versioning.py`, `sdk/python/tests/unit/test_feature_view_versioning.py` diff --git a/go/internal/feast/onlineserving/serving.go b/go/internal/feast/onlineserving/serving.go index ff70443015a..1ce5f6c555c 100644 --- a/go/internal/feast/onlineserving/serving.go +++ b/go/internal/feast/onlineserving/serving.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "errors" "fmt" + "regexp" "sort" "strings" @@ -20,6 +21,8 @@ import ( "github.com/feast-dev/feast/go/types" ) +var versionTagRegex = regexp.MustCompile(`^[vV]\d+$`) + /* FeatureVector type represent result of retrieving single feature for multiple rows. It can be imagined as a column in output dataframe / table. @@ -492,6 +495,18 @@ func ParseFeatureReference(featureRef string) (featureViewName, featureName stri featureViewName = parsedFeatureName[0] featureName = parsedFeatureName[1] } + + // Handle @version qualifier on feature view name + if atIdx := strings.Index(featureViewName, "@"); atIdx >= 0 { + suffix := featureViewName[atIdx+1:] + if versionTagRegex.MatchString(suffix) { + e = fmt.Errorf("versioned feature refs (@%s) are not supported by the Go feature server", suffix) + return + } + if strings.EqualFold(suffix, "latest") { + featureViewName = featureViewName[:atIdx] + } + } return } diff --git a/protos/feast/core/FeatureView.proto b/protos/feast/core/FeatureView.proto index 66dc4c3de6f..19ffe562dc8 100644 --- a/protos/feast/core/FeatureView.proto +++ b/protos/feast/core/FeatureView.proto @@ -36,7 +36,7 @@ message FeatureView { FeatureViewMeta meta = 2; } -// Next available id: 18 +// Next available id: 19 // TODO(adchia): refactor common fields from this and ODFV into separate metadata proto message FeatureViewSpec { // Name of the feature view. Must be unique. Not updated. @@ -94,6 +94,9 @@ message FeatureViewSpec { // Whether schema validation is enabled during materialization bool enable_validation = 17; + + // User-specified version pin (e.g. "latest", "v2", "version2") + string version = 18; } message FeatureViewMeta { @@ -105,6 +108,12 @@ message FeatureViewMeta { // List of pairs (start_time, end_time) for which this feature view has been materialized. repeated MaterializationInterval materialization_intervals = 3; + + // The current version number of this feature view in the version history. + int32 current_version_number = 4; + + // Auto-generated UUID identifying this specific version. + string version_id = 5; } message MaterializationInterval { diff --git a/protos/feast/core/FeatureViewProjection.proto b/protos/feast/core/FeatureViewProjection.proto index b0e697b656f..60a26139abd 100644 --- a/protos/feast/core/FeatureViewProjection.proto +++ b/protos/feast/core/FeatureViewProjection.proto @@ -1,35 +1,38 @@ -syntax = "proto3"; -package feast.core; - -option go_package = "github.com/feast-dev/feast/go/protos/feast/core"; -option java_outer_classname = "FeatureReferenceProto"; -option java_package = "feast.proto.core"; - -import "feast/core/Feature.proto"; -import "feast/core/DataSource.proto"; - - -// A projection to be applied on top of a FeatureView. -// Contains the modifications to a FeatureView such as the features subset to use. -message FeatureViewProjection { - // The feature view name - string feature_view_name = 1; - - // Alias for feature view name - string feature_view_name_alias = 3; - - // The features of the feature view that are a part of the feature reference. - repeated FeatureSpecV2 feature_columns = 2; - - // Map for entity join_key overrides of feature data entity join_key to entity data join_key - map join_key_map = 4; - - string timestamp_field = 5; - string date_partition_column = 6; - string created_timestamp_column = 7; - // Batch/Offline DataSource where this view can retrieve offline feature data. - DataSource batch_source = 8; - // Streaming DataSource from where this view can consume "online" feature data. - DataSource stream_source = 9; - -} +syntax = "proto3"; +package feast.core; + +option go_package = "github.com/feast-dev/feast/go/protos/feast/core"; +option java_outer_classname = "FeatureReferenceProto"; +option java_package = "feast.proto.core"; + +import "feast/core/Feature.proto"; +import "feast/core/DataSource.proto"; + + +// A projection to be applied on top of a FeatureView. +// Contains the modifications to a FeatureView such as the features subset to use. +message FeatureViewProjection { + // The feature view name + string feature_view_name = 1; + + // Alias for feature view name + string feature_view_name_alias = 3; + + // The features of the feature view that are a part of the feature reference. + repeated FeatureSpecV2 feature_columns = 2; + + // Map for entity join_key overrides of feature data entity join_key to entity data join_key + map join_key_map = 4; + + string timestamp_field = 5; + string date_partition_column = 6; + string created_timestamp_column = 7; + // Batch/Offline DataSource where this view can retrieve offline feature data. + DataSource batch_source = 8; + // Streaming DataSource from where this view can consume "online" feature data. + DataSource stream_source = 9; + + // Optional version tag for version-qualified feature references (e.g., @v2). + optional int32 version_tag = 10; + +} diff --git a/protos/feast/core/FeatureViewVersion.proto b/protos/feast/core/FeatureViewVersion.proto new file mode 100644 index 00000000000..c88a43eea80 --- /dev/null +++ b/protos/feast/core/FeatureViewVersion.proto @@ -0,0 +1,42 @@ +// +// Copyright 2024 The Feast Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +syntax = "proto3"; +package feast.core; + +option go_package = "github.com/feast-dev/feast/go/protos/feast/core"; +option java_outer_classname = "FeatureViewVersionProto"; +option java_package = "feast.proto.core"; + +import "google/protobuf/timestamp.proto"; + +message FeatureViewVersionRecord { + string feature_view_name = 1; + string project_id = 2; + int32 version_number = 3; + // "feature_view" | "stream_feature_view" | "on_demand_feature_view" + string feature_view_type = 4; + // serialized FV proto snapshot + bytes feature_view_proto = 5; + google.protobuf.Timestamp created_timestamp = 6; + string description = 7; + // auto-generated UUID for unique identification + string version_id = 8; +} + +message FeatureViewVersionHistory { + repeated FeatureViewVersionRecord records = 1; +} diff --git a/protos/feast/core/OnDemandFeatureView.proto b/protos/feast/core/OnDemandFeatureView.proto index 4b8dabb4f39..d518f22c6cd 100644 --- a/protos/feast/core/OnDemandFeatureView.proto +++ b/protos/feast/core/OnDemandFeatureView.proto @@ -36,7 +36,7 @@ message OnDemandFeatureView { OnDemandFeatureViewMeta meta = 2; } -// Next available id: 9 +// Next available id: 18 message OnDemandFeatureViewSpec { // Name of the feature view. Must be unique. Not updated. string name = 1; @@ -75,6 +75,8 @@ message OnDemandFeatureViewSpec { // Aggregation definitions repeated Aggregation aggregations = 16; + // User-specified version pin (e.g. "latest", "v2", "version2") + string version = 17; } message OnDemandFeatureViewMeta { @@ -83,6 +85,12 @@ message OnDemandFeatureViewMeta { // Time where this Feature View is last updated google.protobuf.Timestamp last_updated_timestamp = 2; + + // The current version number of this feature view in the version history. + int32 current_version_number = 3; + + // Auto-generated UUID identifying this specific version. + string version_id = 4; } message OnDemandSource { diff --git a/protos/feast/core/Registry.proto b/protos/feast/core/Registry.proto index 45ecd2c173e..45c885c7906 100644 --- a/protos/feast/core/Registry.proto +++ b/protos/feast/core/Registry.proto @@ -1,63 +1,65 @@ -// -// * Copyright 2020 The Feast Authors -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * https://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// - -syntax = "proto3"; - -package feast.core; -option java_package = "feast.proto.core"; -option java_outer_classname = "RegistryProto"; -option go_package = "github.com/feast-dev/feast/go/protos/feast/core"; - -import "feast/core/Entity.proto"; -import "feast/core/FeatureService.proto"; -import "feast/core/FeatureTable.proto"; -import "feast/core/FeatureView.proto"; -import "feast/core/InfraObject.proto"; -import "feast/core/OnDemandFeatureView.proto"; -import "feast/core/StreamFeatureView.proto"; -import "feast/core/DataSource.proto"; -import "feast/core/SavedDataset.proto"; -import "feast/core/ValidationProfile.proto"; -import "google/protobuf/timestamp.proto"; -import "feast/core/Permission.proto"; -import "feast/core/Project.proto"; - -// Next id: 18 -message Registry { - repeated Entity entities = 1; - repeated FeatureTable feature_tables = 2; - repeated FeatureView feature_views = 6; - repeated DataSource data_sources = 12; - repeated OnDemandFeatureView on_demand_feature_views = 8; - repeated StreamFeatureView stream_feature_views = 14; - repeated FeatureService feature_services = 7; - repeated SavedDataset saved_datasets = 11; - repeated ValidationReference validation_references = 13; - Infra infra = 10; - // Tracking metadata of Feast by project - repeated ProjectMetadata project_metadata = 15 [deprecated = true]; - - string registry_schema_version = 3; // to support migrations; incremented when schema is changed - string version_id = 4; // version id, random string generated on each update of the data; now used only for debugging purposes - google.protobuf.Timestamp last_updated = 5; - repeated Permission permissions = 16; - repeated Project projects = 17; -} - -message ProjectMetadata { - string project = 1; - string project_uuid = 2; -} +// +// * Copyright 2020 The Feast Authors +// * +// * Licensed under the Apache License, Version 2.0 (the "License"); +// * you may not use this file except in compliance with the License. +// * You may obtain a copy of the License at +// * +// * https://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, software +// * distributed under the License is distributed on an "AS IS" BASIS, +// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// * See the License for the specific language governing permissions and +// * limitations under the License. +// + +syntax = "proto3"; + +package feast.core; +option java_package = "feast.proto.core"; +option java_outer_classname = "RegistryProto"; +option go_package = "github.com/feast-dev/feast/go/protos/feast/core"; + +import "feast/core/Entity.proto"; +import "feast/core/FeatureService.proto"; +import "feast/core/FeatureTable.proto"; +import "feast/core/FeatureView.proto"; +import "feast/core/InfraObject.proto"; +import "feast/core/OnDemandFeatureView.proto"; +import "feast/core/StreamFeatureView.proto"; +import "feast/core/DataSource.proto"; +import "feast/core/SavedDataset.proto"; +import "feast/core/ValidationProfile.proto"; +import "google/protobuf/timestamp.proto"; +import "feast/core/Permission.proto"; +import "feast/core/Project.proto"; +import "feast/core/FeatureViewVersion.proto"; + +// Next id: 19 +message Registry { + repeated Entity entities = 1; + repeated FeatureTable feature_tables = 2; + repeated FeatureView feature_views = 6; + repeated DataSource data_sources = 12; + repeated OnDemandFeatureView on_demand_feature_views = 8; + repeated StreamFeatureView stream_feature_views = 14; + repeated FeatureService feature_services = 7; + repeated SavedDataset saved_datasets = 11; + repeated ValidationReference validation_references = 13; + Infra infra = 10; + // Tracking metadata of Feast by project + repeated ProjectMetadata project_metadata = 15 [deprecated = true]; + + string registry_schema_version = 3; // to support migrations; incremented when schema is changed + string version_id = 4; // version id, random string generated on each update of the data; now used only for debugging purposes + google.protobuf.Timestamp last_updated = 5; + repeated Permission permissions = 16; + repeated Project projects = 17; + FeatureViewVersionHistory feature_view_version_history = 18; +} + +message ProjectMetadata { + string project = 1; + string project_uuid = 2; +} diff --git a/protos/feast/core/StreamFeatureView.proto b/protos/feast/core/StreamFeatureView.proto index 5f9ee6ce39d..05c829b70d3 100644 --- a/protos/feast/core/StreamFeatureView.proto +++ b/protos/feast/core/StreamFeatureView.proto @@ -37,7 +37,7 @@ message StreamFeatureView { FeatureViewMeta meta = 2; } -// Next available id: 21 +// Next available id: 22 message StreamFeatureViewSpec { // Name of the feature view. Must be unique. Not updated. string name = 1; @@ -102,5 +102,8 @@ message StreamFeatureViewSpec { // Whether schema validation is enabled during materialization bool enable_validation = 20; + + // User-specified version pin (e.g. "latest", "v2", "version2") + string version = 21; } diff --git a/protos/feast/serving/ServingService.proto b/protos/feast/serving/ServingService.proto index 154d850099f..87e35ac4edf 100644 --- a/protos/feast/serving/ServingService.proto +++ b/protos/feast/serving/ServingService.proto @@ -91,6 +91,9 @@ message GetOnlineFeaturesRequest { // (was moved to dedicated parameter to avoid unnecessary separation logic on serving side) // A map of variable name -> list of values map request_context = 5; + + // Whether to include feature view version metadata in the response + bool include_feature_view_version_metadata = 6; } message GetOnlineFeaturesResponse { @@ -109,8 +112,14 @@ message GetOnlineFeaturesResponse { bool status = 3; } +message FeatureViewMetadata { + string name = 1; // Feature view name (e.g., "driver_stats") + int32 version = 2; // Version number (e.g., 2) +} + message GetOnlineFeaturesResponseMetadata { - FeatureList feature_names = 1; + FeatureList feature_names = 1; // Clean feature names without @v2 syntax + repeated FeatureViewMetadata feature_view_metadata = 2; // Only populated when requested } enum FieldStatus { diff --git a/sdk/python/feast/base_feature_view.py b/sdk/python/feast/base_feature_view.py index 478058c89b3..f3e0a2cad5b 100644 --- a/sdk/python/feast/base_feature_view.py +++ b/sdk/python/feast/base_feature_view.py @@ -56,6 +56,8 @@ class BaseFeatureView(ABC): projection: FeatureViewProjection created_timestamp: Optional[datetime] last_updated_timestamp: Optional[datetime] + version: str + current_version_number: Optional[int] @abstractmethod def __init__( @@ -92,6 +94,10 @@ def __init__( self.projection = FeatureViewProjection.from_definition(self) self.created_timestamp = None self.last_updated_timestamp = None + if not hasattr(self, "version"): + self.version = "latest" + if not hasattr(self, "current_version_number"): + self.current_version_number = None self.source = source @@ -147,6 +153,17 @@ def __getitem__(self, item): return cp + def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool: + """Check if schema or UDF-related fields have changed (version-worthy changes). + + Callers always match by name first, so name comparison is omitted here. + """ + if sorted(self.features) != sorted(other.features): + return True + # Skip metadata: description, tags, owner, projection + # Skip source changes: treat as deployment/location details, not schema changes + return False + def __eq__(self, other): if not isinstance(other, BaseFeatureView): raise TypeError( @@ -178,6 +195,18 @@ def ensure_valid(self): """ if not self.name: raise ValueError("Feature view needs a name.") + if "@" in self.name: + raise ValueError( + f"Feature view name '{self.name}' must not contain '@'. " + f"The '@' character is reserved for version-qualified references " + f"(e.g., 'fv@v2:feature')." + ) + if ":" in self.name: + raise ValueError( + f"Feature view name '{self.name}' must not contain ':'. " + f"The ':' character is reserved as the separator in fully qualified " + f"feature references (e.g., 'feature_view:feature_name')." + ) def with_name(self, name: str): """ diff --git a/sdk/python/feast/batch_feature_view.py b/sdk/python/feast/batch_feature_view.py index 925d70e58ab..c9c53dfef91 100644 --- a/sdk/python/feast/batch_feature_view.py +++ b/sdk/python/feast/batch_feature_view.py @@ -100,6 +100,7 @@ def __init__( batch_engine: Optional[Dict[str, Any]] = None, aggregations: Optional[List[Aggregation]] = None, enable_validation: bool = False, + version: str = "latest", ): if not flags_helper.is_test(): warnings.warn( @@ -155,6 +156,7 @@ def __init__( sink_source=sink_source, mode=mode, enable_validation=enable_validation, + version=version, ) def get_feature_transformation(self) -> Optional[Transformation]: @@ -189,6 +191,7 @@ def batch_feature_view( owner: str = "", schema: Optional[List[Field]] = None, enable_validation: bool = False, + version: str = "latest", ): """ Creates a BatchFeatureView object with the given user-defined function (UDF) as the transformation. @@ -220,6 +223,7 @@ def decorator(user_function): udf=user_function, udf_string=udf_string, enable_validation=enable_validation, + version=version, ) functools.update_wrapper(wrapper=batch_feature_view_obj, wrapped=user_function) return batch_feature_view_obj diff --git a/sdk/python/feast/cli/cli.py b/sdk/python/feast/cli/cli.py index af746c8f3ef..1e461af4a28 100644 --- a/sdk/python/feast/cli/cli.py +++ b/sdk/python/feast/cli/cli.py @@ -276,12 +276,20 @@ def plan_command( is_flag=True, help="Disable progress bars during apply operation.", ) +@click.option( + "--no-promote", + is_flag=True, + default=False, + help="Save new versions without promoting them to active. " + "New versions are accessible via @v reads and --version materialization.", +) @click.pass_context def apply_total_command( ctx: click.Context, skip_source_validation: bool, skip_feature_view_validation: bool, no_progress: bool, + no_promote: bool, ): """ Create or update a feature store deployment @@ -304,6 +312,7 @@ def apply_total_command( repo, skip_source_validation, skip_feature_view_validation, + no_promote=no_promote, ) except FeastProviderLoginError as e: print(str(e)) @@ -351,6 +360,12 @@ def registry_dump_command(ctx: click.Context): is_flag=True, help="Materialize all available data using current datetime as event timestamp (useful when source data lacks event timestamps)", ) +@click.option( + "--version", + "feature_view_version", + default=None, + help="Version to materialize (e.g., 'v2'). Requires --views with exactly one feature view.", +) @click.pass_context def materialize_command( ctx: click.Context, @@ -358,6 +373,7 @@ def materialize_command( end_ts: Optional[str], views: List[str], disable_event_timestamp: bool, + feature_view_version: Optional[str], ): """ Run a (non-incremental) materialization job to ingest data into the online store. Feast @@ -395,6 +411,7 @@ def materialize_command( start_date=start_date, end_date=end_date, disable_event_timestamp=disable_event_timestamp, + version=feature_view_version, ) @@ -406,8 +423,19 @@ def materialize_command( help="Feature views to incrementally materialize", multiple=True, ) +@click.option( + "--version", + "feature_view_version", + default=None, + help="Version to materialize (e.g., 'v2'). Requires --views with exactly one feature view.", +) @click.pass_context -def materialize_incremental_command(ctx: click.Context, end_ts: str, views: List[str]): +def materialize_incremental_command( + ctx: click.Context, + end_ts: str, + views: List[str], + feature_view_version: Optional[str], +): """ Run an incremental materialization job to ingest new data into the online store. Feast will read all data from the previously ingested point to END_TS from the offline store and write it to the @@ -420,6 +448,7 @@ def materialize_incremental_command(ctx: click.Context, end_ts: str, views: List store.materialize_incremental( feature_views=None if not views else views, end_date=utils.make_tzaware(datetime.fromisoformat(end_ts)), + version=feature_view_version, ) diff --git a/sdk/python/feast/cli/feature_views.py b/sdk/python/feast/cli/feature_views.py index a1a29ac9f27..99de5e70be7 100644 --- a/sdk/python/feast/cli/feature_views.py +++ b/sdk/python/feast/cli/feature_views.py @@ -70,3 +70,47 @@ def feature_view_list(ctx: click.Context, tags: list[str]): from tabulate import tabulate print(tabulate(table, headers=["NAME", "ENTITIES", "TYPE"], tablefmt="plain")) + + +@feature_views_cmd.command("list-versions") +@click.argument("name", type=click.STRING) +@click.pass_context +def feature_view_versions(ctx: click.Context, name: str): + """ + List version history for a feature view + """ + store = create_feature_store(ctx) + + try: + versions = store.list_feature_view_versions(name) + except NotImplementedError: + print("Version history is not supported by this registry backend.") + exit(1) + except Exception as e: + print(e) + exit(1) + + if not versions: + print(f"No version history found for feature view '{name}'.") + return + + table = [] + for v in versions: + table.append( + [ + v["version"], + v["feature_view_type"], + str(v["created_timestamp"]), + v["version_id"], + ] + ) + + from tabulate import tabulate + + print( + tabulate( + table, + headers=["VERSION", "TYPE", "CREATED", "VERSION_ID"], + tablefmt="plain", + ) + ) diff --git a/sdk/python/feast/diff/registry_diff.py b/sdk/python/feast/diff/registry_diff.py index 272c4590d88..58a92db8139 100644 --- a/sdk/python/feast/diff/registry_diff.py +++ b/sdk/python/feast/diff/registry_diff.py @@ -1,416 +1,421 @@ -from dataclasses import dataclass -from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, TypeVar, cast - -from feast.base_feature_view import BaseFeatureView -from feast.data_source import DataSource -from feast.diff.property_diff import PropertyDiff, TransitionType -from feast.entity import Entity -from feast.feast_object import FeastObject, FeastObjectSpecProto -from feast.feature_service import FeatureService -from feast.feature_view import DUMMY_ENTITY_NAME -from feast.infra.registry.base_registry import BaseRegistry -from feast.infra.registry.registry import FEAST_OBJECT_TYPES, FeastObjectType -from feast.permissions.permission import Permission -from feast.project import Project -from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto -from feast.protos.feast.core.Entity_pb2 import Entity as EntityProto -from feast.protos.feast.core.FeatureService_pb2 import ( - FeatureService as FeatureServiceProto, -) -from feast.protos.feast.core.FeatureView_pb2 import FeatureView as FeatureViewProto -from feast.protos.feast.core.OnDemandFeatureView_pb2 import ( - OnDemandFeatureView as OnDemandFeatureViewProto, -) -from feast.protos.feast.core.OnDemandFeatureView_pb2 import OnDemandFeatureViewSpec -from feast.protos.feast.core.Permission_pb2 import Permission as PermissionProto -from feast.protos.feast.core.SavedDataset_pb2 import SavedDataset as SavedDatasetProto -from feast.protos.feast.core.StreamFeatureView_pb2 import ( - StreamFeatureView as StreamFeatureViewProto, -) -from feast.protos.feast.core.ValidationProfile_pb2 import ( - ValidationReference as ValidationReferenceProto, -) -from feast.repo_contents import RepoContents - - -@dataclass -class FeastObjectDiff: - name: str - feast_object_type: FeastObjectType - current_feast_object: Optional[FeastObject] - new_feast_object: Optional[FeastObject] - feast_object_property_diffs: List[PropertyDiff] - transition_type: TransitionType - - -@dataclass -class RegistryDiff: - feast_object_diffs: List[FeastObjectDiff] - - def __init__(self): - self.feast_object_diffs = [] - - def add_feast_object_diff(self, feast_object_diff: FeastObjectDiff): - self.feast_object_diffs.append(feast_object_diff) - - def to_string(self): - from colorama import Fore, Style - - log_string = "" - - message_action_map = { - TransitionType.CREATE: ("Created", Fore.GREEN), - TransitionType.DELETE: ("Deleted", Fore.RED), - TransitionType.UNCHANGED: ("Unchanged", Fore.LIGHTBLUE_EX), - TransitionType.UPDATE: ("Updated", Fore.YELLOW), - } - for feast_object_diff in self.feast_object_diffs: - if feast_object_diff.name == DUMMY_ENTITY_NAME: - continue - if feast_object_diff.transition_type == TransitionType.UNCHANGED: - continue - if feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: - # TODO(adchia): Print statements out starting in Feast 0.24 - continue - action, color = message_action_map[feast_object_diff.transition_type] - log_string += f"{action} {feast_object_diff.feast_object_type.value} {Style.BRIGHT + color}{feast_object_diff.name}{Style.RESET_ALL}\n" - if feast_object_diff.transition_type == TransitionType.UPDATE: - for _p in feast_object_diff.feast_object_property_diffs: - log_string += f"\t{_p.property_name}: {Style.BRIGHT + color}{_p.val_existing}{Style.RESET_ALL} -> {Style.BRIGHT + Fore.LIGHTGREEN_EX}{_p.val_declared}{Style.RESET_ALL}\n" - - log_string = ( - f"{Style.BRIGHT + Fore.LIGHTBLUE_EX}No changes to registry" - if not log_string - else log_string - ) - - return log_string - - -def tag_objects_for_keep_delete_update_add( - existing_objs: Iterable[FeastObject], desired_objs: Iterable[FeastObject] -) -> Tuple[Set[FeastObject], Set[FeastObject], Set[FeastObject], Set[FeastObject]]: - # TODO(adchia): Remove the "if X.name" condition when data sources are forced to have names - existing_obj_names = {e.name for e in existing_objs if e.name} - desired_objs = [obj for obj in desired_objs if obj.name] - existing_objs = [obj for obj in existing_objs if obj.name] - desired_obj_names = {e.name for e in desired_objs if e.name} - - objs_to_add = {e for e in desired_objs if e.name not in existing_obj_names} - objs_to_update = {e for e in desired_objs if e.name in existing_obj_names} - objs_to_keep = {e for e in existing_objs if e.name in desired_obj_names} - objs_to_delete = {e for e in existing_objs if e.name not in desired_obj_names} - - return objs_to_keep, objs_to_delete, objs_to_update, objs_to_add - - -FeastObjectProto = TypeVar( - "FeastObjectProto", - DataSourceProto, - EntityProto, - FeatureViewProto, - FeatureServiceProto, - OnDemandFeatureViewProto, - StreamFeatureViewProto, - ValidationReferenceProto, - SavedDatasetProto, - PermissionProto, -) - - -FIELDS_TO_IGNORE = {"project"} - - -def diff_registry_objects( - current: FeastObject, new: FeastObject, object_type: FeastObjectType -) -> FeastObjectDiff: - current_proto = current.to_proto() - new_proto = new.to_proto() - assert current_proto.DESCRIPTOR.full_name == new_proto.DESCRIPTOR.full_name - property_diffs = [] - transition: TransitionType = TransitionType.UNCHANGED - - current_spec: FeastObjectSpecProto - new_spec: FeastObjectSpecProto - if isinstance( - current_proto, (DataSourceProto, ValidationReferenceProto) - ) or isinstance(new_proto, (DataSourceProto, ValidationReferenceProto)): - assert type(current_proto) == type(new_proto) - current_spec = cast(DataSourceProto, current_proto) - new_spec = cast(DataSourceProto, new_proto) - else: - current_spec = current_proto.spec - new_spec = new_proto.spec - if current != new: - for _field in current_spec.DESCRIPTOR.fields: - if _field.name in FIELDS_TO_IGNORE: - continue - elif getattr(current_spec, _field.name) != getattr(new_spec, _field.name): - if _field.name == "feature_transformation": - current_spec = cast(OnDemandFeatureViewSpec, current_spec) - new_spec = cast(OnDemandFeatureViewSpec, new_spec) - # Check if the old proto is populated and use that if it is - feature_transformation_udf = ( - current_spec.feature_transformation.user_defined_function - ) - if ( - current_spec.HasField("user_defined_function") - and not feature_transformation_udf - ): - deprecated_udf = current_spec.user_defined_function - else: - deprecated_udf = None - current_udf = ( - deprecated_udf - if deprecated_udf is not None - else feature_transformation_udf - ) - new_udf = new_spec.feature_transformation.user_defined_function - for _udf_field in current_udf.DESCRIPTOR.fields: - if _udf_field.name == "body": - continue - if getattr(current_udf, _udf_field.name) != getattr( - new_udf, _udf_field.name - ): - transition = TransitionType.UPDATE - property_diffs.append( - PropertyDiff( - _field.name + "." + _udf_field.name, - getattr(current_udf, _udf_field.name), - getattr(new_udf, _udf_field.name), - ) - ) - else: - transition = TransitionType.UPDATE - property_diffs.append( - PropertyDiff( - _field.name, - getattr(current_spec, _field.name), - getattr(new_spec, _field.name), - ) - ) - return FeastObjectDiff( - name=new_spec.name, - feast_object_type=object_type, - current_feast_object=current, - new_feast_object=new, - feast_object_property_diffs=property_diffs, - transition_type=transition, - ) - - -def extract_objects_for_keep_delete_update_add( - registry: BaseRegistry, - current_project: str, - desired_repo_contents: RepoContents, -) -> Tuple[ - Dict[FeastObjectType, Set[FeastObject]], - Dict[FeastObjectType, Set[FeastObject]], - Dict[FeastObjectType, Set[FeastObject]], - Dict[FeastObjectType, Set[FeastObject]], -]: - """ - Returns the objects in the registry that must be modified to achieve the desired repo state. - - Args: - registry: The registry storing the current repo state. - current_project: The Feast project whose objects should be compared. - desired_repo_contents: The desired repo state. - """ - objs_to_keep = {} - objs_to_delete = {} - objs_to_update = {} - objs_to_add = {} - - registry_object_type_to_objects: Dict[FeastObjectType, List[Any]] = ( - FeastObjectType.get_objects_from_registry(registry, current_project) - ) - registry_object_type_to_repo_contents: Dict[FeastObjectType, List[Any]] = ( - FeastObjectType.get_objects_from_repo_contents(desired_repo_contents) - ) - - for object_type in FEAST_OBJECT_TYPES: - ( - to_keep, - to_delete, - to_update, - to_add, - ) = tag_objects_for_keep_delete_update_add( - registry_object_type_to_objects[object_type], - registry_object_type_to_repo_contents[object_type], - ) - - objs_to_keep[object_type] = to_keep - objs_to_delete[object_type] = to_delete - objs_to_update[object_type] = to_update - objs_to_add[object_type] = to_add - - return objs_to_keep, objs_to_delete, objs_to_update, objs_to_add - - -def diff_between( - registry: BaseRegistry, - current_project: str, - desired_repo_contents: RepoContents, -) -> RegistryDiff: - """ - Returns the difference between the current and desired repo states. - - Args: - registry: The registry storing the current repo state. - current_project: The Feast project for which the diff is being computed. - desired_repo_contents: The desired repo state. - """ - diff = RegistryDiff() - - ( - objs_to_keep, - objs_to_delete, - objs_to_update, - objs_to_add, - ) = extract_objects_for_keep_delete_update_add( - registry, current_project, desired_repo_contents - ) - - for object_type in FEAST_OBJECT_TYPES: - objects_to_keep = objs_to_keep[object_type] - objects_to_delete = objs_to_delete[object_type] - objects_to_update = objs_to_update[object_type] - objects_to_add = objs_to_add[object_type] - - for e in objects_to_add: - diff.add_feast_object_diff( - FeastObjectDiff( - name=e.name, - feast_object_type=object_type, - current_feast_object=None, - new_feast_object=e, - feast_object_property_diffs=[], - transition_type=TransitionType.CREATE, - ) - ) - for e in objects_to_delete: - diff.add_feast_object_diff( - FeastObjectDiff( - name=e.name, - feast_object_type=object_type, - current_feast_object=e, - new_feast_object=None, - feast_object_property_diffs=[], - transition_type=TransitionType.DELETE, - ) - ) - for e in objects_to_update: - current_obj = [_e for _e in objects_to_keep if _e.name == e.name][0] - diff.add_feast_object_diff( - diff_registry_objects(current_obj, e, object_type) - ) - - return diff - - -def apply_diff_to_registry( - registry: BaseRegistry, - registry_diff: RegistryDiff, - project: str, - commit: bool = True, -): - """ - Applies the given diff to the given Feast project in the registry. - - Args: - registry: The registry to be updated. - registry_diff: The diff to apply. - project: Feast project to be updated. - commit: Whether the change should be persisted immediately - """ - for feast_object_diff in registry_diff.feast_object_diffs: - # There is no need to delete the object on an update, since applying the new object - # will automatically delete the existing object. - if feast_object_diff.transition_type == TransitionType.DELETE: - if feast_object_diff.feast_object_type == FeastObjectType.ENTITY: - entity_obj = cast(Entity, feast_object_diff.current_feast_object) - registry.delete_entity(entity_obj.name, project, commit=False) - elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE: - feature_service_obj = cast( - FeatureService, feast_object_diff.current_feast_object - ) - registry.delete_feature_service( - feature_service_obj.name, project, commit=False - ) - elif feast_object_diff.feast_object_type in [ - FeastObjectType.FEATURE_VIEW, - FeastObjectType.ON_DEMAND_FEATURE_VIEW, - FeastObjectType.STREAM_FEATURE_VIEW, - ]: - feature_view_obj = cast( - BaseFeatureView, feast_object_diff.current_feast_object - ) - registry.delete_feature_view( - feature_view_obj.name, - project, - commit=False, - ) - elif feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: - ds_obj = cast(DataSource, feast_object_diff.current_feast_object) - registry.delete_data_source( - ds_obj.name, - project, - commit=False, - ) - elif feast_object_diff.feast_object_type == FeastObjectType.PERMISSION: - permission_obj = cast( - Permission, feast_object_diff.current_feast_object - ) - registry.delete_permission( - permission_obj.name, - project, - commit=False, - ) - - if feast_object_diff.transition_type in [ - TransitionType.CREATE, - TransitionType.UPDATE, - ]: - if feast_object_diff.feast_object_type == FeastObjectType.PROJECT: - registry.apply_project( - cast(Project, feast_object_diff.new_feast_object), - commit=False, - ) - if feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: - registry.apply_data_source( - cast(DataSource, feast_object_diff.new_feast_object), - project, - commit=False, - ) - if feast_object_diff.feast_object_type == FeastObjectType.ENTITY: - registry.apply_entity( - cast(Entity, feast_object_diff.new_feast_object), - project, - commit=False, - ) - elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE: - registry.apply_feature_service( - cast(FeatureService, feast_object_diff.new_feast_object), - project, - commit=False, - ) - elif feast_object_diff.feast_object_type in [ - FeastObjectType.FEATURE_VIEW, - FeastObjectType.ON_DEMAND_FEATURE_VIEW, - FeastObjectType.STREAM_FEATURE_VIEW, - ]: - registry.apply_feature_view( - cast(BaseFeatureView, feast_object_diff.new_feast_object), - project, - commit=False, - ) - elif feast_object_diff.feast_object_type == FeastObjectType.PERMISSION: - registry.apply_permission( - cast(Permission, feast_object_diff.new_feast_object), - project, - commit=False, - ) - - if commit: - registry.commit() +from dataclasses import dataclass +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, TypeVar, cast + +from feast.base_feature_view import BaseFeatureView +from feast.data_source import DataSource +from feast.diff.property_diff import PropertyDiff, TransitionType +from feast.entity import Entity +from feast.feast_object import FeastObject, FeastObjectSpecProto +from feast.feature_service import FeatureService +from feast.feature_view import DUMMY_ENTITY_NAME +from feast.infra.registry.base_registry import BaseRegistry +from feast.infra.registry.registry import FEAST_OBJECT_TYPES, FeastObjectType +from feast.permissions.permission import Permission +from feast.project import Project +from feast.protos.feast.core.DataSource_pb2 import DataSource as DataSourceProto +from feast.protos.feast.core.Entity_pb2 import Entity as EntityProto +from feast.protos.feast.core.FeatureService_pb2 import ( + FeatureService as FeatureServiceProto, +) +from feast.protos.feast.core.FeatureView_pb2 import FeatureView as FeatureViewProto +from feast.protos.feast.core.OnDemandFeatureView_pb2 import ( + OnDemandFeatureView as OnDemandFeatureViewProto, +) +from feast.protos.feast.core.OnDemandFeatureView_pb2 import OnDemandFeatureViewSpec +from feast.protos.feast.core.Permission_pb2 import Permission as PermissionProto +from feast.protos.feast.core.SavedDataset_pb2 import SavedDataset as SavedDatasetProto +from feast.protos.feast.core.StreamFeatureView_pb2 import ( + StreamFeatureView as StreamFeatureViewProto, +) +from feast.protos.feast.core.ValidationProfile_pb2 import ( + ValidationReference as ValidationReferenceProto, +) +from feast.repo_contents import RepoContents + + +@dataclass +class FeastObjectDiff: + name: str + feast_object_type: FeastObjectType + current_feast_object: Optional[FeastObject] + new_feast_object: Optional[FeastObject] + feast_object_property_diffs: List[PropertyDiff] + transition_type: TransitionType + + +@dataclass +class RegistryDiff: + feast_object_diffs: List[FeastObjectDiff] + + def __init__(self): + self.feast_object_diffs = [] + + def add_feast_object_diff(self, feast_object_diff: FeastObjectDiff): + self.feast_object_diffs.append(feast_object_diff) + + def to_string(self): + from colorama import Fore, Style + + log_string = "" + + message_action_map = { + TransitionType.CREATE: ("Created", Fore.GREEN), + TransitionType.DELETE: ("Deleted", Fore.RED), + TransitionType.UNCHANGED: ("Unchanged", Fore.LIGHTBLUE_EX), + TransitionType.UPDATE: ("Updated", Fore.YELLOW), + } + for feast_object_diff in self.feast_object_diffs: + if feast_object_diff.name == DUMMY_ENTITY_NAME: + continue + if feast_object_diff.transition_type == TransitionType.UNCHANGED: + continue + if feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: + # TODO(adchia): Print statements out starting in Feast 0.24 + continue + action, color = message_action_map[feast_object_diff.transition_type] + log_string += f"{action} {feast_object_diff.feast_object_type.value} {Style.BRIGHT + color}{feast_object_diff.name}{Style.RESET_ALL}\n" + if feast_object_diff.transition_type == TransitionType.UPDATE: + for _p in feast_object_diff.feast_object_property_diffs: + log_string += f"\t{_p.property_name}: {Style.BRIGHT + color}{_p.val_existing}{Style.RESET_ALL} -> {Style.BRIGHT + Fore.LIGHTGREEN_EX}{_p.val_declared}{Style.RESET_ALL}\n" + + log_string = ( + f"{Style.BRIGHT + Fore.LIGHTBLUE_EX}No changes to registry" + if not log_string + else log_string + ) + + return log_string + + +def tag_objects_for_keep_delete_update_add( + existing_objs: Iterable[FeastObject], desired_objs: Iterable[FeastObject] +) -> Tuple[Set[FeastObject], Set[FeastObject], Set[FeastObject], Set[FeastObject]]: + # TODO(adchia): Remove the "if X.name" condition when data sources are forced to have names + existing_obj_names = {e.name for e in existing_objs if e.name} + desired_objs = [obj for obj in desired_objs if obj.name] + existing_objs = [obj for obj in existing_objs if obj.name] + desired_obj_names = {e.name for e in desired_objs if e.name} + + objs_to_add = {e for e in desired_objs if e.name not in existing_obj_names} + objs_to_update = {e for e in desired_objs if e.name in existing_obj_names} + objs_to_keep = {e for e in existing_objs if e.name in desired_obj_names} + objs_to_delete = {e for e in existing_objs if e.name not in desired_obj_names} + + return objs_to_keep, objs_to_delete, objs_to_update, objs_to_add + + +FeastObjectProto = TypeVar( + "FeastObjectProto", + DataSourceProto, + EntityProto, + FeatureViewProto, + FeatureServiceProto, + OnDemandFeatureViewProto, + StreamFeatureViewProto, + ValidationReferenceProto, + SavedDatasetProto, + PermissionProto, +) + + +FIELDS_TO_IGNORE = {"project"} + + +def diff_registry_objects( + current: FeastObject, new: FeastObject, object_type: FeastObjectType +) -> FeastObjectDiff: + current_proto = current.to_proto() + new_proto = new.to_proto() + assert current_proto.DESCRIPTOR.full_name == new_proto.DESCRIPTOR.full_name + property_diffs = [] + transition: TransitionType = TransitionType.UNCHANGED + + current_spec: FeastObjectSpecProto + new_spec: FeastObjectSpecProto + if isinstance( + current_proto, (DataSourceProto, ValidationReferenceProto) + ) or isinstance(new_proto, (DataSourceProto, ValidationReferenceProto)): + assert type(current_proto) == type(new_proto) + current_spec = cast(DataSourceProto, current_proto) + new_spec = cast(DataSourceProto, new_proto) + else: + current_spec = current_proto.spec + new_spec = new_proto.spec + if current != new: + for _field in current_spec.DESCRIPTOR.fields: + if _field.name in FIELDS_TO_IGNORE: + continue + elif getattr(current_spec, _field.name) != getattr(new_spec, _field.name): + if _field.name == "feature_transformation": + current_spec = cast(OnDemandFeatureViewSpec, current_spec) + new_spec = cast(OnDemandFeatureViewSpec, new_spec) + # Check if the old proto is populated and use that if it is + feature_transformation_udf = ( + current_spec.feature_transformation.user_defined_function + ) + if ( + current_spec.HasField("user_defined_function") + and not feature_transformation_udf + ): + deprecated_udf = current_spec.user_defined_function + else: + deprecated_udf = None + current_udf = ( + deprecated_udf + if deprecated_udf is not None + else feature_transformation_udf + ) + new_udf = new_spec.feature_transformation.user_defined_function + for _udf_field in current_udf.DESCRIPTOR.fields: + if _udf_field.name == "body": + continue + if getattr(current_udf, _udf_field.name) != getattr( + new_udf, _udf_field.name + ): + transition = TransitionType.UPDATE + property_diffs.append( + PropertyDiff( + _field.name + "." + _udf_field.name, + getattr(current_udf, _udf_field.name), + getattr(new_udf, _udf_field.name), + ) + ) + else: + transition = TransitionType.UPDATE + property_diffs.append( + PropertyDiff( + _field.name, + getattr(current_spec, _field.name), + getattr(new_spec, _field.name), + ) + ) + return FeastObjectDiff( + name=new_spec.name, + feast_object_type=object_type, + current_feast_object=current, + new_feast_object=new, + feast_object_property_diffs=property_diffs, + transition_type=transition, + ) + + +def extract_objects_for_keep_delete_update_add( + registry: BaseRegistry, + current_project: str, + desired_repo_contents: RepoContents, +) -> Tuple[ + Dict[FeastObjectType, Set[FeastObject]], + Dict[FeastObjectType, Set[FeastObject]], + Dict[FeastObjectType, Set[FeastObject]], + Dict[FeastObjectType, Set[FeastObject]], +]: + """ + Returns the objects in the registry that must be modified to achieve the desired repo state. + + Args: + registry: The registry storing the current repo state. + current_project: The Feast project whose objects should be compared. + desired_repo_contents: The desired repo state. + """ + objs_to_keep = {} + objs_to_delete = {} + objs_to_update = {} + objs_to_add = {} + + registry_object_type_to_objects: Dict[FeastObjectType, List[Any]] = ( + FeastObjectType.get_objects_from_registry(registry, current_project) + ) + registry_object_type_to_repo_contents: Dict[FeastObjectType, List[Any]] = ( + FeastObjectType.get_objects_from_repo_contents(desired_repo_contents) + ) + + for object_type in FEAST_OBJECT_TYPES: + ( + to_keep, + to_delete, + to_update, + to_add, + ) = tag_objects_for_keep_delete_update_add( + registry_object_type_to_objects[object_type], + registry_object_type_to_repo_contents[object_type], + ) + + objs_to_keep[object_type] = to_keep + objs_to_delete[object_type] = to_delete + objs_to_update[object_type] = to_update + objs_to_add[object_type] = to_add + + return objs_to_keep, objs_to_delete, objs_to_update, objs_to_add + + +def diff_between( + registry: BaseRegistry, + current_project: str, + desired_repo_contents: RepoContents, +) -> RegistryDiff: + """ + Returns the difference between the current and desired repo states. + + Args: + registry: The registry storing the current repo state. + current_project: The Feast project for which the diff is being computed. + desired_repo_contents: The desired repo state. + """ + diff = RegistryDiff() + + ( + objs_to_keep, + objs_to_delete, + objs_to_update, + objs_to_add, + ) = extract_objects_for_keep_delete_update_add( + registry, current_project, desired_repo_contents + ) + + for object_type in FEAST_OBJECT_TYPES: + objects_to_keep = objs_to_keep[object_type] + objects_to_delete = objs_to_delete[object_type] + objects_to_update = objs_to_update[object_type] + objects_to_add = objs_to_add[object_type] + + for e in objects_to_add: + diff.add_feast_object_diff( + FeastObjectDiff( + name=e.name, + feast_object_type=object_type, + current_feast_object=None, + new_feast_object=e, + feast_object_property_diffs=[], + transition_type=TransitionType.CREATE, + ) + ) + for e in objects_to_delete: + diff.add_feast_object_diff( + FeastObjectDiff( + name=e.name, + feast_object_type=object_type, + current_feast_object=e, + new_feast_object=None, + feast_object_property_diffs=[], + transition_type=TransitionType.DELETE, + ) + ) + for e in objects_to_update: + current_obj = [_e for _e in objects_to_keep if _e.name == e.name][0] + diff.add_feast_object_diff( + diff_registry_objects(current_obj, e, object_type) + ) + + return diff + + +def apply_diff_to_registry( + registry: BaseRegistry, + registry_diff: RegistryDiff, + project: str, + commit: bool = True, + no_promote: bool = False, +): + """ + Applies the given diff to the given Feast project in the registry. + + Args: + registry: The registry to be updated. + registry_diff: The diff to apply. + project: Feast project to be updated. + commit: Whether the change should be persisted immediately + no_promote: If True, save new feature view version snapshots without + promoting them to the active definition. New versions are accessible + only via explicit @v reads. + """ + for feast_object_diff in registry_diff.feast_object_diffs: + # There is no need to delete the object on an update, since applying the new object + # will automatically delete the existing object. + if feast_object_diff.transition_type == TransitionType.DELETE: + if feast_object_diff.feast_object_type == FeastObjectType.ENTITY: + entity_obj = cast(Entity, feast_object_diff.current_feast_object) + registry.delete_entity(entity_obj.name, project, commit=False) + elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE: + feature_service_obj = cast( + FeatureService, feast_object_diff.current_feast_object + ) + registry.delete_feature_service( + feature_service_obj.name, project, commit=False + ) + elif feast_object_diff.feast_object_type in [ + FeastObjectType.FEATURE_VIEW, + FeastObjectType.ON_DEMAND_FEATURE_VIEW, + FeastObjectType.STREAM_FEATURE_VIEW, + ]: + feature_view_obj = cast( + BaseFeatureView, feast_object_diff.current_feast_object + ) + registry.delete_feature_view( + feature_view_obj.name, + project, + commit=False, + ) + elif feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: + ds_obj = cast(DataSource, feast_object_diff.current_feast_object) + registry.delete_data_source( + ds_obj.name, + project, + commit=False, + ) + elif feast_object_diff.feast_object_type == FeastObjectType.PERMISSION: + permission_obj = cast( + Permission, feast_object_diff.current_feast_object + ) + registry.delete_permission( + permission_obj.name, + project, + commit=False, + ) + + if feast_object_diff.transition_type in [ + TransitionType.CREATE, + TransitionType.UPDATE, + ]: + if feast_object_diff.feast_object_type == FeastObjectType.PROJECT: + registry.apply_project( + cast(Project, feast_object_diff.new_feast_object), + commit=False, + ) + if feast_object_diff.feast_object_type == FeastObjectType.DATA_SOURCE: + registry.apply_data_source( + cast(DataSource, feast_object_diff.new_feast_object), + project, + commit=False, + ) + if feast_object_diff.feast_object_type == FeastObjectType.ENTITY: + registry.apply_entity( + cast(Entity, feast_object_diff.new_feast_object), + project, + commit=False, + ) + elif feast_object_diff.feast_object_type == FeastObjectType.FEATURE_SERVICE: + registry.apply_feature_service( + cast(FeatureService, feast_object_diff.new_feast_object), + project, + commit=False, + ) + elif feast_object_diff.feast_object_type in [ + FeastObjectType.FEATURE_VIEW, + FeastObjectType.ON_DEMAND_FEATURE_VIEW, + FeastObjectType.STREAM_FEATURE_VIEW, + ]: + registry.apply_feature_view( + cast(BaseFeatureView, feast_object_diff.new_feast_object), + project, + commit=False, + no_promote=no_promote, + ) + elif feast_object_diff.feast_object_type == FeastObjectType.PERMISSION: + registry.apply_permission( + cast(Permission, feast_object_diff.new_feast_object), + project, + commit=False, + ) + + if commit: + registry.commit() diff --git a/sdk/python/feast/embedded_go/online_features_service.py b/sdk/python/feast/embedded_go/online_features_service.py index 8dd7b5ba0a1..cc54808d4e2 100644 --- a/sdk/python/feast/embedded_go/online_features_service.py +++ b/sdk/python/feast/embedded_go/online_features_service.py @@ -1,345 +1,346 @@ -import logging -from functools import partial -from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union - -import pyarrow as pa -from google.protobuf.timestamp_pb2 import Timestamp -from pyarrow.cffi import ffi - -from feast.errors import ( - FeatureNameCollisionError, - RequestDataNotFoundInEntityRowsException, -) -from feast.feature_service import FeatureService -from feast.infra.feature_servers.base_config import FeatureLoggingConfig -from feast.online_response import OnlineResponse -from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesResponse -from feast.protos.feast.types import Value_pb2 -from feast.repo_config import RepoConfig -from feast.types import from_value_type -from feast.value_type import ValueType - -from .lib.embedded import ( - DataTable, - LoggingOptions, - NewOnlineFeatureService, - OnlineFeatureServiceConfig, -) -from .lib.go import Slice_string -from .type_map import FEAST_TYPE_TO_ARROW_TYPE, arrow_array_to_array_of_proto - -if TYPE_CHECKING: - from feast.feature_store import FeatureStore - -NANO_SECOND = 1 -MICRO_SECOND = 1000 * NANO_SECOND -MILLI_SECOND = 1000 * MICRO_SECOND -SECOND = 1000 * MILLI_SECOND - -logger = logging.getLogger(__name__) - - -class EmbeddedOnlineFeatureServer: - def __init__( - self, repo_path: str, repo_config: RepoConfig, feature_store: "FeatureStore" - ): - # keep callback in self to prevent it from GC - self._transformation_callback = partial(transformation_callback, feature_store) - self._logging_callback = partial(logging_callback, feature_store) - - self._config = OnlineFeatureServiceConfig( - RepoPath=repo_path, RepoConfig=repo_config.json() - ) - - self._service = NewOnlineFeatureService( - self._config, - self._transformation_callback, - ) - - # This should raise an exception if there were any errors in NewOnlineFeatureService. - self._service.CheckForInstantiationError() - - def get_online_features( - self, - features_refs: List[str], - feature_service: Optional[FeatureService], - entities: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], - request_data: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], - full_feature_names: bool = False, - ): - if feature_service: - join_keys_types = self._service.GetEntityTypesMapByFeatureService( - feature_service.name - ) - else: - join_keys_types = self._service.GetEntityTypesMap( - Slice_string(features_refs) - ) - - join_keys_types = { - join_key: ValueType(enum_value) for join_key, enum_value in join_keys_types - } - - # Here we create C structures that will be shared between Python and Go. - # We will pass entities as arrow Record Batch to Go part (in_c_array & in_c_schema) - # and receive features as Record Batch from Go (out_c_array & out_c_schema) - # This objects needs to be initialized here in order to correctly - # free them later using Python GC. - ( - entities_c_schema, - entities_ptr_schema, - entities_c_array, - entities_ptr_array, - ) = allocate_schema_and_array() - ( - req_data_c_schema, - req_data_ptr_schema, - req_data_c_array, - req_data_ptr_array, - ) = allocate_schema_and_array() - - ( - features_c_schema, - features_ptr_schema, - features_c_array, - features_ptr_array, - ) = allocate_schema_and_array() - - batch, schema = map_to_record_batch(entities, join_keys_types) - schema._export_to_c(entities_ptr_schema) - batch._export_to_c(entities_ptr_array) - - batch, schema = map_to_record_batch(request_data) - schema._export_to_c(req_data_ptr_schema) - batch._export_to_c(req_data_ptr_array) - - try: - self._service.GetOnlineFeatures( - featureRefs=Slice_string(features_refs), - featureServiceName=feature_service and feature_service.name or "", - entities=DataTable( - SchemaPtr=entities_ptr_schema, DataPtr=entities_ptr_array - ), - requestData=DataTable( - SchemaPtr=req_data_ptr_schema, DataPtr=req_data_ptr_array - ), - fullFeatureNames=full_feature_names, - output=DataTable( - SchemaPtr=features_ptr_schema, DataPtr=features_ptr_array - ), - ) - except RuntimeError as exc: - (msg,) = exc.args - if msg.startswith("featureNameCollisionError"): - feature_refs = msg[len("featureNameCollisionError: ") : msg.find(";")] - feature_refs = feature_refs.split(",") - raise FeatureNameCollisionError( - feature_refs_collisions=feature_refs, - full_feature_names=full_feature_names, - ) - - if msg.startswith("requestDataNotFoundInEntityRowsException"): - feature_refs = msg[len("requestDataNotFoundInEntityRowsException: ") :] - feature_refs = feature_refs.split(",") - raise RequestDataNotFoundInEntityRowsException(feature_refs) - - raise - - record_batch = pa.RecordBatch._import_from_c( - features_ptr_array, features_ptr_schema - ) - resp = record_batch_to_online_response(record_batch) - del record_batch - return OnlineResponse(resp) - - def start_grpc_server( - self, - host: str, - port: int, - enable_logging: bool = True, - logging_options: Optional[FeatureLoggingConfig] = None, - ): - if enable_logging: - if logging_options: - self._service.StartGprcServerWithLogging( - host, - port, - self._logging_callback, - LoggingOptions( - FlushInterval=logging_options.flush_interval_secs * SECOND, - WriteInterval=logging_options.write_to_disk_interval_secs - * SECOND, - EmitTimeout=logging_options.emit_timeout_micro_secs - * MICRO_SECOND, - ChannelCapacity=logging_options.queue_capacity, - ), - ) - else: - self._service.StartGprcServerWithLoggingDefaultOpts( - host, port, self._logging_callback - ) - else: - self._service.StartGprcServer(host, port) - - def start_http_server( - self, - host: str, - port: int, - enable_logging: bool = True, - logging_options: Optional[FeatureLoggingConfig] = None, - ): - if enable_logging: - if logging_options: - self._service.StartHttpServerWithLogging( - host, - port, - self._logging_callback, - LoggingOptions( - FlushInterval=logging_options.flush_interval_secs * SECOND, - WriteInterval=logging_options.write_to_disk_interval_secs - * SECOND, - EmitTimeout=logging_options.emit_timeout_micro_secs - * MICRO_SECOND, - ChannelCapacity=logging_options.queue_capacity, - ), - ) - else: - self._service.StartHttpServerWithLoggingDefaultOpts( - host, port, self._logging_callback - ) - else: - self._service.StartHttpServer(host, port) - - def stop_grpc_server(self): - self._service.StopGrpcServer() - - def stop_http_server(self): - self._service.StopHttpServer() - - -def _to_arrow(value, type_hint: Optional[ValueType]) -> pa.Array: - if isinstance(value, Value_pb2.RepeatedValue): - _proto_to_arrow(value) - - if type_hint: - feast_type = from_value_type(type_hint) - if feast_type in FEAST_TYPE_TO_ARROW_TYPE: - return pa.array(value, FEAST_TYPE_TO_ARROW_TYPE[feast_type]) - - return pa.array(value) - - -def _proto_to_arrow(value: Value_pb2.RepeatedValue) -> pa.Array: - """ - ToDo: support entity rows already packed in protos - """ - raise NotImplementedError - - -def transformation_callback( - fs: "FeatureStore", - on_demand_feature_view_name: str, - input_arr_ptr: int, - input_schema_ptr: int, - output_arr_ptr: int, - output_schema_ptr: int, - full_feature_names: bool, -) -> int: - try: - odfv = fs.get_on_demand_feature_view(on_demand_feature_view_name) - - input_record = pa.RecordBatch._import_from_c(input_arr_ptr, input_schema_ptr) - - # For some reason, the callback is called with `full_feature_names` as a 1 if True or 0 if false. This handles - # the typeguard requirement. - full_feature_names = bool(full_feature_names) - - if odfv.mode != "pandas": - raise Exception( - f"OnDemandFeatureView mode '{odfv.mode} not supported by EmbeddedOnlineFeatureServer." - ) - - output = odfv.get_transformed_features_df( # type: ignore - input_record.to_pandas(), full_feature_names=full_feature_names - ) - output_record = pa.RecordBatch.from_pandas(output) - - output_record.schema._export_to_c(output_schema_ptr) - output_record._export_to_c(output_arr_ptr) - - return output_record.num_rows - except Exception as e: - logger.exception(f"transformation callback failed with exception: {e}", e) - return 0 - - -def logging_callback( - fs: "FeatureStore", - feature_service_name: str, - dataset_dir: str, -) -> bytes: - feature_service = fs.get_feature_service(feature_service_name, allow_cache=True) - try: - fs.write_logged_features(logs=Path(dataset_dir), source=feature_service) - except Exception as exc: - return repr(exc).encode() - - return "".encode() # no error - - -def allocate_schema_and_array(): - c_schema = ffi.new("struct ArrowSchema*") - ptr_schema = int(ffi.cast("uintptr_t", c_schema)) - - c_array = ffi.new("struct ArrowArray*") - ptr_array = int(ffi.cast("uintptr_t", c_array)) - return c_schema, ptr_schema, c_array, ptr_array - - -def map_to_record_batch( - map: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], - type_hint: Optional[Dict[str, ValueType]] = None, -) -> Tuple[pa.RecordBatch, pa.Schema]: - fields = [] - columns = [] - type_hint = type_hint or {} - - for name, values in map.items(): - arr = _to_arrow(values, type_hint.get(name)) - fields.append((name, arr.type)) - columns.append(arr) - - schema = pa.schema(fields) - batch = pa.RecordBatch.from_arrays(columns, schema=schema) - return batch, schema - - -def record_batch_to_online_response(record_batch): - resp = GetOnlineFeaturesResponse() - - for idx, field in enumerate(record_batch.schema): - if field.name.endswith("__timestamp") or field.name.endswith("__status"): - continue - - feature_vector = GetOnlineFeaturesResponse.FeatureVector( - statuses=record_batch.columns[idx + 1].to_pylist(), - event_timestamps=[ - Timestamp(seconds=seconds) - for seconds in record_batch.columns[idx + 2].to_pylist() - ], - ) - - if field.type == pa.null(): - feature_vector.values.extend( - [Value_pb2.Value()] * len(record_batch.columns[idx]) - ) - else: - feature_vector.values.extend( - arrow_array_to_array_of_proto(field.type, record_batch.columns[idx]) - ) - - resp.results.append(feature_vector) - resp.metadata.feature_names.val.append(field.name) - - return resp +import logging +from functools import partial +from pathlib import Path +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union + +import pyarrow as pa +from google.protobuf.timestamp_pb2 import Timestamp +from pyarrow.cffi import ffi + +from feast.errors import ( + FeatureNameCollisionError, + RequestDataNotFoundInEntityRowsException, +) +from feast.feature_service import FeatureService +from feast.infra.feature_servers.base_config import FeatureLoggingConfig +from feast.online_response import OnlineResponse +from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesResponse +from feast.protos.feast.types import Value_pb2 +from feast.repo_config import RepoConfig +from feast.types import from_value_type +from feast.value_type import ValueType + +from .lib.embedded import ( + DataTable, + LoggingOptions, + NewOnlineFeatureService, + OnlineFeatureServiceConfig, +) +from .lib.go import Slice_string +from .type_map import FEAST_TYPE_TO_ARROW_TYPE, arrow_array_to_array_of_proto + +if TYPE_CHECKING: + from feast.feature_store import FeatureStore + +NANO_SECOND = 1 +MICRO_SECOND = 1000 * NANO_SECOND +MILLI_SECOND = 1000 * MICRO_SECOND +SECOND = 1000 * MILLI_SECOND + +logger = logging.getLogger(__name__) + + +class EmbeddedOnlineFeatureServer: + def __init__( + self, repo_path: str, repo_config: RepoConfig, feature_store: "FeatureStore" + ): + # keep callback in self to prevent it from GC + self._transformation_callback = partial(transformation_callback, feature_store) + self._logging_callback = partial(logging_callback, feature_store) + + self._config = OnlineFeatureServiceConfig( + RepoPath=repo_path, RepoConfig=repo_config.json() + ) + + self._service = NewOnlineFeatureService( + self._config, + self._transformation_callback, + ) + + # This should raise an exception if there were any errors in NewOnlineFeatureService. + self._service.CheckForInstantiationError() + + def get_online_features( + self, + features_refs: List[str], + feature_service: Optional[FeatureService], + entities: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], + request_data: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], + full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, + ): + if feature_service: + join_keys_types = self._service.GetEntityTypesMapByFeatureService( + feature_service.name + ) + else: + join_keys_types = self._service.GetEntityTypesMap( + Slice_string(features_refs) + ) + + join_keys_types = { + join_key: ValueType(enum_value) for join_key, enum_value in join_keys_types + } + + # Here we create C structures that will be shared between Python and Go. + # We will pass entities as arrow Record Batch to Go part (in_c_array & in_c_schema) + # and receive features as Record Batch from Go (out_c_array & out_c_schema) + # This objects needs to be initialized here in order to correctly + # free them later using Python GC. + ( + entities_c_schema, + entities_ptr_schema, + entities_c_array, + entities_ptr_array, + ) = allocate_schema_and_array() + ( + req_data_c_schema, + req_data_ptr_schema, + req_data_c_array, + req_data_ptr_array, + ) = allocate_schema_and_array() + + ( + features_c_schema, + features_ptr_schema, + features_c_array, + features_ptr_array, + ) = allocate_schema_and_array() + + batch, schema = map_to_record_batch(entities, join_keys_types) + schema._export_to_c(entities_ptr_schema) + batch._export_to_c(entities_ptr_array) + + batch, schema = map_to_record_batch(request_data) + schema._export_to_c(req_data_ptr_schema) + batch._export_to_c(req_data_ptr_array) + + try: + self._service.GetOnlineFeatures( + featureRefs=Slice_string(features_refs), + featureServiceName=feature_service and feature_service.name or "", + entities=DataTable( + SchemaPtr=entities_ptr_schema, DataPtr=entities_ptr_array + ), + requestData=DataTable( + SchemaPtr=req_data_ptr_schema, DataPtr=req_data_ptr_array + ), + fullFeatureNames=full_feature_names, + output=DataTable( + SchemaPtr=features_ptr_schema, DataPtr=features_ptr_array + ), + ) + except RuntimeError as exc: + (msg,) = exc.args + if msg.startswith("featureNameCollisionError"): + feature_refs = msg[len("featureNameCollisionError: ") : msg.find(";")] + feature_refs = feature_refs.split(",") + raise FeatureNameCollisionError( + feature_refs_collisions=feature_refs, + full_feature_names=full_feature_names, + ) + + if msg.startswith("requestDataNotFoundInEntityRowsException"): + feature_refs = msg[len("requestDataNotFoundInEntityRowsException: ") :] + feature_refs = feature_refs.split(",") + raise RequestDataNotFoundInEntityRowsException(feature_refs) + + raise + + record_batch = pa.RecordBatch._import_from_c( + features_ptr_array, features_ptr_schema + ) + resp = record_batch_to_online_response(record_batch) + del record_batch + return OnlineResponse(resp) + + def start_grpc_server( + self, + host: str, + port: int, + enable_logging: bool = True, + logging_options: Optional[FeatureLoggingConfig] = None, + ): + if enable_logging: + if logging_options: + self._service.StartGprcServerWithLogging( + host, + port, + self._logging_callback, + LoggingOptions( + FlushInterval=logging_options.flush_interval_secs * SECOND, + WriteInterval=logging_options.write_to_disk_interval_secs + * SECOND, + EmitTimeout=logging_options.emit_timeout_micro_secs + * MICRO_SECOND, + ChannelCapacity=logging_options.queue_capacity, + ), + ) + else: + self._service.StartGprcServerWithLoggingDefaultOpts( + host, port, self._logging_callback + ) + else: + self._service.StartGprcServer(host, port) + + def start_http_server( + self, + host: str, + port: int, + enable_logging: bool = True, + logging_options: Optional[FeatureLoggingConfig] = None, + ): + if enable_logging: + if logging_options: + self._service.StartHttpServerWithLogging( + host, + port, + self._logging_callback, + LoggingOptions( + FlushInterval=logging_options.flush_interval_secs * SECOND, + WriteInterval=logging_options.write_to_disk_interval_secs + * SECOND, + EmitTimeout=logging_options.emit_timeout_micro_secs + * MICRO_SECOND, + ChannelCapacity=logging_options.queue_capacity, + ), + ) + else: + self._service.StartHttpServerWithLoggingDefaultOpts( + host, port, self._logging_callback + ) + else: + self._service.StartHttpServer(host, port) + + def stop_grpc_server(self): + self._service.StopGrpcServer() + + def stop_http_server(self): + self._service.StopHttpServer() + + +def _to_arrow(value, type_hint: Optional[ValueType]) -> pa.Array: + if isinstance(value, Value_pb2.RepeatedValue): + _proto_to_arrow(value) + + if type_hint: + feast_type = from_value_type(type_hint) + if feast_type in FEAST_TYPE_TO_ARROW_TYPE: + return pa.array(value, FEAST_TYPE_TO_ARROW_TYPE[feast_type]) + + return pa.array(value) + + +def _proto_to_arrow(value: Value_pb2.RepeatedValue) -> pa.Array: + """ + ToDo: support entity rows already packed in protos + """ + raise NotImplementedError + + +def transformation_callback( + fs: "FeatureStore", + on_demand_feature_view_name: str, + input_arr_ptr: int, + input_schema_ptr: int, + output_arr_ptr: int, + output_schema_ptr: int, + full_feature_names: bool, +) -> int: + try: + odfv = fs.get_on_demand_feature_view(on_demand_feature_view_name) + + input_record = pa.RecordBatch._import_from_c(input_arr_ptr, input_schema_ptr) + + # For some reason, the callback is called with `full_feature_names` as a 1 if True or 0 if false. This handles + # the typeguard requirement. + full_feature_names = bool(full_feature_names) + + if odfv.mode != "pandas": + raise Exception( + f"OnDemandFeatureView mode '{odfv.mode} not supported by EmbeddedOnlineFeatureServer." + ) + + output = odfv.get_transformed_features_df( # type: ignore + input_record.to_pandas(), full_feature_names=full_feature_names + ) + output_record = pa.RecordBatch.from_pandas(output) + + output_record.schema._export_to_c(output_schema_ptr) + output_record._export_to_c(output_arr_ptr) + + return output_record.num_rows + except Exception as e: + logger.exception(f"transformation callback failed with exception: {e}", e) + return 0 + + +def logging_callback( + fs: "FeatureStore", + feature_service_name: str, + dataset_dir: str, +) -> bytes: + feature_service = fs.get_feature_service(feature_service_name, allow_cache=True) + try: + fs.write_logged_features(logs=Path(dataset_dir), source=feature_service) + except Exception as exc: + return repr(exc).encode() + + return "".encode() # no error + + +def allocate_schema_and_array(): + c_schema = ffi.new("struct ArrowSchema*") + ptr_schema = int(ffi.cast("uintptr_t", c_schema)) + + c_array = ffi.new("struct ArrowArray*") + ptr_array = int(ffi.cast("uintptr_t", c_array)) + return c_schema, ptr_schema, c_array, ptr_array + + +def map_to_record_batch( + map: Dict[str, Union[List[Any], Value_pb2.RepeatedValue]], + type_hint: Optional[Dict[str, ValueType]] = None, +) -> Tuple[pa.RecordBatch, pa.Schema]: + fields = [] + columns = [] + type_hint = type_hint or {} + + for name, values in map.items(): + arr = _to_arrow(values, type_hint.get(name)) + fields.append((name, arr.type)) + columns.append(arr) + + schema = pa.schema(fields) + batch = pa.RecordBatch.from_arrays(columns, schema=schema) + return batch, schema + + +def record_batch_to_online_response(record_batch): + resp = GetOnlineFeaturesResponse() + + for idx, field in enumerate(record_batch.schema): + if field.name.endswith("__timestamp") or field.name.endswith("__status"): + continue + + feature_vector = GetOnlineFeaturesResponse.FeatureVector( + statuses=record_batch.columns[idx + 1].to_pylist(), + event_timestamps=[ + Timestamp(seconds=seconds) + for seconds in record_batch.columns[idx + 2].to_pylist() + ], + ) + + if field.type == pa.null(): + feature_vector.values.extend( + [Value_pb2.Value()] * len(record_batch.columns[idx]) + ) + else: + feature_vector.values.extend( + arrow_array_to_array_of_proto(field.type, record_batch.columns[idx]) + ) + + resp.results.append(feature_vector) + resp.metadata.feature_names.val.append(field.name) + + return resp diff --git a/sdk/python/feast/errors.py b/sdk/python/feast/errors.py index 53895344d3b..f2dd5687ecb 100644 --- a/sdk/python/feast/errors.py +++ b/sdk/python/feast/errors.py @@ -128,6 +128,38 @@ def __init__(self, name, project=None): super().__init__(f"Feature view {name} does not exist") +class FeatureViewVersionNotFound(FeastObjectNotFoundException): + def __init__(self, name, version, project=None): + if project: + super().__init__( + f"Version {version} of feature view {name} does not exist in project {project}" + ) + else: + super().__init__(f"Version {version} of feature view {name} does not exist") + + +class VersionedOnlineReadNotSupported(FeastError): + def __init__(self, store_name: str, version: int): + super().__init__( + f"Versioned feature reads (@v{version}) are not yet supported by {store_name}. " + f"Currently only SQLite supports version-qualified feature references. " + ) + + +class FeatureViewPinConflict(FeastError): + def __init__(self, name, version): + super().__init__( + f"Cannot pin feature view '{name}' to {version} because the definition has also been modified. " + f"To pin to an older version, only change the 'version' parameter — do not modify other fields. " + f"To apply a new definition, use version='latest' or omit the version parameter." + ) + + +class ConcurrentVersionConflict(FeastError): + def __init__(self, msg: str): + super().__init__(msg) + + class OnDemandFeatureViewNotFoundException(FeastObjectNotFoundException): def __init__(self, name, project=None): if project: diff --git a/sdk/python/feast/feature_server.py b/sdk/python/feast/feature_server.py index a093795c42a..7469e31a20e 100644 --- a/sdk/python/feast/feature_server.py +++ b/sdk/python/feast/feature_server.py @@ -99,12 +99,14 @@ class GetOnlineFeaturesRequest(BaseModel): feature_service: Optional[str] = None features: List[str] = [] full_feature_names: bool = False + include_feature_view_version_metadata: bool = False class GetOnlineDocumentsRequest(BaseModel): feature_service: Optional[str] = None features: List[str] = [] full_feature_names: bool = False + include_feature_view_version_metadata: bool = False top_k: Optional[int] = None query: Optional[List[float]] = None query_string: Optional[str] = None @@ -162,7 +164,7 @@ def _resolve_feature_counts( feat_count = sum(len(p.features) for p in projections) elif isinstance(features, list): feat_count = len(features) - fv_names = {ref.split(":")[0] for ref in features if ":" in ref} + fv_names = {ref.split(":")[0].split("@")[0] for ref in features if ":" in ref} fv_count = len(fv_names) else: feat_count = 0 @@ -382,6 +384,7 @@ async def get_online_features(request: GetOnlineFeaturesRequest) -> Any: features=features, entity_rows=request.entities, full_feature_names=request.full_feature_names, + include_feature_view_version_metadata=request.include_feature_view_version_metadata, ) if store._get_provider().async_supported.online.read: @@ -414,12 +417,17 @@ async def retrieve_online_documents( features = await _get_features(request, store) read_params = dict( - features=features, query=request.query, top_k=request.top_k + features=features, + query=request.query, + top_k=request.top_k, ) if request.api_version == 2 and request.query_string is not None: read_params["query_string"] = request.query_string if request.api_version == 2: + read_params["include_feature_view_version_metadata"] = ( + request.include_feature_view_version_metadata + ) response = await run_in_threadpool( lambda: store.retrieve_online_documents_v2(**read_params) # type: ignore ) diff --git a/sdk/python/feast/feature_store.py b/sdk/python/feast/feature_store.py index 8e16b0a30a4..b930b2099d0 100644 --- a/sdk/python/feast/feature_store.py +++ b/sdk/python/feast/feature_store.py @@ -100,6 +100,7 @@ from feast.transformation.pandas_transformation import PandasTransformation from feast.transformation.python_transformation import PythonTransformation from feast.utils import _get_feature_view_vector_field_metadata, _utc_now +from feast.version_utils import parse_version _track_materialization = None # Lazy-loaded on first materialization call _track_materialization_loaded = False @@ -568,6 +569,18 @@ def _get_feature_view( feature_view.entities = [] return feature_view + def list_feature_view_versions(self, name: str) -> List[Dict[str, Any]]: + """ + List version history for a feature view. + + Args: + name: Name of feature view. + + Returns: + List of version records. + """ + return self.registry.list_feature_view_versions(name, self.project) + def get_stream_feature_view( self, name: str, allow_registry_cache: bool = False ) -> StreamFeatureView: @@ -760,9 +773,39 @@ def _make_inferences( for feature_service in feature_services_to_update: feature_service.infer_features(fvs_to_update=fvs_to_update_map) + def _validate_materialize_version( + self, + version: Optional[str], + feature_views: Optional[List[str]], + ) -> Optional[int]: + """Validate and parse the version parameter for materialize calls. + + Returns the parsed version number, or None if no version was specified. + """ + if version is None: + return None + + if not feature_views or len(feature_views) != 1: + raise ValueError( + "--version requires --views with exactly one feature view." + ) + + if not self.config.registry.enable_online_feature_view_versioning: + raise ValueError( + "Version-aware materialization requires " + "'enable_online_feature_view_versioning: true' under 'registry' " + "in feature_store.yaml." + ) + + is_latest, version_number = parse_version(version) + if is_latest: + return None + return version_number + def _get_feature_views_to_materialize( self, feature_views: Optional[List[str]], + version: Optional[int] = None, ) -> List[Union[FeatureView, OnDemandFeatureView]]: """ Returns the list of feature views that should be materialized. @@ -771,6 +814,8 @@ def _get_feature_views_to_materialize( Args: feature_views: List of names of feature views to materialize. + version: If set, load this specific version number from the registry + instead of the active definition. Requires exactly one feature view name. Raises: FeatureViewNotFoundException: One of the specified feature views could not be found. @@ -802,15 +847,25 @@ def _get_feature_views_to_materialize( else: for name in feature_views: feature_view: Union[FeatureView, OnDemandFeatureView] - try: - feature_view = self._get_feature_view(name, hide_dummy_entity=False) - except FeatureViewNotFoundException: + if version is not None: + feature_view = cast( + Union[FeatureView, OnDemandFeatureView], + self.registry.get_feature_view_by_version( + name, self.project, version + ), + ) + else: try: - feature_view = self._get_stream_feature_view( + feature_view = self._get_feature_view( name, hide_dummy_entity=False ) except FeatureViewNotFoundException: - feature_view = self.get_on_demand_feature_view(name) + try: + feature_view = self._get_stream_feature_view( + name, hide_dummy_entity=False + ) + except FeatureViewNotFoundException: + feature_view = self.get_on_demand_feature_view(name) if hasattr(feature_view, "online") and not feature_view.online: raise ValueError( @@ -920,6 +975,7 @@ def _apply_diffs( infra_diff: InfraDiff, new_infra: Infra, progress_ctx: Optional["ApplyProgressContext"] = None, + no_promote: bool = False, ): """Applies the given diffs to the metadata store and infrastructure. @@ -943,7 +999,11 @@ def _apply_diffs( # Registry phase apply_diff_to_registry( - self.registry, registry_diff, self.project, commit=False + self.registry, + registry_diff, + self.project, + commit=False, + no_promote=no_promote, ) if progress_ctx: @@ -994,6 +1054,7 @@ def apply( objects_to_delete: Optional[List[FeastObject]] = None, partial: bool = True, skip_feature_view_validation: bool = False, + no_promote: bool = False, ): """Register objects to metadata store and update related infrastructure. @@ -1136,9 +1197,12 @@ def apply( for ds in data_sources_to_update: self.registry.apply_data_source(ds, project=self.project, commit=False) for view in itertools.chain(views_to_update, odfvs_to_update, sfvs_to_update): - self.registry.apply_feature_view(view, project=self.project, commit=False) + self.registry.apply_feature_view( + view, project=self.project, commit=False, no_promote=no_promote + ) for ent in entities_to_update: self.registry.apply_entity(ent, project=self.project, commit=False) + for feature_service in services_to_update: self.registry.apply_feature_service( feature_service, project=self.project, commit=False @@ -1633,6 +1697,7 @@ def materialize_incremental( end_date: datetime, feature_views: Optional[List[str]] = None, full_feature_names: bool = False, + version: Optional[str] = None, ) -> None: """ Materialize incremental new data from the offline store into the online store. @@ -1649,6 +1714,8 @@ def materialize_incremental( materialization for the specified feature views. full_feature_names (bool): If True, feature names will be prefixed with the corresponding feature view name. + version (str): Optional version to materialize (e.g., 'v2'). Requires feature_views + with exactly one entry and enable_online_feature_view_versioning to be enabled. Raises: Exception: A feature view being materialized does not have a TTL set. @@ -1664,8 +1731,9 @@ def materialize_incremental( ... """ + parsed_version = self._validate_materialize_version(version, feature_views) feature_views_to_materialize = self._get_feature_views_to_materialize( - feature_views + feature_views, version=parsed_version ) _print_materialization_log( None, @@ -1786,6 +1854,7 @@ def materialize( feature_views: Optional[List[str]] = None, disable_event_timestamp: bool = False, full_feature_names: bool = False, + version: Optional[str] = None, ) -> None: """ Materialize data from the offline store into the online store. @@ -1802,6 +1871,8 @@ def materialize( disable_event_timestamp (bool): If True, materializes all available data using current datetime as event timestamp instead of source event timestamps full_feature_names (bool): If True, feature names will be prefixed with the corresponding feature view name. + version (str): Optional version to materialize (e.g., 'v2'). Requires feature_views + with exactly one entry and enable_online_feature_view_versioning to be enabled. Examples: Materialize all features into the online store over the interval @@ -1821,8 +1892,9 @@ def materialize( f"The given start_date {start_date} is greater than the given end_date {end_date}." ) + parsed_version = self._validate_materialize_version(version, feature_views) feature_views_to_materialize = self._get_feature_views_to_materialize( - feature_views + feature_views, version=parsed_version ) _print_materialization_log( start_date, @@ -2491,6 +2563,7 @@ def get_online_features( Mapping[str, Union[Sequence[Any], Sequence[Value], RepeatedValue]], ], full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: """ Retrieves the latest online feature data. @@ -2542,6 +2615,7 @@ def get_online_features( registry=self.registry, project=self.project, full_feature_names=full_feature_names, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) return response @@ -2554,6 +2628,7 @@ async def get_online_features_async( Mapping[str, Union[Sequence[Any], Sequence[Value], RepeatedValue]], ], full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: """ [Alpha] Retrieves the latest online feature data asynchronously. @@ -2590,6 +2665,7 @@ async def get_online_features_async( registry=self.registry, project=self.project, full_feature_names=full_feature_names, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) def retrieve_online_documents( @@ -2625,13 +2701,15 @@ def retrieve_online_documents( ) feature_view_set = set() for _feature in features: - feature_view_name = _feature.split(":")[0] - feature_view = self.get_feature_view(feature_view_name) + fv_name, _, _ = utils._parse_feature_ref(_feature) + feature_view = self.get_feature_view(fv_name) feature_view_set.add(feature_view.name) if len(feature_view_set) > 1: raise ValueError("Document retrieval only supports a single feature view.") requested_features = [ - f.split(":")[1] for f in features if isinstance(f, str) and ":" in f + utils._parse_feature_ref(f)[2] + for f in features + if isinstance(f, str) and ":" in f ] requested_feature_view_name = list(feature_view_set)[0] for feature_view in available_feature_views: @@ -2705,6 +2783,7 @@ def retrieve_online_documents_v2( text_weight: float = 0.5, image_weight: float = 0.5, combine_strategy: str = "weighted_sum", + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: """ Retrieves the top k closest document features. Note, embeddings are a subset of features. @@ -2826,18 +2905,20 @@ def retrieve_online_documents_v2( ) feature_view_set = set() for feature in features: - feature_view_name = feature.split(":")[0] - if feature_view_name in [fv.name for fv in available_odfv_views]: + fv_name, _, _ = utils._parse_feature_ref(feature) + if fv_name in [fv.name for fv in available_odfv_views]: feature_view: Union[OnDemandFeatureView, FeatureView] = ( - self.get_on_demand_feature_view(feature_view_name) + self.get_on_demand_feature_view(fv_name) ) else: - feature_view = self.get_feature_view(feature_view_name) + feature_view = self.get_feature_view(fv_name) feature_view_set.add(feature_view.name) if len(feature_view_set) > 1: raise ValueError("Document retrieval only supports a single feature view.") requested_features = [ - f.split(":")[1] for f in features if isinstance(f, str) and ":" in f + utils._parse_feature_ref(f)[2] + for f in features + if isinstance(f, str) and ":" in f ] if len(available_feature_views) == 0: available_feature_views.extend(available_odfv_views) # type: ignore[arg-type] @@ -2857,6 +2938,7 @@ def retrieve_online_documents_v2( top_k, distance_metric, query_string, + include_feature_view_version_metadata, ) def _retrieve_from_online_store( @@ -2921,6 +3003,7 @@ def _retrieve_from_online_store_v2( top_k: int, distance_metric: Optional[str], query_string: Optional[str], + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: """ Search and return document features from the online document store. @@ -2937,6 +3020,7 @@ def _retrieve_from_online_store_v2( top_k=top_k, distance_metric=distance_metric, query_string=query_string, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) entity_key_dict: Dict[str, List[ValueProto]] = {} @@ -2994,6 +3078,7 @@ def _retrieve_from_online_store_v2( requested_features=features_to_request, table=table, output_len=output_len, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) utils._populate_result_rows_from_columnar( diff --git a/sdk/python/feast/feature_view.py b/sdk/python/feast/feature_view.py index 94e95da545f..3863634ac80 100644 --- a/sdk/python/feast/feature_view.py +++ b/sdk/python/feast/feature_view.py @@ -44,6 +44,7 @@ from feast.transformation.mode import TransformationMode from feast.types import from_value_type from feast.value_type import ValueType +from feast.version_utils import normalize_version_string warnings.simplefilter("once", DeprecationWarning) @@ -126,6 +127,7 @@ def __init__( owner: str = "", mode: Optional[Union["TransformationMode", str]] = None, enable_validation: bool = False, + version: str = "latest", ): """ Creates a FeatureView object. @@ -154,11 +156,16 @@ def __init__( when transformations are applied. Choose from TransformationMode enum values. enable_validation (optional): If True, enables schema validation during materialization to check that data conforms to the declared feature types. Default is False. + version (optional): Version string for definition management. Controls which historical + snapshot is active after ``feast apply``. Only one version can be active per feature + view name per project. For concurrent multi-version testing, use separate projects + or distinct feature view names. Default is "latest". Raises: ValueError: A field mapping conflicts with an Entity or a Feature. """ self.name = name + self.version = version self.enable_validation = enable_validation self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME] self.ttl = ttl @@ -292,6 +299,9 @@ def __copy__(self): offline=self.offline, sink_source=self.batch_source if self.source_views else None, enable_validation=self.enable_validation, + version=self.version, + description=self.description, + owner=self.owner, ) # This is deliberately set outside of the FV initialization as we do not have the Entity objects. @@ -301,6 +311,28 @@ def __copy__(self): fv.projection = copy.copy(self.projection) return fv + def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool: + """Check for FeatureView schema/UDF changes.""" + if super()._schema_or_udf_changed(other): + return True + + if not isinstance(other, FeatureView): + return True + + # Schema-related fields + if sorted(self.entities) != sorted(other.entities): + return True + if sorted(self.entity_columns) != sorted(other.entity_columns): + return True + if self.source_views != other.source_views: + return True + + # Skip UDF-related data source fields: batch_source, stream_source + # (treat as deployment configuration, not schema changes) + # Skip configuration: ttl, online, offline, enable_validation + # Skip metadata: materialization_intervals (excluded in current equality) + return False + def __eq__(self, other): if not isinstance(other, FeatureView): raise TypeError( @@ -321,6 +353,8 @@ def __eq__(self, other): or self.source_views != other.source_views or self.materialization_intervals != other.materialization_intervals or self.enable_validation != other.enable_validation + or normalize_version_string(self.version) + != normalize_version_string(other.version) ): return False @@ -460,6 +494,7 @@ def to_proto_spec( feature_transformation=feature_transformation_proto, mode=mode_to_string(self.mode), enable_validation=self.enable_validation, + version=self.version, ) def to_proto_meta(self): @@ -473,6 +508,8 @@ def to_proto_meta(self): interval_proto.start_time.FromDatetime(interval[0]) interval_proto.end_time.FromDatetime(interval[1]) meta.materialization_intervals.append(interval_proto) + if self.current_version_number is not None: + meta.current_version_number = self.current_version_number return meta def get_ttl_duration(self): @@ -632,6 +669,17 @@ def _from_proto_internal( # Restore enable_validation from proto field. feature_view.enable_validation = feature_view_proto.spec.enable_validation + # Restore version fields. + spec_version = feature_view_proto.spec.version + feature_view.version = spec_version or "latest" + cvn = feature_view_proto.meta.current_version_number + if cvn > 0: + feature_view.current_version_number = cvn + elif cvn == 0 and spec_version and spec_version.lower() != "latest": + feature_view.current_version_number = 0 + else: + feature_view.current_version_number = None + # FeatureViewProjections are not saved in the FeatureView proto. # Create the default projection. feature_view.projection = FeatureViewProjection.from_feature_view_definition( diff --git a/sdk/python/feast/feature_view_projection.py b/sdk/python/feast/feature_view_projection.py index 530194ec6a8..a19afda458e 100644 --- a/sdk/python/feast/feature_view_projection.py +++ b/sdk/python/feast/feature_view_projection.py @@ -47,9 +47,13 @@ class FeatureViewProjection: date_partition_column: Optional[str] = None created_timestamp_column: Optional[str] = None batch_source: Optional[DataSource] = None + version_tag: Optional[int] = None def name_to_use(self): - return self.name_alias or self.name + base = self.name_alias or self.name + if self.version_tag is not None: + return f"{base}@v{self.version_tag}" + return base def to_proto(self) -> FeatureViewProjectionProto: batch_source = None @@ -70,6 +74,9 @@ def to_proto(self) -> FeatureViewProjectionProto: for feature in self.features: feature_reference_proto.feature_columns.append(feature.to_proto()) + if self.version_tag is not None: + feature_reference_proto.version_tag = self.version_tag + return feature_reference_proto @staticmethod @@ -93,6 +100,9 @@ def from_proto(proto: FeatureViewProjectionProto) -> "FeatureViewProjection": for feature_column in proto.feature_columns: feature_view_projection.features.append(Field.from_proto(feature_column)) + if proto.HasField("version_tag"): + feature_view_projection.version_tag = proto.version_tag + return feature_view_projection @staticmethod diff --git a/sdk/python/feast/infra/offline_stores/contrib/oracle_offline_store/oracle.py b/sdk/python/feast/infra/offline_stores/contrib/oracle_offline_store/oracle.py index ecabab517b0..43c37f8ec10 100644 --- a/sdk/python/feast/infra/offline_stores/contrib/oracle_offline_store/oracle.py +++ b/sdk/python/feast/infra/offline_stores/contrib/oracle_offline_store/oracle.py @@ -191,7 +191,6 @@ def pull_latest_from_table_or_query( start_date: datetime, end_date: datetime, ) -> RetrievalJob: - con = get_ibis_connection(config) return pull_latest_from_table_or_query_ibis( diff --git a/sdk/python/feast/infra/offline_stores/ibis.py b/sdk/python/feast/infra/offline_stores/ibis.py index 2d0adbfdb73..e7e94af31e4 100644 --- a/sdk/python/feast/infra/offline_stores/ibis.py +++ b/sdk/python/feast/infra/offline_stores/ibis.py @@ -197,7 +197,7 @@ def read_fv( } ) - full_name_prefix = feature_view.projection.name_alias or feature_view.name + full_name_prefix = feature_view.projection.name_to_use() feature_refs = [ fr.split(":")[1] @@ -205,13 +205,16 @@ def read_fv( if fr.startswith(f"{full_name_prefix}:") ] + # Use base name (without version) for column naming + base_name_prefix = feature_view.projection.name_alias or feature_view.name + if full_feature_names: fv_table = fv_table.rename( - {f"{full_name_prefix}__{feature}": feature for feature in feature_refs} + {f"{base_name_prefix}__{feature}": feature for feature in feature_refs} ) feature_refs = [ - f"{full_name_prefix}__{feature}" for feature in feature_refs + f"{base_name_prefix}__{feature}" for feature in feature_refs ] return ( diff --git a/sdk/python/feast/infra/online_stores/elasticsearch_online_store/elasticsearch.py b/sdk/python/feast/infra/online_stores/elasticsearch_online_store/elasticsearch.py index 7e8e533281d..b78d003ac25 100644 --- a/sdk/python/feast/infra/online_stores/elasticsearch_online_store/elasticsearch.py +++ b/sdk/python/feast/infra/online_stores/elasticsearch_online_store/elasticsearch.py @@ -279,8 +279,7 @@ def retrieve_online_documents( requested_features: List[str], embedding: List[float], top_k: int, - *args, - **kwargs, + distance_metric: Optional[str] = None, ) -> List[ Tuple[ Optional[datetime], @@ -349,6 +348,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/online_stores/faiss_online_store.py b/sdk/python/feast/infra/online_stores/faiss_online_store.py index 4b666f60f40..3e3d92cde6d 100644 --- a/sdk/python/feast/infra/online_stores/faiss_online_store.py +++ b/sdk/python/feast/infra/online_stores/faiss_online_store.py @@ -176,7 +176,7 @@ def retrieve_online_documents( self, config: RepoConfig, table: FeatureView, - requested_featres: List[str], + requested_features: List[str], embedding: List[float], top_k: int, distance_metric: Optional[str] = None, diff --git a/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py b/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py index fb812f82b7b..ee2534684cc 100644 --- a/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py +++ b/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py @@ -522,6 +522,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/online_stores/online_store.py b/sdk/python/feast/infra/online_stores/online_store.py index 49cb2c55ef2..4913046470c 100644 --- a/sdk/python/feast/infra/online_stores/online_store.py +++ b/sdk/python/feast/infra/online_stores/online_store.py @@ -18,6 +18,7 @@ from feast import Entity, utils from feast.batch_feature_view import BatchFeatureView +from feast.errors import VersionedOnlineReadNotSupported from feast.feature_service import FeatureService from feast.feature_view import FeatureView from feast.infra.infra_object import InfraObject @@ -154,6 +155,7 @@ def get_online_features( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: if isinstance(entity_rows, list): columnar: Dict[str, List[Any]] = {k: [] for k in entity_rows[0].keys()} @@ -185,6 +187,8 @@ def get_online_features( native_entity_values=True, ) + # Check for versioned reads on unsupported stores + self._check_versioned_read_support(grouped_refs) _track_read = False try: from feast.metrics import _config as _metrics_config @@ -229,6 +233,7 @@ def get_online_features( requested_features, table, output_len, + include_feature_view_version_metadata, ) if _track_read: @@ -249,6 +254,19 @@ def get_online_features( ) return OnlineResponse(online_features_response) + def _check_versioned_read_support(self, grouped_refs): + """Raise an error if versioned reads are attempted on unsupported stores.""" + from feast.infra.online_stores.sqlite import SqliteOnlineStore + + if isinstance(self, SqliteOnlineStore): + return + for table, _ in grouped_refs: + version_tag = getattr(table.projection, "version_tag", None) + if version_tag is not None: + raise VersionedOnlineReadNotSupported( + self.__class__.__name__, version_tag + ) + async def get_online_features_async( self, config: RepoConfig, @@ -260,6 +278,7 @@ async def get_online_features_async( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: if isinstance(entity_rows, list): columnar: Dict[str, List[Any]] = {k: [] for k in entity_rows[0].keys()} @@ -291,6 +310,9 @@ async def get_online_features_async( native_entity_values=True, ) + # Check for versioned reads on unsupported stores + self._check_versioned_read_support(grouped_refs) + async def query_table(table, requested_features): # Get the correct set of entity values with the correct join keys. table_entity_values, idxs, output_len = utils._get_unique_entities( @@ -347,6 +369,7 @@ async def query_table(table, requested_features): requested_features, table, output_len, + include_feature_view_version_metadata, ) if _track_read: @@ -472,6 +495,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/online_stores/postgres_online_store/postgres.py b/sdk/python/feast/infra/online_stores/postgres_online_store/postgres.py index e252280285e..f7780726d12 100644 --- a/sdk/python/feast/infra/online_stores/postgres_online_store/postgres.py +++ b/sdk/python/feast/infra/online_stores/postgres_online_store/postgres.py @@ -488,6 +488,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/online_stores/remote.py b/sdk/python/feast/infra/online_stores/remote.py index 5b5b04c362d..ed5821e18ca 100644 --- a/sdk/python/feast/infra/online_stores/remote.py +++ b/sdk/python/feast/infra/online_stores/remote.py @@ -301,6 +301,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/online_stores/sqlite.py b/sdk/python/feast/infra/online_stores/sqlite.py index 1be4141c650..f04995c61bb 100644 --- a/sdk/python/feast/infra/online_stores/sqlite.py +++ b/sdk/python/feast/infra/online_stores/sqlite.py @@ -174,7 +174,11 @@ def online_write_batch( if created_ts is not None: created_ts = to_naive_utc(created_ts) - table_name = _table_id(project, table) + table_name = _table_id( + project, + table, + config.registry.enable_online_feature_view_versioning, + ) for feature_name, val in values.items(): if config.online_store.vector_enabled: if ( @@ -254,7 +258,7 @@ def online_read( # Fetch all entities in one go cur.execute( f"SELECT entity_key, feature_name, value, event_ts " - f"FROM {_table_id(config.project, table)} " + f"FROM {_table_id(config.project, table, config.registry.enable_online_feature_view_versioning)} " f"WHERE entity_key IN ({','.join('?' * len(entity_keys))}) " f"ORDER BY entity_key", serialized_entity_keys, @@ -294,16 +298,19 @@ def update( conn = self._get_conn(config) project = config.project + versioning = config.registry.enable_online_feature_view_versioning for table in tables_to_keep: conn.execute( - f"CREATE TABLE IF NOT EXISTS {_table_id(project, table)} (entity_key BLOB, feature_name TEXT, value BLOB, vector_value BLOB, event_ts timestamp, created_ts timestamp, PRIMARY KEY(entity_key, feature_name))" + f"CREATE TABLE IF NOT EXISTS {_table_id(project, table, versioning)} (entity_key BLOB, feature_name TEXT, value BLOB, vector_value BLOB, event_ts timestamp, created_ts timestamp, PRIMARY KEY(entity_key, feature_name))" ) conn.execute( - f"CREATE INDEX IF NOT EXISTS {_table_id(project, table)}_ek ON {_table_id(project, table)} (entity_key);" + f"CREATE INDEX IF NOT EXISTS {_table_id(project, table, versioning)}_ek ON {_table_id(project, table, versioning)} (entity_key);" ) for table in tables_to_delete: - conn.execute(f"DROP TABLE IF EXISTS {_table_id(project, table)}") + conn.execute( + f"DROP TABLE IF EXISTS {_table_id(project, table, versioning)}" + ) def plan( self, config: RepoConfig, desired_registry_proto: RegistryProto @@ -313,7 +320,11 @@ def plan( infra_objects: List[InfraObject] = [ SqliteTable( path=self._get_db_path(config), - name=_table_id(project, FeatureView.from_proto(view)), + name=_table_id( + project, + FeatureView.from_proto(view), + config.registry.enable_online_feature_view_versioning, + ), ) for view in [ *desired_registry_proto.feature_views, @@ -375,7 +386,9 @@ def retrieve_online_documents( # Convert the embedding to a binary format instead of using SerializeToString() query_embedding_bin = serialize_f32(embedding, vector_field_length) - table_name = _table_id(project, table) + table_name = _table_id( + project, table, config.registry.enable_online_feature_view_versioning + ) vector_field = _get_vector_field(table) cur.execute( @@ -464,6 +477,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], @@ -499,7 +513,9 @@ def retrieve_online_documents_v2( _get_feature_view_vector_field_metadata(table), "vector_length", 512 ) - table_name = _table_id(config.project, table) + table_name = _table_id( + config.project, table, config.registry.enable_online_feature_view_versioning + ) vector_field = _get_vector_field(table) if online_store.vector_enabled: @@ -699,8 +715,17 @@ def _initialize_conn( return db -def _table_id(project: str, table: FeatureView) -> str: - return f"{project}_{table.name}" +def _table_id(project: str, table: FeatureView, enable_versioning: bool = False) -> str: + name = table.name + if enable_versioning: + # Prefer version_tag from the projection (set by version-qualified refs like @v2) + # over current_version_number (the FV's active version in metadata). + version = getattr(table.projection, "version_tag", None) + if version is None: + version = getattr(table, "current_version_number", None) + if version is not None and version > 0: + name = f"{table.name}_v{version}" + return f"{project}_{name}" class SqliteTable(InfraObject): diff --git a/sdk/python/feast/infra/passthrough_provider.py b/sdk/python/feast/infra/passthrough_provider.py index 6830929e776..20334e53a2e 100644 --- a/sdk/python/feast/infra/passthrough_provider.py +++ b/sdk/python/feast/infra/passthrough_provider.py @@ -247,6 +247,7 @@ def get_online_features( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: return self.online_store.get_online_features( config=config, @@ -255,6 +256,7 @@ def get_online_features( registry=registry, project=project, full_feature_names=full_feature_names, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) async def get_online_features_async( @@ -268,6 +270,7 @@ async def get_online_features_async( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: return await self.online_store.get_online_features_async( config=config, @@ -276,6 +279,7 @@ async def get_online_features_async( registry=registry, project=project, full_feature_names=full_feature_names, + include_feature_view_version_metadata=include_feature_view_version_metadata, ) async def online_read_async( @@ -322,6 +326,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List: result = [] if self.online_store: @@ -333,6 +338,7 @@ def retrieve_online_documents_v2( top_k, distance_metric, query_string, + include_feature_view_version_metadata, ) return result @@ -488,8 +494,12 @@ def get_historical_features( def retrieve_saved_dataset( self, config: RepoConfig, dataset: SavedDataset ) -> RetrievalJob: + from feast.utils import _strip_version_from_ref + feature_name_columns = [ - ref.replace(":", "__") if dataset.full_feature_names else ref.split(":")[1] + _strip_version_from_ref(ref).replace(":", "__") + if dataset.full_feature_names + else ref.split(":")[1] for ref in dataset.features ] diff --git a/sdk/python/feast/infra/provider.py b/sdk/python/feast/infra/provider.py index c2879c1e2db..9bdf681fb69 100644 --- a/sdk/python/feast/infra/provider.py +++ b/sdk/python/feast/infra/provider.py @@ -316,6 +316,7 @@ def get_online_features( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: pass @@ -331,6 +332,7 @@ async def get_online_features_async( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: pass @@ -468,6 +470,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], diff --git a/sdk/python/feast/infra/registry/base_registry.py b/sdk/python/feast/infra/registry/base_registry.py index c4bf1f5979c..da4f291bc44 100644 --- a/sdk/python/feast/infra/registry/base_registry.py +++ b/sdk/python/feast/infra/registry/base_registry.py @@ -255,7 +255,11 @@ def list_feature_services( # Feature view operations @abstractmethod def apply_feature_view( - self, feature_view: BaseFeatureView, project: str, commit: bool = True + self, + feature_view: BaseFeatureView, + project: str, + commit: bool = True, + no_promote: bool = False, ): """ Registers a single feature view with Feast @@ -264,6 +268,9 @@ def apply_feature_view( feature_view: Feature view that will be registered project: Feast project that this feature view belongs to commit: Whether the change should be persisted immediately + no_promote: If True, save a new version snapshot without promoting + it to the active definition. The new version is accessible only + via explicit @v reads. """ raise NotImplementedError @@ -491,6 +498,46 @@ def list_all_feature_views( """ raise NotImplementedError + def list_feature_view_versions( + self, name: str, project: str + ) -> List[Dict[str, Any]]: + """ + List version history for a feature view. + + Args: + name: Name of feature view + project: Feast project that this feature view belongs to + + Returns: + List of version records with version, version_number, feature_view_type, + created_timestamp, and version_id. + """ + raise NotImplementedError( + "list_feature_view_versions is not implemented for this registry" + ) + + def get_feature_view_by_version( + self, name: str, project: str, version_number: int, allow_cache: bool = False + ) -> BaseFeatureView: + """ + Retrieve a feature view snapshot for a specific version number. + + Args: + name: Name of feature view + project: Feast project that this feature view belongs to + version_number: The version number to retrieve + allow_cache: Whether to allow returning from a cached registry + + Returns: + The feature view snapshot at the specified version. + + Raises: + FeatureViewVersionNotFound: if the version doesn't exist. + """ + raise NotImplementedError( + "get_feature_view_by_version is not implemented for this registry" + ) + @abstractmethod def apply_materialization( self, diff --git a/sdk/python/feast/infra/registry/caching_registry.py b/sdk/python/feast/infra/registry/caching_registry.py index ce346272af9..ad6714d9796 100644 --- a/sdk/python/feast/infra/registry/caching_registry.py +++ b/sdk/python/feast/infra/registry/caching_registry.py @@ -5,7 +5,7 @@ from abc import abstractmethod from datetime import timedelta from threading import Lock -from typing import List, Optional +from typing import Any, Dict, List, Optional from feast.base_feature_view import BaseFeatureView from feast.data_source import DataSource @@ -424,6 +424,13 @@ def list_projects( return proto_registry_utils.list_projects(self.cached_registry_proto, tags) return self._list_projects(tags) + def list_feature_view_versions( + self, name: str, project: str + ) -> List[Dict[str, Any]]: + raise NotImplementedError( + "list_feature_view_versions is not implemented for this registry" + ) + def refresh(self, project: Optional[str] = None): try: self.cached_registry_proto = self.proto() diff --git a/sdk/python/feast/infra/registry/proto_registry_utils.py b/sdk/python/feast/infra/registry/proto_registry_utils.py index 26a5b7e1689..82b7f3e8aaa 100644 --- a/sdk/python/feast/infra/registry/proto_registry_utils.py +++ b/sdk/python/feast/infra/registry/proto_registry_utils.py @@ -10,6 +10,7 @@ EntityNotFoundException, FeatureServiceNotFoundException, FeatureViewNotFoundException, + FeatureViewVersionNotFound, PermissionObjectNotFoundException, ProjectObjectNotFoundException, SavedDatasetNotFound, @@ -147,6 +148,49 @@ def get_any_feature_view( raise FeatureViewNotFoundException(name, project) +def get_feature_view_by_version( + registry_proto: RegistryProto, name: str, project: str, version_number: int +) -> BaseFeatureView: + """Retrieve a feature view snapshot for a specific version from version history.""" + from feast.protos.feast.core.FeatureView_pb2 import ( + FeatureView as FeatureViewProto, + ) + from feast.protos.feast.core.OnDemandFeatureView_pb2 import ( + OnDemandFeatureView as OnDemandFeatureViewProto, + ) + from feast.protos.feast.core.StreamFeatureView_pb2 import ( + StreamFeatureView as StreamFeatureViewProto, + ) + from feast.version_utils import version_tag + + for record in registry_proto.feature_view_version_history.records: + if ( + record.feature_view_name == name + and record.project_id == project + and record.version_number == version_number + ): + if record.feature_view_type == "feature_view": + fv_proto = FeatureViewProto.FromString(record.feature_view_proto) + fv = FeatureView.from_proto(fv_proto) + elif record.feature_view_type == "stream_feature_view": + sfv_proto = StreamFeatureViewProto.FromString(record.feature_view_proto) + fv = StreamFeatureView.from_proto(sfv_proto) + elif record.feature_view_type == "on_demand_feature_view": + odfv_proto = OnDemandFeatureViewProto.FromString( + record.feature_view_proto + ) + fv = OnDemandFeatureView.from_proto(odfv_proto) + else: + raise ValueError( + f"Unknown feature view type: {record.feature_view_type}" + ) + + fv.current_version_number = version_number + return fv + + raise FeatureViewVersionNotFound(name, version_tag(version_number), project) + + def get_feature_view( registry_proto: RegistryProto, name: str, project: str ) -> FeatureView: diff --git a/sdk/python/feast/infra/registry/registry.py b/sdk/python/feast/infra/registry/registry.py index ff9c1f405a1..76da6ad831d 100644 --- a/sdk/python/feast/infra/registry/registry.py +++ b/sdk/python/feast/infra/registry/registry.py @@ -31,6 +31,8 @@ EntityNotFoundException, FeatureServiceNotFoundException, FeatureViewNotFoundException, + FeatureViewPinConflict, + FeatureViewVersionNotFound, PermissionNotFoundException, ProjectNotFoundException, ProjectObjectNotFoundException, @@ -48,12 +50,18 @@ from feast.permissions.permission import Permission from feast.project import Project from feast.project_metadata import ProjectMetadata +from feast.protos.feast.core.FeatureViewVersion_pb2 import FeatureViewVersionRecord from feast.protos.feast.core.Registry_pb2 import Registry as RegistryProto from feast.repo_config import RegistryConfig from feast.repo_contents import RepoContents from feast.saved_dataset import SavedDataset, ValidationReference from feast.stream_feature_view import StreamFeatureView from feast.utils import _utc_now +from feast.version_utils import ( + generate_version_id, + parse_version, + version_tag, +) REGISTRY_SCHEMA_VERSION = "1" @@ -221,6 +229,12 @@ def __init__( else False ) + self.enable_online_versioning = ( + registry_config.enable_online_feature_view_versioning + if registry_config is not None + else False + ) + self.cache_mode = ( registry_config.cache_mode if registry_config is not None else "sync" ) @@ -470,8 +484,197 @@ def get_entity(self, name: str, project: str, allow_cache: bool = False) -> Enti ) return proto_registry_utils.get_entity(registry_proto, name, project) + def _infer_fv_type_string(self, feature_view) -> str: + if isinstance(feature_view, StreamFeatureView): + return "stream_feature_view" + elif isinstance(feature_view, FeatureView): + return "feature_view" + elif isinstance(feature_view, OnDemandFeatureView): + return "on_demand_feature_view" + else: + raise ValueError(f"Unexpected feature view type: {type(feature_view)}") + + def _proto_class_for_type(self, fv_type: str): + from feast.protos.feast.core.FeatureView_pb2 import ( + FeatureView as FeatureViewProto, + ) + from feast.protos.feast.core.OnDemandFeatureView_pb2 import ( + OnDemandFeatureView as OnDemandFeatureViewProto, + ) + from feast.protos.feast.core.StreamFeatureView_pb2 import ( + StreamFeatureView as StreamFeatureViewProto, + ) + + if fv_type == "stream_feature_view": + return StreamFeatureViewProto, StreamFeatureView + elif fv_type == "feature_view": + return FeatureViewProto, FeatureView + elif fv_type == "on_demand_feature_view": + return OnDemandFeatureViewProto, OnDemandFeatureView + else: + raise ValueError(f"Unknown feature view type: {fv_type}") + + def _next_version_number(self, name: str, project: str) -> int: + history = self.cached_registry_proto.feature_view_version_history + max_ver = -1 + for record in history.records: + if record.feature_view_name == name and record.project_id == project: + if record.version_number > max_ver: + max_ver = record.version_number + return max_ver + 1 + + def _get_version_record( + self, name: str, project: str, version_number: int + ) -> Optional[FeatureViewVersionRecord]: + history = self.cached_registry_proto.feature_view_version_history + for record in history.records: + if ( + record.feature_view_name == name + and record.project_id == project + and record.version_number == version_number + ): + return record + return None + + def _update_metadata_fields( + self, existing_proto: Any, updated_fv: BaseFeatureView + ) -> None: + """Update non-version-significant fields without creating new version.""" + from feast.feature_view import FeatureView + + # Metadata fields + existing_proto.spec.description = updated_fv.description + existing_proto.spec.tags.clear() + existing_proto.spec.tags.update(updated_fv.tags) + existing_proto.spec.owner = updated_fv.owner + if hasattr(existing_proto.spec, "version") and hasattr(updated_fv, "version"): + existing_proto.spec.version = getattr(updated_fv, "version") + + # Configuration fields (FeatureView) + if ( + hasattr(existing_proto.spec, "ttl") + and hasattr(updated_fv, "ttl") + and updated_fv.ttl + ): + if isinstance(updated_fv, FeatureView): + ttl_duration = updated_fv.get_ttl_duration() + if ttl_duration: + existing_proto.spec.ttl.CopyFrom(ttl_duration) + if hasattr(existing_proto.spec, "online") and hasattr(updated_fv, "online"): + existing_proto.spec.online = getattr(updated_fv, "online") + if hasattr(existing_proto.spec, "offline") and hasattr(updated_fv, "offline"): + existing_proto.spec.offline = getattr(updated_fv, "offline") + if hasattr(existing_proto.spec, "enable_validation") and hasattr( + updated_fv, "enable_validation" + ): + existing_proto.spec.enable_validation = getattr( + updated_fv, "enable_validation" + ) + + # OnDemandFeatureView configuration + if hasattr(existing_proto.spec, "write_to_online_store") and hasattr( + updated_fv, "write_to_online_store" + ): + existing_proto.spec.write_to_online_store = getattr( + updated_fv, "write_to_online_store" + ) + if hasattr(existing_proto.spec, "singleton") and hasattr( + updated_fv, "singleton" + ): + existing_proto.spec.singleton = getattr(updated_fv, "singleton") + + # Data sources (treat as configuration) + if ( + hasattr(existing_proto.spec, "batch_source") + and hasattr(updated_fv, "batch_source") + and updated_fv.batch_source + ): + existing_proto.spec.batch_source.CopyFrom( + updated_fv.batch_source.to_proto() + ) + if ( + hasattr(existing_proto.spec, "stream_source") + and hasattr(updated_fv, "stream_source") + and updated_fv.stream_source + ): + existing_proto.spec.stream_source.CopyFrom( + updated_fv.stream_source.to_proto() + ) + + # Update or clear version pin + if hasattr(existing_proto.meta, "current_version_number") and hasattr( + updated_fv, "current_version_number" + ): + if updated_fv.current_version_number is not None: + existing_proto.meta.current_version_number = ( + updated_fv.current_version_number + ) + else: + # Unpin: reset to proto default (0). + # from_proto interprets cvn=0 with spec.version="latest" as None. + existing_proto.meta.current_version_number = 0 + + # Update timestamp + existing_proto.meta.last_updated_timestamp.FromDatetime(_utc_now()) + + def _save_version_record( + self, + name: str, + project: str, + version_number: int, + fv_type: str, + proto_bytes: bytes, + ): + now = _utc_now() + record = FeatureViewVersionRecord( + feature_view_name=name, + project_id=project, + version_number=version_number, + feature_view_type=fv_type, + feature_view_proto=proto_bytes, + description="", + version_id=generate_version_id(), + ) + record.created_timestamp.FromDatetime(now) + self.cached_registry_proto.feature_view_version_history.records.append(record) + + def list_feature_view_versions( + self, name: str, project: str + ) -> List[Dict[str, Any]]: + history = self.cached_registry_proto.feature_view_version_history + results = [] + for record in history.records: + if record.feature_view_name == name and record.project_id == project: + results.append( + { + "version": version_tag(record.version_number), + "version_number": record.version_number, + "feature_view_type": record.feature_view_type, + "created_timestamp": record.created_timestamp.ToDatetime(), + "version_id": record.version_id, + } + ) + results.sort(key=lambda r: r["version_number"]) + return results + + def get_feature_view_by_version( + self, name: str, project: str, version_number: int, allow_cache: bool = False + ) -> BaseFeatureView: + record = self._get_version_record(name, project, version_number) + if record is None: + raise FeatureViewVersionNotFound(name, version_tag(version_number), project) + proto_class, python_class = self._proto_class_for_type(record.feature_view_type) + snap_proto = proto_class.FromString(record.feature_view_proto) + fv = python_class.from_proto(snap_proto) + fv.current_version_number = version_number + return fv + def apply_feature_view( - self, feature_view: BaseFeatureView, project: str, commit: bool = True + self, + feature_view: BaseFeatureView, + project: str, + commit: bool = True, + no_promote: bool = False, ): feature_view.ensure_valid() @@ -480,6 +683,73 @@ def apply_feature_view( feature_view.created_timestamp = now feature_view.last_updated_timestamp = now + fv_type_str = self._infer_fv_type_string(feature_view) + is_latest, pin_version = parse_version(feature_view.version) + + if not is_latest: + # Explicit version: check if it exists (pin/revert) or not (forward declaration). + # Note: The file registry is last-write-wins for true concurrent races — + # this is a pre-existing limitation for all file registry operations. + # For multi-client environments, use the SQL registry. + record = self._get_version_record(feature_view.name, project, pin_version) + + if record is not None: + # Version exists → pin/revert to that snapshot + # Check that the user hasn't also modified the definition. + # Compare user's FV (with version="latest") against active FV. + self._prepare_registry_for_changes(project) + try: + active_fv = proto_registry_utils.get_any_feature_view( + self.cached_registry_proto, feature_view.name, project + ) + user_fv_copy = feature_view.__copy__() + user_fv_copy.version = "latest" + active_fv.version = "latest" + # Clear metadata that differs due to registry state + user_fv_copy.created_timestamp = active_fv.created_timestamp + user_fv_copy.last_updated_timestamp = ( + active_fv.last_updated_timestamp + ) + user_fv_copy.current_version_number = ( + active_fv.current_version_number + ) + if hasattr(active_fv, "materialization_intervals"): + user_fv_copy.materialization_intervals = ( + active_fv.materialization_intervals + ) + if user_fv_copy != active_fv: + raise FeatureViewPinConflict( + feature_view.name, version_tag(pin_version) + ) + except FeatureViewNotFoundException: + pass + + proto_class, python_class = self._proto_class_for_type( + record.feature_view_type + ) + snap_proto = proto_class.FromString(record.feature_view_proto) + restored_fv = python_class.from_proto(snap_proto) + restored_fv.version = feature_view.version + restored_fv.current_version_number = pin_version + restored_fv.last_updated_timestamp = now + # Apply the restored FV using the standard path below + feature_view = restored_fv + else: + # Version doesn't exist → forward declaration: create it + feature_view.current_version_number = pin_version + feature_view_proto = feature_view.to_proto() + feature_view_proto.spec.project = project + snapshot_proto_bytes = feature_view_proto.SerializeToString() + self._prepare_registry_for_changes(project) + self._save_version_record( + feature_view.name, + project, + pin_version, + fv_type_str, + snapshot_proto_bytes, + ) + # Fall through to apply the FV as active (with current_version_number set) + feature_view_proto = feature_view.to_proto() feature_view_proto.spec.project = project self._prepare_registry_for_changes(project) @@ -502,6 +772,7 @@ def apply_feature_view( else: raise ValueError(f"Unexpected feature view type: {type(feature_view)}") + old_proto_bytes = None for idx, existing_feature_view_proto in enumerate( existing_feature_views_of_same_type ): @@ -509,12 +780,22 @@ def apply_feature_view( existing_feature_view_proto.spec.name == feature_view_proto.spec.name and existing_feature_view_proto.spec.project == project ): - if ( - feature_view.__class__.from_proto(existing_feature_view_proto) - == feature_view - ): + existing_feature_view = feature_view.__class__.from_proto( + existing_feature_view_proto + ) + if not feature_view._schema_or_udf_changed(existing_feature_view): + # Update non-version-significant fields in place + self._update_metadata_fields( + existing_feature_view_proto, feature_view + ) + if commit: + self.commit() return else: + old_proto_bytes = existing_feature_view_proto.SerializeToString() + # Save a copy before deletion for no_promote restore + existing_proto_copy = type(existing_feature_view_proto)() + existing_proto_copy.CopyFrom(existing_feature_view_proto) existing_feature_view = type(feature_view).from_proto( existing_feature_view_proto ) @@ -530,6 +811,54 @@ def apply_feature_view( del existing_feature_views_of_same_type[idx] break + # Version history tracking + if is_latest: + if old_proto_bytes is not None: + # FV changed: save old as a version if first time, then save new + next_ver = self._next_version_number(feature_view.name, project) + if next_ver == 0: + self._save_version_record( + feature_view.name, project, 0, fv_type_str, old_proto_bytes + ) + next_ver = 1 + + if no_promote: + # Save version snapshot but keep the old active definition + no_promote_fv = feature_view.__copy__() + no_promote_fv.current_version_number = next_ver + no_promote_proto = no_promote_fv.to_proto() + no_promote_proto.spec.project = project + no_promote_proto_bytes = no_promote_proto.SerializeToString() + self._save_version_record( + feature_view.name, + project, + next_ver, + fv_type_str, + no_promote_proto_bytes, + ) + # Re-insert the old active definition (was deleted above) + existing_feature_views_of_same_type.append(existing_proto_copy) + if commit: + self.commit() + return + + feature_view.current_version_number = next_ver + feature_view_proto = feature_view.to_proto() + feature_view_proto.spec.project = project + new_proto_bytes = feature_view_proto.SerializeToString() + self._save_version_record( + feature_view.name, project, next_ver, fv_type_str, new_proto_bytes + ) + else: + # New FV: save as v0 + feature_view.current_version_number = 0 + feature_view_proto = feature_view.to_proto() + feature_view_proto.spec.project = project + new_proto_bytes = feature_view_proto.SerializeToString() + self._save_version_record( + feature_view.name, project, 0, fv_type_str, new_proto_bytes + ) + existing_feature_views_of_same_type.append(feature_view_proto) if commit: self.commit() @@ -706,6 +1035,7 @@ def delete_feature_view(self, name: str, project: str, commit: bool = True): self._prepare_registry_for_changes(project) assert self.cached_registry_proto + found = False for idx, existing_feature_view_proto in enumerate( self.cached_registry_proto.feature_views ): @@ -714,35 +1044,48 @@ def delete_feature_view(self, name: str, project: str, commit: bool = True): and existing_feature_view_proto.spec.project == project ): del self.cached_registry_proto.feature_views[idx] - if commit: - self.commit() - return + found = True + break - for idx, existing_on_demand_feature_view_proto in enumerate( - self.cached_registry_proto.on_demand_feature_views - ): - if ( - existing_on_demand_feature_view_proto.spec.name == name - and existing_on_demand_feature_view_proto.spec.project == project + if not found: + for idx, existing_on_demand_feature_view_proto in enumerate( + self.cached_registry_proto.on_demand_feature_views ): - del self.cached_registry_proto.on_demand_feature_views[idx] - if commit: - self.commit() - return + if ( + existing_on_demand_feature_view_proto.spec.name == name + and existing_on_demand_feature_view_proto.spec.project == project + ): + del self.cached_registry_proto.on_demand_feature_views[idx] + found = True + break - for idx, existing_stream_feature_view_proto in enumerate( - self.cached_registry_proto.stream_feature_views - ): - if ( - existing_stream_feature_view_proto.spec.name == name - and existing_stream_feature_view_proto.spec.project == project + if not found: + for idx, existing_stream_feature_view_proto in enumerate( + self.cached_registry_proto.stream_feature_views ): - del self.cached_registry_proto.stream_feature_views[idx] - if commit: - self.commit() - return + if ( + existing_stream_feature_view_proto.spec.name == name + and existing_stream_feature_view_proto.spec.project == project + ): + del self.cached_registry_proto.stream_feature_views[idx] + found = True + break + + if not found: + raise FeatureViewNotFoundException(name, project) - raise FeatureViewNotFoundException(name, project) + # Clean up version history for the deleted feature view + history = self.cached_registry_proto.feature_view_version_history + indices_to_remove = [ + i + for i, record in enumerate(history.records) + if record.feature_view_name == name and record.project_id == project + ] + for i in reversed(indices_to_remove): + del history.records[i] + + if commit: + self.commit() def delete_entity(self, name: str, project: str, commit: bool = True): self._prepare_registry_for_changes(project) diff --git a/sdk/python/feast/infra/registry/remote.py b/sdk/python/feast/infra/registry/remote.py index 8fc0db55c27..c553a55f754 100644 --- a/sdk/python/feast/infra/registry/remote.py +++ b/sdk/python/feast/infra/registry/remote.py @@ -217,7 +217,11 @@ def list_feature_services( ] def apply_feature_view( - self, feature_view: BaseFeatureView, project: str, commit: bool = True + self, + feature_view: BaseFeatureView, + project: str, + commit: bool = True, + no_promote: bool = False, ): if isinstance(feature_view, StreamFeatureView): arg_name = "stream_feature_view" diff --git a/sdk/python/feast/infra/registry/snowflake.py b/sdk/python/feast/infra/registry/snowflake.py index 12299572f04..68bf376e650 100644 --- a/sdk/python/feast/infra/registry/snowflake.py +++ b/sdk/python/feast/infra/registry/snowflake.py @@ -259,8 +259,18 @@ def apply_feature_service( ) def apply_feature_view( - self, feature_view: BaseFeatureView, project: str, commit: bool = True + self, + feature_view: BaseFeatureView, + project: str, + commit: bool = True, + no_promote: bool = False, ): + if no_promote: + raise NotImplementedError( + "Feature view versioning (no_promote) is not supported by the Snowflake registry. " + "Use the SQL registry or file registry for versioning support." + ) + feature_view.ensure_valid() fv_table_str = self._infer_fv_table(feature_view) fv_column_name = fv_table_str[:-1] return self._apply_object( diff --git a/sdk/python/feast/infra/registry/sql.py b/sdk/python/feast/infra/registry/sql.py index e76291cdb01..ae09c8e52b6 100644 --- a/sdk/python/feast/infra/registry/sql.py +++ b/sdk/python/feast/infra/registry/sql.py @@ -11,6 +11,7 @@ BigInteger, Column, Index, + Integer, LargeBinary, MetaData, String, @@ -18,6 +19,7 @@ Text, create_engine, delete, + func, insert, select, update, @@ -30,10 +32,13 @@ from feast.data_source import DataSource from feast.entity import Entity from feast.errors import ( + ConcurrentVersionConflict, DataSourceObjectNotFoundException, EntityNotFoundException, FeatureServiceNotFoundException, FeatureViewNotFoundException, + FeatureViewPinConflict, + FeatureViewVersionNotFound, PermissionNotFoundException, ProjectNotFoundException, ProjectObjectNotFoundException, @@ -72,6 +77,11 @@ from feast.saved_dataset import SavedDataset, ValidationReference from feast.stream_feature_view import StreamFeatureView from feast.utils import _utc_now +from feast.version_utils import ( + generate_version_id, + parse_version, + version_tag, +) metadata = MetaData() @@ -200,6 +210,24 @@ Index("idx_permissions_project_id", permissions.c.project_id) +feature_view_version_history = Table( + "feature_view_version_history", + metadata, + Column("feature_view_name", String(255), primary_key=True), + Column("project_id", String(255), primary_key=True), + Column("version_number", Integer, primary_key=True), + Column("feature_view_type", String(50), nullable=False), + Column("feature_view_proto", LargeBinary, nullable=False), + Column("created_timestamp", BigInteger, nullable=False), + Column("description", Text, nullable=True), + Column("version_id", String(36), nullable=False), +) + +Index( + "idx_fv_version_history_project_id", + feature_view_version_history.c.project_id, +) + class FeastMetadataKeys(Enum): LAST_UPDATED_TIMESTAMP = "last_updated_timestamp" @@ -267,6 +295,9 @@ def __init__( registry_config.thread_pool_executor_worker_count ) self.purge_feast_metadata = registry_config.purge_feast_metadata + self.enable_online_versioning = ( + registry_config.enable_online_feature_view_versioning + ) super().__init__( project=project, cache_ttl_seconds=registry_config.cache_ttl_seconds, @@ -337,6 +368,7 @@ def teardown(self): saved_datasets, validation_references, permissions, + feature_view_version_history, }: with self.write_engine.begin() as conn: stmt = delete(t) @@ -529,17 +561,36 @@ def delete_entity(self, name: str, project: str, commit: bool = True): ) def delete_feature_view(self, name: str, project: str, commit: bool = True): - deleted_count = 0 - for table in { - feature_views, - on_demand_feature_views, - stream_feature_views, - }: - deleted_count += self._delete_object( - table, name, project, "feature_view_name", None + with self.write_engine.begin() as conn: + deleted_count = 0 + for table in { + feature_views, + on_demand_feature_views, + stream_feature_views, + }: + stmt = delete(table).where( + table.c.feature_view_name == name, + table.c.project_id == project, + ) + rows = conn.execute(stmt) + deleted_count += rows.rowcount + if deleted_count == 0: + raise FeatureViewNotFoundException(name, project) + # Clean up version history in the same transaction + stmt = delete(feature_view_version_history).where( + feature_view_version_history.c.feature_view_name == name, + feature_view_version_history.c.project_id == project, ) - if deleted_count == 0: - raise FeatureViewNotFoundException(name, project) + conn.execute(stmt) + + self.apply_project( + self.get_project(name=project, allow_cache=False), commit=True + ) + if not self.purge_feast_metadata: + with self.write_engine.begin() as conn: + self._set_last_updated_metadata(_utc_now(), project, conn) + if self.cache_mode == "sync": + self.refresh() def delete_feature_service(self, name: str, project: str, commit: bool = True): return self._delete_object( @@ -582,15 +633,229 @@ def apply_data_source( ) def apply_feature_view( - self, feature_view: BaseFeatureView, project: str, commit: bool = True + self, + feature_view: BaseFeatureView, + project: str, + commit: bool = True, + no_promote: bool = False, ): + feature_view.ensure_valid() self._ensure_feature_view_name_is_unique(feature_view, project) fv_table = self._infer_fv_table(feature_view) + fv_type_str = self._infer_fv_type_string(feature_view) - return self._apply_object( + is_latest, pin_version = parse_version(feature_view.version) + + if not is_latest: + # Explicit version: check if it exists (pin/revert) or not (forward declaration) + snapshot = self._get_version_snapshot( + feature_view.name, project, pin_version + ) + + if snapshot is not None: + # Version exists → pin/revert to that snapshot + # Check that the user hasn't also modified the definition. + # Compare user's FV (with version="latest") against active FV. + try: + active_fv = self._get_any_feature_view(feature_view.name, project) + user_fv_copy = feature_view.__copy__() + user_fv_copy.version = "latest" + active_fv.version = "latest" + # Clear metadata that differs due to registry state + user_fv_copy.created_timestamp = active_fv.created_timestamp + user_fv_copy.last_updated_timestamp = ( + active_fv.last_updated_timestamp + ) + user_fv_copy.current_version_number = ( + active_fv.current_version_number + ) + if hasattr(active_fv, "materialization_intervals"): + user_fv_copy.materialization_intervals = ( + active_fv.materialization_intervals + ) + if user_fv_copy != active_fv: + raise FeatureViewPinConflict( + feature_view.name, version_tag(pin_version) + ) + except FeatureViewNotFoundException: + pass + + snap_type, snap_proto_bytes = snapshot + proto_class, python_class = self._proto_class_for_type(snap_type) + snap_proto = proto_class.FromString(snap_proto_bytes) + restored_fv = python_class.from_proto(snap_proto) + restored_fv.version = feature_view.version + restored_fv.current_version_number = pin_version + return self._apply_object( + fv_table, + project, + "feature_view_name", + restored_fv, + "feature_view_proto", + ) + else: + # Version doesn't exist → forward declaration: create it + feature_view.current_version_number = pin_version + snapshot_proto = feature_view.to_proto() + snapshot_proto.spec.project = project + snapshot_proto_bytes = snapshot_proto.SerializeToString() + try: + self._save_version_snapshot( + feature_view.name, + project, + pin_version, + fv_type_str, + snapshot_proto_bytes, + ) + except IntegrityError: + raise ConcurrentVersionConflict( + f"Version v{pin_version} of '{feature_view.name}' was just created by " + f"another concurrent apply. Pull latest and retry." + ) + # Apply the FV as active + return self._apply_object( + fv_table, + project, + "feature_view_name", + feature_view, + "feature_view_proto", + ) + + # Normal (latest) apply: snapshot old version if changed, then save new + # First check if the FV already exists so we can snapshot the old one. + # Use write_engine for both reads to avoid read replica lag issues. + old_proto_bytes = None + with self.write_engine.begin() as conn: + stmt = select(fv_table).where( + fv_table.c.feature_view_name == feature_view.name, + fv_table.c.project_id == project, + ) + row = conn.execute(stmt).first() + if row: + old_proto_bytes = row._mapping["feature_view_proto"] + + # Apply the object (handles idempotency check internally) + # We need to detect if _apply_object actually made a change + # by checking before/after + self._apply_object( fv_table, project, "feature_view_name", feature_view, "feature_view_proto" ) + # After apply, read the current proto to see if it changed + with self.write_engine.begin() as conn: + stmt = select(fv_table).where( + fv_table.c.feature_view_name == feature_view.name, + fv_table.c.project_id == project, + ) + row = conn.execute(stmt).first() + if row: + new_proto_bytes = row._mapping["feature_view_proto"] + else: + return # shouldn't happen + + if old_proto_bytes is not None: + # Deserialize both versions to compare schema/UDF changes + proto_class, fv_class = self._proto_class_for_type(fv_type_str) + old_proto = proto_class.FromString(old_proto_bytes) + new_proto = proto_class.FromString(new_proto_bytes) + + old_fv = fv_class.from_proto(old_proto) + new_fv = fv_class.from_proto(new_proto) + + if not new_fv._schema_or_udf_changed(old_fv): + # No version-significant change, skip version creation + return + + # Something changed (or new FV). Save version snapshot(s). + if old_proto_bytes is not None: + # Snapshot the old version first (if not already in history) + next_ver = self._get_next_version_number(feature_view.name, project) + if next_ver == 0: + # First time versioning: save old as v0 + self._save_version_snapshot( + feature_view.name, + project, + 0, + fv_type_str, + old_proto_bytes, + ) + next_ver = 1 + + # Retry loop: if a concurrent apply claimed the same version number, + # re-read MAX+1 and try again. The client said "latest" so the + # exact number doesn't matter. + max_retries = 3 + for attempt in range(max_retries): + # Update current_version_number before saving snapshot + feature_view.current_version_number = next_ver + snapshot_proto = feature_view.to_proto() + snapshot_proto.spec.project = project + snapshot_proto_bytes = snapshot_proto.SerializeToString() + + try: + # Save new as next version (with correct current_version_number) + self._save_version_snapshot( + feature_view.name, + project, + next_ver, + fv_type_str, + snapshot_proto_bytes, + ) + break + except IntegrityError: + if attempt == max_retries - 1: + raise ConcurrentVersionConflict( + f"Failed to assign version for '{feature_view.name}' after " + f"{max_retries} attempts due to concurrent applies. " + f"Please retry." + ) + # Re-read the next available version number + next_ver = self._get_next_version_number(feature_view.name, project) + + if no_promote: + # Save version snapshot but skip updating the active row. + # The new version is accessible only via explicit @v reads. + return + + # Re-serialize with updated version number + with self.write_engine.begin() as conn: + update_stmt = ( + update(fv_table) + .where( + fv_table.c.feature_view_name == feature_view.name, + fv_table.c.project_id == project, + ) + .values( + feature_view_proto=snapshot_proto_bytes, + ) + ) + conn.execute(update_stmt) + else: + # New FV: save as v0 + feature_view.current_version_number = 0 + snapshot_proto = feature_view.to_proto() + snapshot_proto.spec.project = project + snapshot_proto_bytes = snapshot_proto.SerializeToString() + self._save_version_snapshot( + feature_view.name, + project, + 0, + fv_type_str, + snapshot_proto_bytes, + ) + with self.write_engine.begin() as conn: + update_stmt = ( + update(fv_table) + .where( + fv_table.c.feature_view_name == feature_view.name, + fv_table.c.project_id == project, + ) + .values( + feature_view_proto=snapshot_proto_bytes, + ) + ) + conn.execute(update_stmt) + def apply_feature_service( self, feature_service: FeatureService, project: str, commit: bool = True ): @@ -829,6 +1094,118 @@ def _infer_fv_classes(self, feature_view): raise ValueError(f"Unexpected feature view type: {type(feature_view)}") return python_class, proto_class + def _infer_fv_type_string(self, feature_view) -> str: + if isinstance(feature_view, StreamFeatureView): + return "stream_feature_view" + elif isinstance(feature_view, FeatureView): + return "feature_view" + elif isinstance(feature_view, OnDemandFeatureView): + return "on_demand_feature_view" + else: + raise ValueError(f"Unexpected feature view type: {type(feature_view)}") + + def _proto_class_for_type(self, fv_type: str): + if fv_type == "stream_feature_view": + return StreamFeatureViewProto, StreamFeatureView + elif fv_type == "feature_view": + return FeatureViewProto, FeatureView + elif fv_type == "on_demand_feature_view": + return OnDemandFeatureViewProto, OnDemandFeatureView + else: + raise ValueError(f"Unknown feature view type: {fv_type}") + + def _get_next_version_number(self, name: str, project: str) -> int: + with self.write_engine.begin() as conn: + stmt = select( + func.coalesce( + func.max(feature_view_version_history.c.version_number) + 1, 0 + ) + ).where( + feature_view_version_history.c.feature_view_name == name, + feature_view_version_history.c.project_id == project, + ) + result = conn.execute(stmt).scalar() + return result or 0 + + def _save_version_snapshot( + self, + name: str, + project: str, + version_number: int, + fv_type: str, + proto_bytes: bytes, + ): + now = int(_utc_now().timestamp()) + vid = generate_version_id() + with self.write_engine.begin() as conn: + stmt = insert(feature_view_version_history).values( + feature_view_name=name, + project_id=project, + version_number=version_number, + feature_view_type=fv_type, + feature_view_proto=proto_bytes, + created_timestamp=now, + description="", + version_id=vid, + ) + conn.execute(stmt) + + def _get_version_snapshot( + self, name: str, project: str, version_number: int + ) -> Optional[tuple]: + with self.read_engine.begin() as conn: + stmt = select(feature_view_version_history).where( + feature_view_version_history.c.feature_view_name == name, + feature_view_version_history.c.project_id == project, + feature_view_version_history.c.version_number == version_number, + ) + row = conn.execute(stmt).first() + if row: + return ( + row._mapping["feature_view_type"], + row._mapping["feature_view_proto"], + ) + return None + + def get_feature_view_by_version( + self, name: str, project: str, version_number: int, allow_cache: bool = False + ) -> BaseFeatureView: + snapshot = self._get_version_snapshot(name, project, version_number) + if snapshot is None: + raise FeatureViewVersionNotFound(name, version_tag(version_number), project) + snap_type, snap_proto_bytes = snapshot + proto_class, python_class = self._proto_class_for_type(snap_type) + snap_proto = proto_class.FromString(snap_proto_bytes) + fv = python_class.from_proto(snap_proto) + fv.current_version_number = version_number + return fv + + def list_feature_view_versions( + self, name: str, project: str + ) -> List[Dict[str, Any]]: + with self.read_engine.begin() as conn: + stmt = ( + select(feature_view_version_history) + .where( + feature_view_version_history.c.feature_view_name == name, + feature_view_version_history.c.project_id == project, + ) + .order_by(feature_view_version_history.c.version_number) + ) + rows = conn.execute(stmt).all() + return [ + { + "version": version_tag(row._mapping["version_number"]), + "version_number": row._mapping["version_number"], + "feature_view_type": row._mapping["feature_view_type"], + "created_timestamp": datetime.fromtimestamp( + row._mapping["created_timestamp"], tz=timezone.utc + ), + "version_id": row._mapping["version_id"], + } + for row in rows + ] + def get_user_metadata( self, project: str, feature_view: BaseFeatureView ) -> Optional[bytes]: diff --git a/sdk/python/feast/on_demand_feature_view.py b/sdk/python/feast/on_demand_feature_view.py index eaf3ca88ed8..4dd971b13e2 100644 --- a/sdk/python/feast/on_demand_feature_view.py +++ b/sdk/python/feast/on_demand_feature_view.py @@ -35,6 +35,7 @@ from feast.transformation.substrait_transformation import SubstraitTransformation from feast.utils import _utc_now from feast.value_type import ValueType +from feast.version_utils import normalize_version_string warnings.simplefilter("once", DeprecationWarning) OnDemandSourceType = Union[FeatureView, FeatureViewProjection, RequestSource] @@ -168,6 +169,7 @@ def __init__( # noqa: C901 singleton: bool = False, track_metrics: bool = False, aggregations: Optional[List[Aggregation]] = None, + version: str = "latest", ): """ Creates an OnDemandFeatureView object. @@ -208,6 +210,7 @@ def __init__( # noqa: C901 owner=owner, ) + self.version = version schema = schema or [] self.entities = [e.name for e in entities] if entities else [DUMMY_ENTITY_NAME] self.sources = sources @@ -328,6 +331,7 @@ def __copy__(self): owner=self.owner, write_to_online_store=self.write_to_online_store, singleton=self.singleton, + version=self.version, track_metrics=self.track_metrics, ) fv.entities = self.entities @@ -337,6 +341,49 @@ def __copy__(self): return fv + def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool: + """Check for OnDemandFeatureView schema/UDF changes.""" + if super()._schema_or_udf_changed(other): + return True + + if not isinstance(other, OnDemandFeatureView): + return True + + # UDF/transformation changes + # Handle None cases for feature_transformation + if ( + self.feature_transformation is None + and other.feature_transformation is not None + ): + return True + if ( + self.feature_transformation is not None + and other.feature_transformation is None + ): + return True + if ( + self.feature_transformation is not None + and other.feature_transformation is not None + and self.feature_transformation != other.feature_transformation + ): + return True + if self.mode != other.mode: + return True + if ( + self.source_feature_view_projections + != other.source_feature_view_projections + ): + return True + if self.source_request_sources != other.source_request_sources: + return True + if sorted(self.entity_columns) != sorted(other.entity_columns): + return True + if self.aggregations != other.aggregations: + return True + + # Skip configuration: write_to_online_store, singleton + return False + def __eq__(self, other): if not isinstance(other, OnDemandFeatureView): raise TypeError( @@ -358,6 +405,8 @@ def __eq__(self, other): or self.singleton != other.singleton or self.track_metrics != other.track_metrics or self.aggregations != other.aggregations + or normalize_version_string(self.version) + != normalize_version_string(other.version) ): return False @@ -468,6 +517,8 @@ def to_proto(self) -> OnDemandFeatureViewProto: meta.created_timestamp.FromDatetime(self.created_timestamp) if self.last_updated_timestamp: meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp) + if self.current_version_number is not None: + meta.current_version_number = self.current_version_number sources = {} for source_name, fv_projection in self.source_feature_view_projections.items(): sources[source_name] = OnDemandSource( @@ -505,6 +556,7 @@ def to_proto(self) -> OnDemandFeatureViewProto: write_to_online_store=self.write_to_online_store, singleton=self.singleton or False, aggregations=self.aggregations, + version=self.version, ) return OnDemandFeatureViewProto(spec=spec, meta=meta) @@ -570,6 +622,17 @@ def from_proto( on_demand_feature_view_obj ) + # Restore version fields. + spec_version = on_demand_feature_view_proto.spec.version + on_demand_feature_view_obj.version = spec_version or "latest" + cvn = on_demand_feature_view_proto.meta.current_version_number + if cvn > 0: + on_demand_feature_view_obj.current_version_number = cvn + elif cvn == 0 and spec_version and spec_version.lower() != "latest": + on_demand_feature_view_obj.current_version_number = 0 + else: + on_demand_feature_view_obj.current_version_number = None + # Set timestamps if present cls._set_timestamps_from_proto( on_demand_feature_view_proto, on_demand_feature_view_obj @@ -1146,6 +1209,7 @@ def on_demand_feature_view( singleton: bool = False, track_metrics: bool = False, explode: bool = False, + version: str = "latest", ): """ Creates an OnDemandFeatureView object with the given user function as udf. @@ -1196,6 +1260,7 @@ def decorator(user_function): track_metrics=track_metrics, udf=user_function, udf_string=udf_string, + version=version, ) functools.update_wrapper( wrapper=on_demand_feature_view_obj, wrapped=user_function diff --git a/sdk/python/feast/protos/feast/core/Aggregation_pb2.py b/sdk/python/feast/protos/feast/core/Aggregation_pb2.py index 48f107b8eff..44013acd55d 100644 --- a/sdk/python/feast/protos/feast/core/Aggregation_pb2.py +++ b/sdk/python/feast/protos/feast/core/Aggregation_pb2.py @@ -15,7 +15,7 @@ from google.protobuf import duration_pb2 as google_dot_protobuf_dot_duration__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1cfeast/core/Aggregation.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\"\xd3\x01\n\x0bAggregation\x12\x16\n\x06column\x18\x01 \x01(\tR\x06column\x12\x1a\n\x08function\x18\x02 \x01(\tR\x08function\x12:\n\x0btime_window\x18\x03 \x01(\x0b2\x19.google.protobuf.DurationR\ntimeWindow\x12@\n\x0eslide_interval\x18\x04 \x01(\x0b2\x19.google.protobuf.DurationR\rslideInterval\x12\x12\n\x04name\x18\x05 \x01(\tR\x04nameBU\n\x10feast.proto.coreB\x10AggregationProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66\x65\x61st/core/Aggregation.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\"\xa0\x01\n\x0b\x41ggregation\x12\x0e\n\x06\x63olumn\x18\x01 \x01(\t\x12\x10\n\x08\x66unction\x18\x02 \x01(\t\x12.\n\x0btime_window\x18\x03 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x31\n\x0eslide_interval\x18\x04 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x0c\n\x04name\x18\x05 \x01(\tBU\n\x10\x66\x65\x61st.proto.coreB\x10\x41ggregationProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -24,5 +24,5 @@ _globals['DESCRIPTOR']._options = None _globals['DESCRIPTOR']._serialized_options = b'\n\020feast.proto.coreB\020AggregationProtoZ/github.com/feast-dev/feast/go/protos/feast/core' _globals['_AGGREGATION']._serialized_start=77 - _globals['_AGGREGATION']._serialized_end=288 + _globals['_AGGREGATION']._serialized_end=237 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/Aggregation_pb2.pyi b/sdk/python/feast/protos/feast/core/Aggregation_pb2.pyi index af9ec2b191f..4c6bd7c089c 100644 --- a/sdk/python/feast/protos/feast/core/Aggregation_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/Aggregation_pb2.pyi @@ -25,11 +25,11 @@ class Aggregation(google.protobuf.message.Message): NAME_FIELD_NUMBER: builtins.int column: builtins.str function: builtins.str - name: builtins.str @property def time_window(self) -> google.protobuf.duration_pb2.Duration: ... @property def slide_interval(self) -> google.protobuf.duration_pb2.Duration: ... + name: builtins.str def __init__( self, *, diff --git a/sdk/python/feast/protos/feast/core/DatastoreTable_pb2.pyi b/sdk/python/feast/protos/feast/core/DatastoreTable_pb2.pyi index 6339a97536e..7b5a629eb7a 100644 --- a/sdk/python/feast/protos/feast/core/DatastoreTable_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/DatastoreTable_pb2.pyi @@ -1,19 +1,19 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file - -* Copyright 2021 The Feast Authors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* https://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and + +* Copyright 2021 The Feast Authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* https://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. """ import builtins diff --git a/sdk/python/feast/protos/feast/core/Entity_pb2.pyi b/sdk/python/feast/protos/feast/core/Entity_pb2.pyi index 025817edfee..a5924a13451 100644 --- a/sdk/python/feast/protos/feast/core/Entity_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/Entity_pb2.pyi @@ -1,19 +1,19 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file - -* Copyright 2020 The Feast Authors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* https://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and + +* Copyright 2020 The Feast Authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* https://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. """ import builtins diff --git a/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.py b/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.py index b47d4fe392f..9a51148f32c 100644 --- a/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.py +++ b/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.py @@ -16,7 +16,7 @@ from feast.protos.feast.core import DataSource_pb2 as feast_dot_core_dot_DataSource__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n&feast/core/FeatureViewProjection.proto\x12\nfeast.core\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\"\xba\x03\n\x15\x46\x65\x61tureViewProjection\x12\x19\n\x11\x66\x65\x61ture_view_name\x18\x01 \x01(\t\x12\x1f\n\x17\x66\x65\x61ture_view_name_alias\x18\x03 \x01(\t\x12\x32\n\x0f\x66\x65\x61ture_columns\x18\x02 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12G\n\x0cjoin_key_map\x18\x04 \x03(\x0b\x32\x31.feast.core.FeatureViewProjection.JoinKeyMapEntry\x12\x17\n\x0ftimestamp_field\x18\x05 \x01(\t\x12\x1d\n\x15\x64\x61te_partition_column\x18\x06 \x01(\t\x12 \n\x18\x63reated_timestamp_column\x18\x07 \x01(\t\x12,\n\x0c\x62\x61tch_source\x18\x08 \x01(\x0b\x32\x16.feast.core.DataSource\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x1a\x31\n\x0fJoinKeyMapEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42Z\n\x10\x66\x65\x61st.proto.coreB\x15\x46\x65\x61tureReferenceProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n&feast/core/FeatureViewProjection.proto\x12\nfeast.core\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\"\xe4\x03\n\x15\x46\x65\x61tureViewProjection\x12\x19\n\x11\x66\x65\x61ture_view_name\x18\x01 \x01(\t\x12\x1f\n\x17\x66\x65\x61ture_view_name_alias\x18\x03 \x01(\t\x12\x32\n\x0f\x66\x65\x61ture_columns\x18\x02 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12G\n\x0cjoin_key_map\x18\x04 \x03(\x0b\x32\x31.feast.core.FeatureViewProjection.JoinKeyMapEntry\x12\x17\n\x0ftimestamp_field\x18\x05 \x01(\t\x12\x1d\n\x15\x64\x61te_partition_column\x18\x06 \x01(\t\x12 \n\x18\x63reated_timestamp_column\x18\x07 \x01(\t\x12,\n\x0c\x62\x61tch_source\x18\x08 \x01(\x0b\x32\x16.feast.core.DataSource\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x12\x18\n\x0bversion_tag\x18\n \x01(\x05H\x00\x88\x01\x01\x1a\x31\n\x0fJoinKeyMapEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42\x0e\n\x0c_version_tagBZ\n\x10\x66\x65\x61st.proto.coreB\x15\x46\x65\x61tureReferenceProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -27,7 +27,7 @@ _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._options = None _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._serialized_options = b'8\001' _globals['_FEATUREVIEWPROJECTION']._serialized_start=110 - _globals['_FEATUREVIEWPROJECTION']._serialized_end=552 - _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._serialized_start=503 - _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._serialized_end=552 + _globals['_FEATUREVIEWPROJECTION']._serialized_end=594 + _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._serialized_start=529 + _globals['_FEATUREVIEWPROJECTION_JOINKEYMAPENTRY']._serialized_end=578 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.pyi b/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.pyi index 6b44ad4a931..6fd1010f2e4 100644 --- a/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/FeatureViewProjection_pb2.pyi @@ -19,7 +19,7 @@ else: DESCRIPTOR: google.protobuf.descriptor.FileDescriptor class FeatureViewProjection(google.protobuf.message.Message): - """A projection to be applied on top of a FeatureView. + """A projection to be applied on top of a FeatureView. Contains the modifications to a FeatureView such as the features subset to use. """ @@ -49,6 +49,7 @@ class FeatureViewProjection(google.protobuf.message.Message): CREATED_TIMESTAMP_COLUMN_FIELD_NUMBER: builtins.int BATCH_SOURCE_FIELD_NUMBER: builtins.int STREAM_SOURCE_FIELD_NUMBER: builtins.int + VERSION_TAG_FIELD_NUMBER: builtins.int feature_view_name: builtins.str """The feature view name""" feature_view_name_alias: builtins.str @@ -68,6 +69,8 @@ class FeatureViewProjection(google.protobuf.message.Message): @property def stream_source(self) -> feast.core.DataSource_pb2.DataSource: """Streaming DataSource from where this view can consume "online" feature data.""" + version_tag: builtins.int + """Optional version tag for version-qualified feature references (e.g., @v2).""" def __init__( self, *, @@ -80,8 +83,10 @@ class FeatureViewProjection(google.protobuf.message.Message): created_timestamp_column: builtins.str = ..., batch_source: feast.core.DataSource_pb2.DataSource | None = ..., stream_source: feast.core.DataSource_pb2.DataSource | None = ..., + version_tag: builtins.int | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "stream_source", b"stream_source"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "created_timestamp_column", b"created_timestamp_column", "date_partition_column", b"date_partition_column", "feature_columns", b"feature_columns", "feature_view_name", b"feature_view_name", "feature_view_name_alias", b"feature_view_name_alias", "join_key_map", b"join_key_map", "stream_source", b"stream_source", "timestamp_field", b"timestamp_field"]) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["_version_tag", b"_version_tag", "batch_source", b"batch_source", "stream_source", b"stream_source", "version_tag", b"version_tag"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["_version_tag", b"_version_tag", "batch_source", b"batch_source", "created_timestamp_column", b"created_timestamp_column", "date_partition_column", b"date_partition_column", "feature_columns", b"feature_columns", "feature_view_name", b"feature_view_name", "feature_view_name_alias", b"feature_view_name_alias", "join_key_map", b"join_key_map", "stream_source", b"stream_source", "timestamp_field", b"timestamp_field", "version_tag", b"version_tag"]) -> None: ... + def WhichOneof(self, oneof_group: typing_extensions.Literal["_version_tag", b"_version_tag"]) -> typing_extensions.Literal["version_tag"] | None: ... global___FeatureViewProjection = FeatureViewProjection diff --git a/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.py b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.py new file mode 100644 index 00000000000..88bc21c2a8f --- /dev/null +++ b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: feast/core/FeatureViewVersion.proto +# Protobuf Python Version: 4.25.1 +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +from google.protobuf.internal import builder as _builder +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n#feast/core/FeatureViewVersion.proto\x12\nfeast.core\x1a\x1fgoogle/protobuf/timestamp.proto\"\xf8\x01\n\x18\x46\x65\x61tureViewVersionRecord\x12\x19\n\x11\x66\x65\x61ture_view_name\x18\x01 \x01(\t\x12\x12\n\nproject_id\x18\x02 \x01(\t\x12\x16\n\x0eversion_number\x18\x03 \x01(\x05\x12\x19\n\x11\x66\x65\x61ture_view_type\x18\x04 \x01(\t\x12\x1a\n\x12\x66\x65\x61ture_view_proto\x18\x05 \x01(\x0c\x12\x35\n\x11\x63reated_timestamp\x18\x06 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x13\n\x0b\x64\x65scription\x18\x07 \x01(\t\x12\x12\n\nversion_id\x18\x08 \x01(\t\"R\n\x19\x46\x65\x61tureViewVersionHistory\x12\x35\n\x07records\x18\x01 \x03(\x0b\x32$.feast.core.FeatureViewVersionRecordB\\\n\x10\x66\x65\x61st.proto.coreB\x17\x46\x65\x61tureViewVersionProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') + +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'feast.core.FeatureViewVersion_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + _globals['DESCRIPTOR']._options = None + _globals['DESCRIPTOR']._serialized_options = b'\n\020feast.proto.coreB\027FeatureViewVersionProtoZ/github.com/feast-dev/feast/go/protos/feast/core' + _globals['_FEATUREVIEWVERSIONRECORD']._serialized_start=85 + _globals['_FEATUREVIEWVERSIONRECORD']._serialized_end=333 + _globals['_FEATUREVIEWVERSIONHISTORY']._serialized_start=335 + _globals['_FEATUREVIEWVERSIONHISTORY']._serialized_end=417 +# @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.pyi b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.pyi new file mode 100644 index 00000000000..a6dba9d53d4 --- /dev/null +++ b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2.pyi @@ -0,0 +1,87 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file + +Copyright 2024 The Feast Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" +import builtins +import collections.abc +import google.protobuf.descriptor +import google.protobuf.internal.containers +import google.protobuf.message +import google.protobuf.timestamp_pb2 +import sys + +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions + +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor + +class FeatureViewVersionRecord(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + FEATURE_VIEW_NAME_FIELD_NUMBER: builtins.int + PROJECT_ID_FIELD_NUMBER: builtins.int + VERSION_NUMBER_FIELD_NUMBER: builtins.int + FEATURE_VIEW_TYPE_FIELD_NUMBER: builtins.int + FEATURE_VIEW_PROTO_FIELD_NUMBER: builtins.int + CREATED_TIMESTAMP_FIELD_NUMBER: builtins.int + DESCRIPTION_FIELD_NUMBER: builtins.int + VERSION_ID_FIELD_NUMBER: builtins.int + feature_view_name: builtins.str + project_id: builtins.str + version_number: builtins.int + feature_view_type: builtins.str + """"feature_view" | "stream_feature_view" | "on_demand_feature_view" """ + feature_view_proto: builtins.bytes + """serialized FV proto snapshot""" + @property + def created_timestamp(self) -> google.protobuf.timestamp_pb2.Timestamp: ... + description: builtins.str + version_id: builtins.str + """auto-generated UUID for unique identification""" + def __init__( + self, + *, + feature_view_name: builtins.str = ..., + project_id: builtins.str = ..., + version_number: builtins.int = ..., + feature_view_type: builtins.str = ..., + feature_view_proto: builtins.bytes = ..., + created_timestamp: google.protobuf.timestamp_pb2.Timestamp | None = ..., + description: builtins.str = ..., + version_id: builtins.str = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "description", b"description", "feature_view_name", b"feature_view_name", "feature_view_proto", b"feature_view_proto", "feature_view_type", b"feature_view_type", "project_id", b"project_id", "version_id", b"version_id", "version_number", b"version_number"]) -> None: ... + +global___FeatureViewVersionRecord = FeatureViewVersionRecord + +class FeatureViewVersionHistory(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + RECORDS_FIELD_NUMBER: builtins.int + @property + def records(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___FeatureViewVersionRecord]: ... + def __init__( + self, + *, + records: collections.abc.Iterable[global___FeatureViewVersionRecord] | None = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["records", b"records"]) -> None: ... + +global___FeatureViewVersionHistory = FeatureViewVersionHistory diff --git a/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2_grpc.py b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2_grpc.py new file mode 100644 index 00000000000..2daafffebfc --- /dev/null +++ b/sdk/python/feast/protos/feast/core/FeatureViewVersion_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/sdk/python/feast/protos/feast/core/FeatureView_pb2.py b/sdk/python/feast/protos/feast/core/FeatureView_pb2.py index 0221a96031b..43995d4aa72 100644 --- a/sdk/python/feast/protos/feast/core/FeatureView_pb2.py +++ b/sdk/python/feast/protos/feast/core/FeatureView_pb2.py @@ -19,7 +19,7 @@ from feast.protos.feast.core import Transformation_pb2 as feast_dot_core_dot_Transformation__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66\x65\x61st/core/FeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"c\n\x0b\x46\x65\x61tureView\x12)\n\x04spec\x18\x01 \x01(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\xef\x04\n\x0f\x46\x65\x61tureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x33\n\x04tags\x18\x05 \x03(\x0b\x32%.feast.core.FeatureViewSpec.TagsEntry\x12&\n\x03ttl\x18\x06 \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\x07 \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x08 \x01(\x08\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x12\x13\n\x0b\x64\x65scription\x18\n \x01(\t\x12\r\n\x05owner\x18\x0b \x01(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0c \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x0f\n\x07offline\x18\r \x01(\x08\x12\x31\n\x0csource_views\x18\x0e \x03(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x0f \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x0c\n\x04mode\x18\x10 \x01(\t\x12\x19\n\x11\x65nable_validation\x18\x11 \x01(\x08\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xcc\x01\n\x0f\x46\x65\x61tureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x46\n\x19materialization_intervals\x18\x03 \x03(\x0b\x32#.feast.core.MaterializationInterval\"w\n\x17MaterializationInterval\x12.\n\nstart_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12,\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"@\n\x0f\x46\x65\x61tureViewList\x12-\n\x0c\x66\x65\x61tureviews\x18\x01 \x03(\x0b\x32\x17.feast.core.FeatureViewBU\n\x10\x66\x65\x61st.proto.coreB\x10\x46\x65\x61tureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1c\x66\x65\x61st/core/FeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"c\n\x0b\x46\x65\x61tureView\x12)\n\x04spec\x18\x01 \x01(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\x80\x05\n\x0f\x46\x65\x61tureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x33\n\x04tags\x18\x05 \x03(\x0b\x32%.feast.core.FeatureViewSpec.TagsEntry\x12&\n\x03ttl\x18\x06 \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\x07 \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x08 \x01(\x08\x12-\n\rstream_source\x18\t \x01(\x0b\x32\x16.feast.core.DataSource\x12\x13\n\x0b\x64\x65scription\x18\n \x01(\t\x12\r\n\x05owner\x18\x0b \x01(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0c \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x0f\n\x07offline\x18\r \x01(\x08\x12\x31\n\x0csource_views\x18\x0e \x03(\x0b\x32\x1b.feast.core.FeatureViewSpec\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x0f \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x0c\n\x04mode\x18\x10 \x01(\t\x12\x19\n\x11\x65nable_validation\x18\x11 \x01(\x08\x12\x0f\n\x07version\x18\x12 \x01(\t\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x80\x02\n\x0f\x46\x65\x61tureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x46\n\x19materialization_intervals\x18\x03 \x03(\x0b\x32#.feast.core.MaterializationInterval\x12\x1e\n\x16\x63urrent_version_number\x18\x04 \x01(\x05\x12\x12\n\nversion_id\x18\x05 \x01(\t\"w\n\x17MaterializationInterval\x12.\n\nstart_time\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12,\n\x08\x65nd_time\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"@\n\x0f\x46\x65\x61tureViewList\x12-\n\x0c\x66\x65\x61tureviews\x18\x01 \x03(\x0b\x32\x17.feast.core.FeatureViewBU\n\x10\x66\x65\x61st.proto.coreB\x10\x46\x65\x61tureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -32,13 +32,13 @@ _globals['_FEATUREVIEW']._serialized_start=197 _globals['_FEATUREVIEW']._serialized_end=296 _globals['_FEATUREVIEWSPEC']._serialized_start=299 - _globals['_FEATUREVIEWSPEC']._serialized_end=922 - _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_start=879 - _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_end=922 - _globals['_FEATUREVIEWMETA']._serialized_start=925 - _globals['_FEATUREVIEWMETA']._serialized_end=1129 - _globals['_MATERIALIZATIONINTERVAL']._serialized_start=1131 - _globals['_MATERIALIZATIONINTERVAL']._serialized_end=1250 - _globals['_FEATUREVIEWLIST']._serialized_start=1252 - _globals['_FEATUREVIEWLIST']._serialized_end=1316 + _globals['_FEATUREVIEWSPEC']._serialized_end=939 + _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_start=896 + _globals['_FEATUREVIEWSPEC_TAGSENTRY']._serialized_end=939 + _globals['_FEATUREVIEWMETA']._serialized_start=942 + _globals['_FEATUREVIEWMETA']._serialized_end=1198 + _globals['_MATERIALIZATIONINTERVAL']._serialized_start=1200 + _globals['_MATERIALIZATIONINTERVAL']._serialized_end=1319 + _globals['_FEATUREVIEWLIST']._serialized_start=1321 + _globals['_FEATUREVIEWLIST']._serialized_end=1385 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi index c5a54394320..a62e275260f 100644 --- a/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/FeatureView_pb2.pyi @@ -58,7 +58,7 @@ class FeatureView(google.protobuf.message.Message): global___FeatureView = FeatureView class FeatureViewSpec(google.protobuf.message.Message): - """Next available id: 18 + """Next available id: 19 TODO(adchia): refactor common fields from this and ODFV into separate metadata proto """ @@ -96,6 +96,7 @@ class FeatureViewSpec(google.protobuf.message.Message): FEATURE_TRANSFORMATION_FIELD_NUMBER: builtins.int MODE_FIELD_NUMBER: builtins.int ENABLE_VALIDATION_FIELD_NUMBER: builtins.int + VERSION_FIELD_NUMBER: builtins.int name: builtins.str """Name of the feature view. Must be unique. Not updated.""" project: builtins.str @@ -118,14 +119,18 @@ class FeatureViewSpec(google.protobuf.message.Message): """ @property def batch_source(self) -> feast.core.DataSource_pb2.DataSource: - """Batch/Offline DataSource where this view can retrieve offline feature data.""" + """Batch/Offline DataSource where this view can retrieve offline feature data. + Optional: if not set, the feature view has no associated batch data source (e.g. purely derived views). + """ online: builtins.bool """Whether these features should be served online or not This is also used to determine whether the features should be written to the online store """ @property def stream_source(self) -> feast.core.DataSource_pb2.DataSource: - """Streaming DataSource from where this view can consume "online" feature data.""" + """Streaming DataSource from where this view can consume "online" feature data. + Optional: only required for streaming feature views. + """ description: builtins.str """Description of the feature view.""" owner: builtins.str @@ -144,6 +149,8 @@ class FeatureViewSpec(google.protobuf.message.Message): """The transformation mode (e.g., "python", "pandas", "spark", "sql", "ray")""" enable_validation: builtins.bool """Whether schema validation is enabled during materialization""" + version: builtins.str + """User-specified version pin (e.g. "latest", "v2", "version2")""" def __init__( self, *, @@ -164,9 +171,10 @@ class FeatureViewSpec(google.protobuf.message.Message): feature_transformation: feast.core.Transformation_pb2.FeatureTransformationV2 | None = ..., mode: builtins.str = ..., enable_validation: builtins.bool = ..., + version: builtins.str = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "feature_transformation", b"feature_transformation", "stream_source", b"stream_source", "ttl", b"ttl"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "description", b"description", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "offline", b"offline", "online", b"online", "owner", b"owner", "project", b"project", "source_views", b"source_views", "stream_source", b"stream_source", "tags", b"tags", "ttl", b"ttl"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "description", b"description", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "offline", b"offline", "online", b"online", "owner", b"owner", "project", b"project", "source_views", b"source_views", "stream_source", b"stream_source", "tags", b"tags", "ttl", b"ttl", "version", b"version"]) -> None: ... global___FeatureViewSpec = FeatureViewSpec @@ -176,6 +184,8 @@ class FeatureViewMeta(google.protobuf.message.Message): CREATED_TIMESTAMP_FIELD_NUMBER: builtins.int LAST_UPDATED_TIMESTAMP_FIELD_NUMBER: builtins.int MATERIALIZATION_INTERVALS_FIELD_NUMBER: builtins.int + CURRENT_VERSION_NUMBER_FIELD_NUMBER: builtins.int + VERSION_ID_FIELD_NUMBER: builtins.int @property def created_timestamp(self) -> google.protobuf.timestamp_pb2.Timestamp: """Time where this Feature View is created""" @@ -185,15 +195,21 @@ class FeatureViewMeta(google.protobuf.message.Message): @property def materialization_intervals(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___MaterializationInterval]: """List of pairs (start_time, end_time) for which this feature view has been materialized.""" + current_version_number: builtins.int + """The current version number of this feature view in the version history.""" + version_id: builtins.str + """Auto-generated UUID identifying this specific version.""" def __init__( self, *, created_timestamp: google.protobuf.timestamp_pb2.Timestamp | None = ..., last_updated_timestamp: google.protobuf.timestamp_pb2.Timestamp | None = ..., materialization_intervals: collections.abc.Iterable[global___MaterializationInterval] | None = ..., + current_version_number: builtins.int = ..., + version_id: builtins.str = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "last_updated_timestamp", b"last_updated_timestamp"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "last_updated_timestamp", b"last_updated_timestamp", "materialization_intervals", b"materialization_intervals"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "current_version_number", b"current_version_number", "last_updated_timestamp", b"last_updated_timestamp", "materialization_intervals", b"materialization_intervals", "version_id", b"version_id"]) -> None: ... global___FeatureViewMeta = FeatureViewMeta diff --git a/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.py b/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.py index 5b8ec9b11f6..629c02c3a5f 100644 --- a/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.py +++ b/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.py @@ -21,7 +21,7 @@ from feast.protos.feast.core import Aggregation_pb2 as feast_dot_core_dot_Aggregation__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$feast/core/OnDemandFeatureView.proto\x12\nfeast.core\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a&feast/core/FeatureViewProjection.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\x1a\x1c\x66\x65\x61st/core/Aggregation.proto\"{\n\x13OnDemandFeatureView\x12\x31\n\x04spec\x18\x01 \x01(\x0b\x32#.feast.core.OnDemandFeatureViewSpec\x12\x31\n\x04meta\x18\x02 \x01(\x0b\x32#.feast.core.OnDemandFeatureViewMeta\"\xbf\x05\n\x17OnDemandFeatureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12+\n\x08\x66\x65\x61tures\x18\x03 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x41\n\x07sources\x18\x04 \x03(\x0b\x32\x30.feast.core.OnDemandFeatureViewSpec.SourcesEntry\x12\x42\n\x15user_defined_function\x18\x05 \x01(\x0b\x32\x1f.feast.core.UserDefinedFunctionB\x02\x18\x01\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\n \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x13\n\x0b\x64\x65scription\x18\x06 \x01(\t\x12;\n\x04tags\x18\x07 \x03(\x0b\x32-.feast.core.OnDemandFeatureViewSpec.TagsEntry\x12\r\n\x05owner\x18\x08 \x01(\t\x12\x0c\n\x04mode\x18\x0b \x01(\t\x12\x1d\n\x15write_to_online_store\x18\x0c \x01(\x08\x12\x10\n\x08\x65ntities\x18\r \x03(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0e \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x11\n\tsingleton\x18\x0f \x01(\x08\x12-\n\x0c\x61ggregations\x18\x10 \x03(\x0b\x32\x17.feast.core.Aggregation\x1aJ\n\x0cSourcesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.core.OnDemandSource:\x02\x38\x01\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x8c\x01\n\x17OnDemandFeatureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\"\xc8\x01\n\x0eOnDemandSource\x12/\n\x0c\x66\x65\x61ture_view\x18\x01 \x01(\x0b\x32\x17.feast.core.FeatureViewH\x00\x12\x44\n\x17\x66\x65\x61ture_view_projection\x18\x03 \x01(\x0b\x32!.feast.core.FeatureViewProjectionH\x00\x12\x35\n\x13request_data_source\x18\x02 \x01(\x0b\x32\x16.feast.core.DataSourceH\x00\x42\x08\n\x06source\"H\n\x13UserDefinedFunction\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x62ody\x18\x02 \x01(\x0c\x12\x11\n\tbody_text\x18\x03 \x01(\t:\x02\x18\x01\"X\n\x17OnDemandFeatureViewList\x12=\n\x14ondemandfeatureviews\x18\x01 \x03(\x0b\x32\x1f.feast.core.OnDemandFeatureViewB]\n\x10\x66\x65\x61st.proto.coreB\x18OnDemandFeatureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$feast/core/OnDemandFeatureView.proto\x12\nfeast.core\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a&feast/core/FeatureViewProjection.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\x1a\x1c\x66\x65\x61st/core/Aggregation.proto\"{\n\x13OnDemandFeatureView\x12\x31\n\x04spec\x18\x01 \x01(\x0b\x32#.feast.core.OnDemandFeatureViewSpec\x12\x31\n\x04meta\x18\x02 \x01(\x0b\x32#.feast.core.OnDemandFeatureViewMeta\"\xd0\x05\n\x17OnDemandFeatureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12+\n\x08\x66\x65\x61tures\x18\x03 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x41\n\x07sources\x18\x04 \x03(\x0b\x32\x30.feast.core.OnDemandFeatureViewSpec.SourcesEntry\x12\x42\n\x15user_defined_function\x18\x05 \x01(\x0b\x32\x1f.feast.core.UserDefinedFunctionB\x02\x18\x01\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\n \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x13\n\x0b\x64\x65scription\x18\x06 \x01(\t\x12;\n\x04tags\x18\x07 \x03(\x0b\x32-.feast.core.OnDemandFeatureViewSpec.TagsEntry\x12\r\n\x05owner\x18\x08 \x01(\t\x12\x0c\n\x04mode\x18\x0b \x01(\t\x12\x1d\n\x15write_to_online_store\x18\x0c \x01(\x08\x12\x10\n\x08\x65ntities\x18\r \x03(\t\x12\x31\n\x0e\x65ntity_columns\x18\x0e \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x11\n\tsingleton\x18\x0f \x01(\x08\x12-\n\x0c\x61ggregations\x18\x10 \x03(\x0b\x32\x17.feast.core.Aggregation\x12\x0f\n\x07version\x18\x11 \x01(\t\x1aJ\n\x0cSourcesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.core.OnDemandSource:\x02\x38\x01\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xc0\x01\n\x17OnDemandFeatureViewMeta\x12\x35\n\x11\x63reated_timestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12:\n\x16last_updated_timestamp\x18\x02 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12\x1e\n\x16\x63urrent_version_number\x18\x03 \x01(\x05\x12\x12\n\nversion_id\x18\x04 \x01(\t\"\xc8\x01\n\x0eOnDemandSource\x12/\n\x0c\x66\x65\x61ture_view\x18\x01 \x01(\x0b\x32\x17.feast.core.FeatureViewH\x00\x12\x44\n\x17\x66\x65\x61ture_view_projection\x18\x03 \x01(\x0b\x32!.feast.core.FeatureViewProjectionH\x00\x12\x35\n\x13request_data_source\x18\x02 \x01(\x0b\x32\x16.feast.core.DataSourceH\x00\x42\x08\n\x06source\"H\n\x13UserDefinedFunction\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04\x62ody\x18\x02 \x01(\x0c\x12\x11\n\tbody_text\x18\x03 \x01(\t:\x02\x18\x01\"X\n\x17OnDemandFeatureViewList\x12=\n\x14ondemandfeatureviews\x18\x01 \x03(\x0b\x32\x1f.feast.core.OnDemandFeatureViewB]\n\x10\x66\x65\x61st.proto.coreB\x18OnDemandFeatureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -40,17 +40,17 @@ _globals['_ONDEMANDFEATUREVIEW']._serialized_start=273 _globals['_ONDEMANDFEATUREVIEW']._serialized_end=396 _globals['_ONDEMANDFEATUREVIEWSPEC']._serialized_start=399 - _globals['_ONDEMANDFEATUREVIEWSPEC']._serialized_end=1102 - _globals['_ONDEMANDFEATUREVIEWSPEC_SOURCESENTRY']._serialized_start=983 - _globals['_ONDEMANDFEATUREVIEWSPEC_SOURCESENTRY']._serialized_end=1057 - _globals['_ONDEMANDFEATUREVIEWSPEC_TAGSENTRY']._serialized_start=1059 - _globals['_ONDEMANDFEATUREVIEWSPEC_TAGSENTRY']._serialized_end=1102 - _globals['_ONDEMANDFEATUREVIEWMETA']._serialized_start=1105 - _globals['_ONDEMANDFEATUREVIEWMETA']._serialized_end=1245 - _globals['_ONDEMANDSOURCE']._serialized_start=1248 - _globals['_ONDEMANDSOURCE']._serialized_end=1448 - _globals['_USERDEFINEDFUNCTION']._serialized_start=1450 - _globals['_USERDEFINEDFUNCTION']._serialized_end=1522 - _globals['_ONDEMANDFEATUREVIEWLIST']._serialized_start=1524 - _globals['_ONDEMANDFEATUREVIEWLIST']._serialized_end=1612 + _globals['_ONDEMANDFEATUREVIEWSPEC']._serialized_end=1119 + _globals['_ONDEMANDFEATUREVIEWSPEC_SOURCESENTRY']._serialized_start=1000 + _globals['_ONDEMANDFEATUREVIEWSPEC_SOURCESENTRY']._serialized_end=1074 + _globals['_ONDEMANDFEATUREVIEWSPEC_TAGSENTRY']._serialized_start=1076 + _globals['_ONDEMANDFEATUREVIEWSPEC_TAGSENTRY']._serialized_end=1119 + _globals['_ONDEMANDFEATUREVIEWMETA']._serialized_start=1122 + _globals['_ONDEMANDFEATUREVIEWMETA']._serialized_end=1314 + _globals['_ONDEMANDSOURCE']._serialized_start=1317 + _globals['_ONDEMANDSOURCE']._serialized_end=1517 + _globals['_USERDEFINEDFUNCTION']._serialized_start=1519 + _globals['_USERDEFINEDFUNCTION']._serialized_end=1591 + _globals['_ONDEMANDFEATUREVIEWLIST']._serialized_start=1593 + _globals['_ONDEMANDFEATUREVIEWLIST']._serialized_end=1681 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.pyi b/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.pyi index c424c442ee7..42fd91f7725 100644 --- a/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/OnDemandFeatureView_pb2.pyi @@ -59,7 +59,7 @@ class OnDemandFeatureView(google.protobuf.message.Message): global___OnDemandFeatureView = OnDemandFeatureView class OnDemandFeatureViewSpec(google.protobuf.message.Message): - """Next available id: 9""" + """Next available id: 18""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -110,6 +110,7 @@ class OnDemandFeatureViewSpec(google.protobuf.message.Message): ENTITY_COLUMNS_FIELD_NUMBER: builtins.int SINGLETON_FIELD_NUMBER: builtins.int AGGREGATIONS_FIELD_NUMBER: builtins.int + VERSION_FIELD_NUMBER: builtins.int name: builtins.str """Name of the feature view. Must be unique. Not updated.""" project: builtins.str @@ -144,6 +145,8 @@ class OnDemandFeatureViewSpec(google.protobuf.message.Message): @property def aggregations(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[feast.core.Aggregation_pb2.Aggregation]: """Aggregation definitions""" + version: builtins.str + """User-specified version pin (e.g. "latest", "v2", "version2")""" def __init__( self, *, @@ -162,9 +165,10 @@ class OnDemandFeatureViewSpec(google.protobuf.message.Message): entity_columns: collections.abc.Iterable[feast.core.Feature_pb2.FeatureSpecV2] | None = ..., singleton: builtins.bool = ..., aggregations: collections.abc.Iterable[feast.core.Aggregation_pb2.Aggregation] | None = ..., + version: builtins.str = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["feature_transformation", b"feature_transformation", "user_defined_function", b"user_defined_function"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["aggregations", b"aggregations", "description", b"description", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "owner", b"owner", "project", b"project", "singleton", b"singleton", "sources", b"sources", "tags", b"tags", "user_defined_function", b"user_defined_function", "write_to_online_store", b"write_to_online_store"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["aggregations", b"aggregations", "description", b"description", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "owner", b"owner", "project", b"project", "singleton", b"singleton", "sources", b"sources", "tags", b"tags", "user_defined_function", b"user_defined_function", "version", b"version", "write_to_online_store", b"write_to_online_store"]) -> None: ... global___OnDemandFeatureViewSpec = OnDemandFeatureViewSpec @@ -173,20 +177,28 @@ class OnDemandFeatureViewMeta(google.protobuf.message.Message): CREATED_TIMESTAMP_FIELD_NUMBER: builtins.int LAST_UPDATED_TIMESTAMP_FIELD_NUMBER: builtins.int + CURRENT_VERSION_NUMBER_FIELD_NUMBER: builtins.int + VERSION_ID_FIELD_NUMBER: builtins.int @property def created_timestamp(self) -> google.protobuf.timestamp_pb2.Timestamp: """Time where this Feature View is created""" @property def last_updated_timestamp(self) -> google.protobuf.timestamp_pb2.Timestamp: """Time where this Feature View is last updated""" + current_version_number: builtins.int + """The current version number of this feature view in the version history.""" + version_id: builtins.str + """Auto-generated UUID identifying this specific version.""" def __init__( self, *, created_timestamp: google.protobuf.timestamp_pb2.Timestamp | None = ..., last_updated_timestamp: google.protobuf.timestamp_pb2.Timestamp | None = ..., + current_version_number: builtins.int = ..., + version_id: builtins.str = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "last_updated_timestamp", b"last_updated_timestamp"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "last_updated_timestamp", b"last_updated_timestamp"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["created_timestamp", b"created_timestamp", "current_version_number", b"current_version_number", "last_updated_timestamp", b"last_updated_timestamp", "version_id", b"version_id"]) -> None: ... global___OnDemandFeatureViewMeta = OnDemandFeatureViewMeta diff --git a/sdk/python/feast/protos/feast/core/Project_pb2.pyi b/sdk/python/feast/protos/feast/core/Project_pb2.pyi index e3cce2ec425..3196304a19b 100644 --- a/sdk/python/feast/protos/feast/core/Project_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/Project_pb2.pyi @@ -1,19 +1,19 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file - -* Copyright 2020 The Feast Authors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* https://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and + +* Copyright 2020 The Feast Authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* https://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. """ import builtins diff --git a/sdk/python/feast/protos/feast/core/Registry_pb2.py b/sdk/python/feast/protos/feast/core/Registry_pb2.py index 671958d80c7..04c4e700597 100644 --- a/sdk/python/feast/protos/feast/core/Registry_pb2.py +++ b/sdk/python/feast/protos/feast/core/Registry_pb2.py @@ -25,9 +25,10 @@ from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 from feast.protos.feast.core import Permission_pb2 as feast_dot_core_dot_Permission__pb2 from feast.protos.feast.core import Project_pb2 as feast_dot_core_dot_Project__pb2 +from feast.protos.feast.core import FeatureViewVersion_pb2 as feast_dot_core_dot_FeatureViewVersion__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x19\x66\x65\x61st/core/Registry.proto\x12\nfeast.core\x1a\x17\x66\x65\x61st/core/Entity.proto\x1a\x1f\x66\x65\x61st/core/FeatureService.proto\x1a\x1d\x66\x65\x61st/core/FeatureTable.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a\x1c\x66\x65\x61st/core/InfraObject.proto\x1a$feast/core/OnDemandFeatureView.proto\x1a\"feast/core/StreamFeatureView.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1d\x66\x65\x61st/core/SavedDataset.proto\x1a\"feast/core/ValidationProfile.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/Permission.proto\x1a\x18\x66\x65\x61st/core/Project.proto\"\xff\x05\n\x08Registry\x12$\n\x08\x65ntities\x18\x01 \x03(\x0b\x32\x12.feast.core.Entity\x12\x30\n\x0e\x66\x65\x61ture_tables\x18\x02 \x03(\x0b\x32\x18.feast.core.FeatureTable\x12.\n\rfeature_views\x18\x06 \x03(\x0b\x32\x17.feast.core.FeatureView\x12,\n\x0c\x64\x61ta_sources\x18\x0c \x03(\x0b\x32\x16.feast.core.DataSource\x12@\n\x17on_demand_feature_views\x18\x08 \x03(\x0b\x32\x1f.feast.core.OnDemandFeatureView\x12;\n\x14stream_feature_views\x18\x0e \x03(\x0b\x32\x1d.feast.core.StreamFeatureView\x12\x34\n\x10\x66\x65\x61ture_services\x18\x07 \x03(\x0b\x32\x1a.feast.core.FeatureService\x12\x30\n\x0esaved_datasets\x18\x0b \x03(\x0b\x32\x18.feast.core.SavedDataset\x12>\n\x15validation_references\x18\r \x03(\x0b\x32\x1f.feast.core.ValidationReference\x12 \n\x05infra\x18\n \x01(\x0b\x32\x11.feast.core.Infra\x12\x39\n\x10project_metadata\x18\x0f \x03(\x0b\x32\x1b.feast.core.ProjectMetadataB\x02\x18\x01\x12\x1f\n\x17registry_schema_version\x18\x03 \x01(\t\x12\x12\n\nversion_id\x18\x04 \x01(\t\x12\x30\n\x0clast_updated\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12+\n\x0bpermissions\x18\x10 \x03(\x0b\x32\x16.feast.core.Permission\x12%\n\x08projects\x18\x11 \x03(\x0b\x32\x13.feast.core.Project\"8\n\x0fProjectMetadata\x12\x0f\n\x07project\x18\x01 \x01(\t\x12\x14\n\x0cproject_uuid\x18\x02 \x01(\tBR\n\x10\x66\x65\x61st.proto.coreB\rRegistryProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x19\x66\x65\x61st/core/Registry.proto\x12\nfeast.core\x1a\x17\x66\x65\x61st/core/Entity.proto\x1a\x1f\x66\x65\x61st/core/FeatureService.proto\x1a\x1d\x66\x65\x61st/core/FeatureTable.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a\x1c\x66\x65\x61st/core/InfraObject.proto\x1a$feast/core/OnDemandFeatureView.proto\x1a\"feast/core/StreamFeatureView.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1d\x66\x65\x61st/core/SavedDataset.proto\x1a\"feast/core/ValidationProfile.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x1b\x66\x65\x61st/core/Permission.proto\x1a\x18\x66\x65\x61st/core/Project.proto\x1a#feast/core/FeatureViewVersion.proto\"\xcc\x06\n\x08Registry\x12$\n\x08\x65ntities\x18\x01 \x03(\x0b\x32\x12.feast.core.Entity\x12\x30\n\x0e\x66\x65\x61ture_tables\x18\x02 \x03(\x0b\x32\x18.feast.core.FeatureTable\x12.\n\rfeature_views\x18\x06 \x03(\x0b\x32\x17.feast.core.FeatureView\x12,\n\x0c\x64\x61ta_sources\x18\x0c \x03(\x0b\x32\x16.feast.core.DataSource\x12@\n\x17on_demand_feature_views\x18\x08 \x03(\x0b\x32\x1f.feast.core.OnDemandFeatureView\x12;\n\x14stream_feature_views\x18\x0e \x03(\x0b\x32\x1d.feast.core.StreamFeatureView\x12\x34\n\x10\x66\x65\x61ture_services\x18\x07 \x03(\x0b\x32\x1a.feast.core.FeatureService\x12\x30\n\x0esaved_datasets\x18\x0b \x03(\x0b\x32\x18.feast.core.SavedDataset\x12>\n\x15validation_references\x18\r \x03(\x0b\x32\x1f.feast.core.ValidationReference\x12 \n\x05infra\x18\n \x01(\x0b\x32\x11.feast.core.Infra\x12\x39\n\x10project_metadata\x18\x0f \x03(\x0b\x32\x1b.feast.core.ProjectMetadataB\x02\x18\x01\x12\x1f\n\x17registry_schema_version\x18\x03 \x01(\t\x12\x12\n\nversion_id\x18\x04 \x01(\t\x12\x30\n\x0clast_updated\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12+\n\x0bpermissions\x18\x10 \x03(\x0b\x32\x16.feast.core.Permission\x12%\n\x08projects\x18\x11 \x03(\x0b\x32\x13.feast.core.Project\x12K\n\x1c\x66\x65\x61ture_view_version_history\x18\x12 \x01(\x0b\x32%.feast.core.FeatureViewVersionHistory\"8\n\x0fProjectMetadata\x12\x0f\n\x07project\x18\x01 \x01(\t\x12\x14\n\x0cproject_uuid\x18\x02 \x01(\tBR\n\x10\x66\x65\x61st.proto.coreB\rRegistryProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -37,8 +38,8 @@ _globals['DESCRIPTOR']._serialized_options = b'\n\020feast.proto.coreB\rRegistryProtoZ/github.com/feast-dev/feast/go/protos/feast/core' _globals['_REGISTRY'].fields_by_name['project_metadata']._options = None _globals['_REGISTRY'].fields_by_name['project_metadata']._serialized_options = b'\030\001' - _globals['_REGISTRY']._serialized_start=449 - _globals['_REGISTRY']._serialized_end=1216 - _globals['_PROJECTMETADATA']._serialized_start=1218 - _globals['_PROJECTMETADATA']._serialized_end=1274 + _globals['_REGISTRY']._serialized_start=486 + _globals['_REGISTRY']._serialized_end=1330 + _globals['_PROJECTMETADATA']._serialized_start=1332 + _globals['_PROJECTMETADATA']._serialized_end=1388 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/Registry_pb2.pyi b/sdk/python/feast/protos/feast/core/Registry_pb2.pyi index fca49c75481..29bd76323e3 100644 --- a/sdk/python/feast/protos/feast/core/Registry_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/Registry_pb2.pyi @@ -1,19 +1,19 @@ """ @generated by mypy-protobuf. Do not edit manually! isort:skip_file - -* Copyright 2020 The Feast Authors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* https://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and + +* Copyright 2020 The Feast Authors +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* https://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and * limitations under the License. """ import builtins @@ -22,6 +22,7 @@ import feast.core.DataSource_pb2 import feast.core.Entity_pb2 import feast.core.FeatureService_pb2 import feast.core.FeatureTable_pb2 +import feast.core.FeatureViewVersion_pb2 import feast.core.FeatureView_pb2 import feast.core.InfraObject_pb2 import feast.core.OnDemandFeatureView_pb2 @@ -44,7 +45,7 @@ else: DESCRIPTOR: google.protobuf.descriptor.FileDescriptor class Registry(google.protobuf.message.Message): - """Next id: 18""" + """Next id: 19""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -64,6 +65,7 @@ class Registry(google.protobuf.message.Message): LAST_UPDATED_FIELD_NUMBER: builtins.int PERMISSIONS_FIELD_NUMBER: builtins.int PROJECTS_FIELD_NUMBER: builtins.int + FEATURE_VIEW_VERSION_HISTORY_FIELD_NUMBER: builtins.int @property def entities(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[feast.core.Entity_pb2.Entity]: ... @property @@ -97,6 +99,8 @@ class Registry(google.protobuf.message.Message): def permissions(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[feast.core.Permission_pb2.Permission]: ... @property def projects(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[feast.core.Project_pb2.Project]: ... + @property + def feature_view_version_history(self) -> feast.core.FeatureViewVersion_pb2.FeatureViewVersionHistory: ... def __init__( self, *, @@ -116,9 +120,10 @@ class Registry(google.protobuf.message.Message): last_updated: google.protobuf.timestamp_pb2.Timestamp | None = ..., permissions: collections.abc.Iterable[feast.core.Permission_pb2.Permission] | None = ..., projects: collections.abc.Iterable[feast.core.Project_pb2.Project] | None = ..., + feature_view_version_history: feast.core.FeatureViewVersion_pb2.FeatureViewVersionHistory | None = ..., ) -> None: ... - def HasField(self, field_name: typing_extensions.Literal["infra", b"infra", "last_updated", b"last_updated"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["data_sources", b"data_sources", "entities", b"entities", "feature_services", b"feature_services", "feature_tables", b"feature_tables", "feature_views", b"feature_views", "infra", b"infra", "last_updated", b"last_updated", "on_demand_feature_views", b"on_demand_feature_views", "permissions", b"permissions", "project_metadata", b"project_metadata", "projects", b"projects", "registry_schema_version", b"registry_schema_version", "saved_datasets", b"saved_datasets", "stream_feature_views", b"stream_feature_views", "validation_references", b"validation_references", "version_id", b"version_id"]) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["feature_view_version_history", b"feature_view_version_history", "infra", b"infra", "last_updated", b"last_updated"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["data_sources", b"data_sources", "entities", b"entities", "feature_services", b"feature_services", "feature_tables", b"feature_tables", "feature_view_version_history", b"feature_view_version_history", "feature_views", b"feature_views", "infra", b"infra", "last_updated", b"last_updated", "on_demand_feature_views", b"on_demand_feature_views", "permissions", b"permissions", "project_metadata", b"project_metadata", "projects", b"projects", "registry_schema_version", b"registry_schema_version", "saved_datasets", b"saved_datasets", "stream_feature_views", b"stream_feature_views", "validation_references", b"validation_references", "version_id", b"version_id"]) -> None: ... global___Registry = Registry diff --git a/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.py b/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.py index cd3ec690574..3c87e635b92 100644 --- a/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.py +++ b/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.py @@ -21,7 +21,7 @@ from feast.protos.feast.core import Transformation_pb2 as feast_dot_core_dot_Transformation__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"feast/core/StreamFeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a$feast/core/OnDemandFeatureView.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1c\x66\x65\x61st/core/Aggregation.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"o\n\x11StreamFeatureView\x12/\n\x04spec\x18\x01 \x01(\x0b\x32!.feast.core.StreamFeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\x8e\x06\n\x15StreamFeatureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x31\n\x0e\x65ntity_columns\x18\x05 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x13\n\x0b\x64\x65scription\x18\x06 \x01(\t\x12\x39\n\x04tags\x18\x07 \x03(\x0b\x32+.feast.core.StreamFeatureViewSpec.TagsEntry\x12\r\n\x05owner\x18\x08 \x01(\t\x12&\n\x03ttl\x18\t \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\n \x01(\x0b\x32\x16.feast.core.DataSource\x12-\n\rstream_source\x18\x0b \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x0c \x01(\x08\x12\x42\n\x15user_defined_function\x18\r \x01(\x0b\x32\x1f.feast.core.UserDefinedFunctionB\x02\x18\x01\x12\x0c\n\x04mode\x18\x0e \x01(\t\x12-\n\x0c\x61ggregations\x18\x0f \x03(\x0b\x32\x17.feast.core.Aggregation\x12\x17\n\x0ftimestamp_field\x18\x10 \x01(\t\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x11 \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x15\n\renable_tiling\x18\x12 \x01(\x08\x12\x32\n\x0ftiling_hop_size\x18\x13 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x19\n\x11\x65nable_validation\x18\x14 \x01(\x08\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42[\n\x10\x66\x65\x61st.proto.coreB\x16StreamFeatureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"feast/core/StreamFeatureView.proto\x12\nfeast.core\x1a\x1egoogle/protobuf/duration.proto\x1a$feast/core/OnDemandFeatureView.proto\x1a\x1c\x66\x65\x61st/core/FeatureView.proto\x1a\x18\x66\x65\x61st/core/Feature.proto\x1a\x1b\x66\x65\x61st/core/DataSource.proto\x1a\x1c\x66\x65\x61st/core/Aggregation.proto\x1a\x1f\x66\x65\x61st/core/Transformation.proto\"o\n\x11StreamFeatureView\x12/\n\x04spec\x18\x01 \x01(\x0b\x32!.feast.core.StreamFeatureViewSpec\x12)\n\x04meta\x18\x02 \x01(\x0b\x32\x1b.feast.core.FeatureViewMeta\"\x9f\x06\n\x15StreamFeatureViewSpec\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07project\x18\x02 \x01(\t\x12\x10\n\x08\x65ntities\x18\x03 \x03(\t\x12+\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x31\n\x0e\x65ntity_columns\x18\x05 \x03(\x0b\x32\x19.feast.core.FeatureSpecV2\x12\x13\n\x0b\x64\x65scription\x18\x06 \x01(\t\x12\x39\n\x04tags\x18\x07 \x03(\x0b\x32+.feast.core.StreamFeatureViewSpec.TagsEntry\x12\r\n\x05owner\x18\x08 \x01(\t\x12&\n\x03ttl\x18\t \x01(\x0b\x32\x19.google.protobuf.Duration\x12,\n\x0c\x62\x61tch_source\x18\n \x01(\x0b\x32\x16.feast.core.DataSource\x12-\n\rstream_source\x18\x0b \x01(\x0b\x32\x16.feast.core.DataSource\x12\x0e\n\x06online\x18\x0c \x01(\x08\x12\x42\n\x15user_defined_function\x18\r \x01(\x0b\x32\x1f.feast.core.UserDefinedFunctionB\x02\x18\x01\x12\x0c\n\x04mode\x18\x0e \x01(\t\x12-\n\x0c\x61ggregations\x18\x0f \x03(\x0b\x32\x17.feast.core.Aggregation\x12\x17\n\x0ftimestamp_field\x18\x10 \x01(\t\x12\x43\n\x16\x66\x65\x61ture_transformation\x18\x11 \x01(\x0b\x32#.feast.core.FeatureTransformationV2\x12\x15\n\renable_tiling\x18\x12 \x01(\x08\x12\x32\n\x0ftiling_hop_size\x18\x13 \x01(\x0b\x32\x19.google.protobuf.Duration\x12\x19\n\x11\x65nable_validation\x18\x14 \x01(\x08\x12\x0f\n\x07version\x18\x15 \x01(\t\x1a+\n\tTagsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42[\n\x10\x66\x65\x61st.proto.coreB\x16StreamFeatureViewProtoZ/github.com/feast-dev/feast/go/protos/feast/coreb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -36,7 +36,7 @@ _globals['_STREAMFEATUREVIEW']._serialized_start=268 _globals['_STREAMFEATUREVIEW']._serialized_end=379 _globals['_STREAMFEATUREVIEWSPEC']._serialized_start=382 - _globals['_STREAMFEATUREVIEWSPEC']._serialized_end=1164 - _globals['_STREAMFEATUREVIEWSPEC_TAGSENTRY']._serialized_start=1121 - _globals['_STREAMFEATUREVIEWSPEC_TAGSENTRY']._serialized_end=1164 + _globals['_STREAMFEATUREVIEWSPEC']._serialized_end=1181 + _globals['_STREAMFEATUREVIEWSPEC_TAGSENTRY']._serialized_start=1138 + _globals['_STREAMFEATUREVIEWSPEC_TAGSENTRY']._serialized_end=1181 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.pyi b/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.pyi index 853ada60a27..b4ab6a9a016 100644 --- a/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.pyi +++ b/sdk/python/feast/protos/feast/core/StreamFeatureView_pb2.pyi @@ -59,7 +59,7 @@ class StreamFeatureView(google.protobuf.message.Message): global___StreamFeatureView = StreamFeatureView class StreamFeatureViewSpec(google.protobuf.message.Message): - """Next available id: 21""" + """Next available id: 22""" DESCRIPTOR: google.protobuf.descriptor.Descriptor @@ -98,6 +98,7 @@ class StreamFeatureViewSpec(google.protobuf.message.Message): ENABLE_TILING_FIELD_NUMBER: builtins.int TILING_HOP_SIZE_FIELD_NUMBER: builtins.int ENABLE_VALIDATION_FIELD_NUMBER: builtins.int + VERSION_FIELD_NUMBER: builtins.int name: builtins.str """Name of the feature view. Must be unique. Not updated.""" project: builtins.str @@ -155,6 +156,8 @@ class StreamFeatureViewSpec(google.protobuf.message.Message): """ enable_validation: builtins.bool """Whether schema validation is enabled during materialization""" + version: builtins.str + """User-specified version pin (e.g. "latest", "v2", "version2")""" def __init__( self, *, @@ -178,8 +181,9 @@ class StreamFeatureViewSpec(google.protobuf.message.Message): enable_tiling: builtins.bool = ..., tiling_hop_size: google.protobuf.duration_pb2.Duration | None = ..., enable_validation: builtins.bool = ..., + version: builtins.str = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["batch_source", b"batch_source", "feature_transformation", b"feature_transformation", "stream_source", b"stream_source", "tiling_hop_size", b"tiling_hop_size", "ttl", b"ttl", "user_defined_function", b"user_defined_function"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["aggregations", b"aggregations", "batch_source", b"batch_source", "description", b"description", "enable_tiling", b"enable_tiling", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "online", b"online", "owner", b"owner", "project", b"project", "stream_source", b"stream_source", "tags", b"tags", "tiling_hop_size", b"tiling_hop_size", "timestamp_field", b"timestamp_field", "ttl", b"ttl", "user_defined_function", b"user_defined_function"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["aggregations", b"aggregations", "batch_source", b"batch_source", "description", b"description", "enable_tiling", b"enable_tiling", "enable_validation", b"enable_validation", "entities", b"entities", "entity_columns", b"entity_columns", "feature_transformation", b"feature_transformation", "features", b"features", "mode", b"mode", "name", b"name", "online", b"online", "owner", b"owner", "project", b"project", "stream_source", b"stream_source", "tags", b"tags", "tiling_hop_size", b"tiling_hop_size", "timestamp_field", b"timestamp_field", "ttl", b"ttl", "user_defined_function", b"user_defined_function", "version", b"version"]) -> None: ... global___StreamFeatureViewSpec = StreamFeatureViewSpec diff --git a/sdk/python/feast/protos/feast/serving/ServingService_pb2.py b/sdk/python/feast/protos/feast/serving/ServingService_pb2.py index fa866640577..82ade7eb988 100644 --- a/sdk/python/feast/protos/feast/serving/ServingService_pb2.py +++ b/sdk/python/feast/protos/feast/serving/ServingService_pb2.py @@ -16,7 +16,7 @@ from feast.protos.feast.types import Value_pb2 as feast_dot_types_dot_Value__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"feast/serving/ServingService.proto\x12\rfeast.serving\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17\x66\x65\x61st/types/Value.proto\"\x1c\n\x1aGetFeastServingInfoRequest\".\n\x1bGetFeastServingInfoResponse\x12\x0f\n\x07version\x18\x01 \x01(\t\"E\n\x12\x46\x65\x61tureReferenceV2\x12\x19\n\x11\x66\x65\x61ture_view_name\x18\x01 \x01(\t\x12\x14\n\x0c\x66\x65\x61ture_name\x18\x02 \x01(\t\"\xfd\x02\n\x1aGetOnlineFeaturesRequestV2\x12\x33\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32!.feast.serving.FeatureReferenceV2\x12H\n\x0b\x65ntity_rows\x18\x02 \x03(\x0b\x32\x33.feast.serving.GetOnlineFeaturesRequestV2.EntityRow\x12\x0f\n\x07project\x18\x05 \x01(\t\x1a\xce\x01\n\tEntityRow\x12-\n\ttimestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12O\n\x06\x66ields\x18\x02 \x03(\x0b\x32?.feast.serving.GetOnlineFeaturesRequestV2.EntityRow.FieldsEntry\x1a\x41\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12!\n\x05value\x18\x02 \x01(\x0b\x32\x12.feast.types.Value:\x02\x38\x01\"\x1a\n\x0b\x46\x65\x61tureList\x12\x0b\n\x03val\x18\x01 \x03(\t\"\xc8\x03\n\x18GetOnlineFeaturesRequest\x12\x19\n\x0f\x66\x65\x61ture_service\x18\x01 \x01(\tH\x00\x12.\n\x08\x66\x65\x61tures\x18\x02 \x01(\x0b\x32\x1a.feast.serving.FeatureListH\x00\x12G\n\x08\x65ntities\x18\x03 \x03(\x0b\x32\x35.feast.serving.GetOnlineFeaturesRequest.EntitiesEntry\x12\x1a\n\x12\x66ull_feature_names\x18\x04 \x01(\x08\x12T\n\x0frequest_context\x18\x05 \x03(\x0b\x32;.feast.serving.GetOnlineFeaturesRequest.RequestContextEntry\x1aK\n\rEntitiesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.types.RepeatedValue:\x02\x38\x01\x1aQ\n\x13RequestContextEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.types.RepeatedValue:\x02\x38\x01\x42\x06\n\x04kind\"\xd2\x02\n\x19GetOnlineFeaturesResponse\x12\x42\n\x08metadata\x18\x01 \x01(\x0b\x32\x30.feast.serving.GetOnlineFeaturesResponseMetadata\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.feast.serving.GetOnlineFeaturesResponse.FeatureVector\x12\x0e\n\x06status\x18\x03 \x01(\x08\x1a\x97\x01\n\rFeatureVector\x12\"\n\x06values\x18\x01 \x03(\x0b\x32\x12.feast.types.Value\x12,\n\x08statuses\x18\x02 \x03(\x0e\x32\x1a.feast.serving.FieldStatus\x12\x34\n\x10\x65vent_timestamps\x18\x03 \x03(\x0b\x32\x1a.google.protobuf.Timestamp\"V\n!GetOnlineFeaturesResponseMetadata\x12\x31\n\rfeature_names\x18\x01 \x01(\x0b\x32\x1a.feast.serving.FeatureList*[\n\x0b\x46ieldStatus\x12\x0b\n\x07INVALID\x10\x00\x12\x0b\n\x07PRESENT\x10\x01\x12\x0e\n\nNULL_VALUE\x10\x02\x12\r\n\tNOT_FOUND\x10\x03\x12\x13\n\x0fOUTSIDE_MAX_AGE\x10\x04\x32\xe6\x01\n\x0eServingService\x12l\n\x13GetFeastServingInfo\x12).feast.serving.GetFeastServingInfoRequest\x1a*.feast.serving.GetFeastServingInfoResponse\x12\x66\n\x11GetOnlineFeatures\x12\'.feast.serving.GetOnlineFeaturesRequest\x1a(.feast.serving.GetOnlineFeaturesResponseBZ\n\x13\x66\x65\x61st.proto.servingB\x0fServingAPIProtoZ2github.com/feast-dev/feast/go/protos/feast/servingb\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\"feast/serving/ServingService.proto\x12\rfeast.serving\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x17\x66\x65\x61st/types/Value.proto\"\x1c\n\x1aGetFeastServingInfoRequest\".\n\x1bGetFeastServingInfoResponse\x12\x0f\n\x07version\x18\x01 \x01(\t\"E\n\x12\x46\x65\x61tureReferenceV2\x12\x19\n\x11\x66\x65\x61ture_view_name\x18\x01 \x01(\t\x12\x14\n\x0c\x66\x65\x61ture_name\x18\x02 \x01(\t\"\xfd\x02\n\x1aGetOnlineFeaturesRequestV2\x12\x33\n\x08\x66\x65\x61tures\x18\x04 \x03(\x0b\x32!.feast.serving.FeatureReferenceV2\x12H\n\x0b\x65ntity_rows\x18\x02 \x03(\x0b\x32\x33.feast.serving.GetOnlineFeaturesRequestV2.EntityRow\x12\x0f\n\x07project\x18\x05 \x01(\t\x1a\xce\x01\n\tEntityRow\x12-\n\ttimestamp\x18\x01 \x01(\x0b\x32\x1a.google.protobuf.Timestamp\x12O\n\x06\x66ields\x18\x02 \x03(\x0b\x32?.feast.serving.GetOnlineFeaturesRequestV2.EntityRow.FieldsEntry\x1a\x41\n\x0b\x46ieldsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12!\n\x05value\x18\x02 \x01(\x0b\x32\x12.feast.types.Value:\x02\x38\x01\"\x1a\n\x0b\x46\x65\x61tureList\x12\x0b\n\x03val\x18\x01 \x03(\t\"\xf7\x03\n\x18GetOnlineFeaturesRequest\x12\x19\n\x0f\x66\x65\x61ture_service\x18\x01 \x01(\tH\x00\x12.\n\x08\x66\x65\x61tures\x18\x02 \x01(\x0b\x32\x1a.feast.serving.FeatureListH\x00\x12G\n\x08\x65ntities\x18\x03 \x03(\x0b\x32\x35.feast.serving.GetOnlineFeaturesRequest.EntitiesEntry\x12\x1a\n\x12\x66ull_feature_names\x18\x04 \x01(\x08\x12T\n\x0frequest_context\x18\x05 \x03(\x0b\x32;.feast.serving.GetOnlineFeaturesRequest.RequestContextEntry\x12-\n%include_feature_view_version_metadata\x18\x06 \x01(\x08\x1aK\n\rEntitiesEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.types.RepeatedValue:\x02\x38\x01\x1aQ\n\x13RequestContextEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12)\n\x05value\x18\x02 \x01(\x0b\x32\x1a.feast.types.RepeatedValue:\x02\x38\x01\x42\x06\n\x04kind\"\xd2\x02\n\x19GetOnlineFeaturesResponse\x12\x42\n\x08metadata\x18\x01 \x01(\x0b\x32\x30.feast.serving.GetOnlineFeaturesResponseMetadata\x12G\n\x07results\x18\x02 \x03(\x0b\x32\x36.feast.serving.GetOnlineFeaturesResponse.FeatureVector\x12\x0e\n\x06status\x18\x03 \x01(\x08\x1a\x97\x01\n\rFeatureVector\x12\"\n\x06values\x18\x01 \x03(\x0b\x32\x12.feast.types.Value\x12,\n\x08statuses\x18\x02 \x03(\x0e\x32\x1a.feast.serving.FieldStatus\x12\x34\n\x10\x65vent_timestamps\x18\x03 \x03(\x0b\x32\x1a.google.protobuf.Timestamp\"4\n\x13\x46\x65\x61tureViewMetadata\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0f\n\x07version\x18\x02 \x01(\x05\"\x99\x01\n!GetOnlineFeaturesResponseMetadata\x12\x31\n\rfeature_names\x18\x01 \x01(\x0b\x32\x1a.feast.serving.FeatureList\x12\x41\n\x15\x66\x65\x61ture_view_metadata\x18\x02 \x03(\x0b\x32\".feast.serving.FeatureViewMetadata*[\n\x0b\x46ieldStatus\x12\x0b\n\x07INVALID\x10\x00\x12\x0b\n\x07PRESENT\x10\x01\x12\x0e\n\nNULL_VALUE\x10\x02\x12\r\n\tNOT_FOUND\x10\x03\x12\x13\n\x0fOUTSIDE_MAX_AGE\x10\x04\x32\xe6\x01\n\x0eServingService\x12l\n\x13GetFeastServingInfo\x12).feast.serving.GetFeastServingInfoRequest\x1a*.feast.serving.GetFeastServingInfoResponse\x12\x66\n\x11GetOnlineFeatures\x12\'.feast.serving.GetOnlineFeaturesRequest\x1a(.feast.serving.GetOnlineFeaturesResponseBZ\n\x13\x66\x65\x61st.proto.servingB\x0fServingAPIProtoZ2github.com/feast-dev/feast/go/protos/feast/servingb\x06proto3') _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) @@ -30,8 +30,8 @@ _globals['_GETONLINEFEATURESREQUEST_ENTITIESENTRY']._serialized_options = b'8\001' _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._options = None _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._serialized_options = b'8\001' - _globals['_FIELDSTATUS']._serialized_start=1560 - _globals['_FIELDSTATUS']._serialized_end=1651 + _globals['_FIELDSTATUS']._serialized_start=1729 + _globals['_FIELDSTATUS']._serialized_end=1820 _globals['_GETFEASTSERVINGINFOREQUEST']._serialized_start=111 _globals['_GETFEASTSERVINGINFOREQUEST']._serialized_end=139 _globals['_GETFEASTSERVINGINFORESPONSE']._serialized_start=141 @@ -47,17 +47,19 @@ _globals['_FEATURELIST']._serialized_start=644 _globals['_FEATURELIST']._serialized_end=670 _globals['_GETONLINEFEATURESREQUEST']._serialized_start=673 - _globals['_GETONLINEFEATURESREQUEST']._serialized_end=1129 - _globals['_GETONLINEFEATURESREQUEST_ENTITIESENTRY']._serialized_start=963 - _globals['_GETONLINEFEATURESREQUEST_ENTITIESENTRY']._serialized_end=1038 - _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._serialized_start=1040 - _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._serialized_end=1121 - _globals['_GETONLINEFEATURESRESPONSE']._serialized_start=1132 - _globals['_GETONLINEFEATURESRESPONSE']._serialized_end=1470 - _globals['_GETONLINEFEATURESRESPONSE_FEATUREVECTOR']._serialized_start=1319 - _globals['_GETONLINEFEATURESRESPONSE_FEATUREVECTOR']._serialized_end=1470 - _globals['_GETONLINEFEATURESRESPONSEMETADATA']._serialized_start=1472 - _globals['_GETONLINEFEATURESRESPONSEMETADATA']._serialized_end=1558 - _globals['_SERVINGSERVICE']._serialized_start=1654 - _globals['_SERVINGSERVICE']._serialized_end=1884 + _globals['_GETONLINEFEATURESREQUEST']._serialized_end=1176 + _globals['_GETONLINEFEATURESREQUEST_ENTITIESENTRY']._serialized_start=1010 + _globals['_GETONLINEFEATURESREQUEST_ENTITIESENTRY']._serialized_end=1085 + _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._serialized_start=1087 + _globals['_GETONLINEFEATURESREQUEST_REQUESTCONTEXTENTRY']._serialized_end=1168 + _globals['_GETONLINEFEATURESRESPONSE']._serialized_start=1179 + _globals['_GETONLINEFEATURESRESPONSE']._serialized_end=1517 + _globals['_GETONLINEFEATURESRESPONSE_FEATUREVECTOR']._serialized_start=1366 + _globals['_GETONLINEFEATURESRESPONSE_FEATUREVECTOR']._serialized_end=1517 + _globals['_FEATUREVIEWMETADATA']._serialized_start=1519 + _globals['_FEATUREVIEWMETADATA']._serialized_end=1571 + _globals['_GETONLINEFEATURESRESPONSEMETADATA']._serialized_start=1574 + _globals['_GETONLINEFEATURESRESPONSEMETADATA']._serialized_end=1727 + _globals['_SERVINGSERVICE']._serialized_start=1823 + _globals['_SERVINGSERVICE']._serialized_end=2053 # @@protoc_insertion_point(module_scope) diff --git a/sdk/python/feast/protos/feast/serving/ServingService_pb2.pyi b/sdk/python/feast/protos/feast/serving/ServingService_pb2.pyi index 3c5e57ae45a..1804ce0428e 100644 --- a/sdk/python/feast/protos/feast/serving/ServingService_pb2.pyi +++ b/sdk/python/feast/protos/feast/serving/ServingService_pb2.pyi @@ -253,6 +253,7 @@ class GetOnlineFeaturesRequest(google.protobuf.message.Message): ENTITIES_FIELD_NUMBER: builtins.int FULL_FEATURE_NAMES_FIELD_NUMBER: builtins.int REQUEST_CONTEXT_FIELD_NUMBER: builtins.int + INCLUDE_FEATURE_VIEW_VERSION_METADATA_FIELD_NUMBER: builtins.int feature_service: builtins.str @property def features(self) -> global___FeatureList: ... @@ -268,6 +269,8 @@ class GetOnlineFeaturesRequest(google.protobuf.message.Message): (was moved to dedicated parameter to avoid unnecessary separation logic on serving side) A map of variable name -> list of values """ + include_feature_view_version_metadata: builtins.bool + """Whether to include feature view version metadata in the response""" def __init__( self, *, @@ -276,9 +279,10 @@ class GetOnlineFeaturesRequest(google.protobuf.message.Message): entities: collections.abc.Mapping[builtins.str, feast.types.Value_pb2.RepeatedValue] | None = ..., full_feature_names: builtins.bool = ..., request_context: collections.abc.Mapping[builtins.str, feast.types.Value_pb2.RepeatedValue] | None = ..., + include_feature_view_version_metadata: builtins.bool = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["feature_service", b"feature_service", "features", b"features", "kind", b"kind"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["entities", b"entities", "feature_service", b"feature_service", "features", b"features", "full_feature_names", b"full_feature_names", "kind", b"kind", "request_context", b"request_context"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["entities", b"entities", "feature_service", b"feature_service", "features", b"features", "full_feature_names", b"full_feature_names", "include_feature_view_version_metadata", b"include_feature_view_version_metadata", "kind", b"kind", "request_context", b"request_context"]) -> None: ... def WhichOneof(self, oneof_group: typing_extensions.Literal["kind", b"kind"]) -> typing_extensions.Literal["feature_service", "features"] | None: ... global___GetOnlineFeaturesRequest = GetOnlineFeaturesRequest @@ -330,18 +334,43 @@ class GetOnlineFeaturesResponse(google.protobuf.message.Message): global___GetOnlineFeaturesResponse = GetOnlineFeaturesResponse +class FeatureViewMetadata(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + NAME_FIELD_NUMBER: builtins.int + VERSION_FIELD_NUMBER: builtins.int + name: builtins.str + """Feature view name (e.g., "driver_stats")""" + version: builtins.int + """Version number (e.g., 2)""" + def __init__( + self, + *, + name: builtins.str = ..., + version: builtins.int = ..., + ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["name", b"name", "version", b"version"]) -> None: ... + +global___FeatureViewMetadata = FeatureViewMetadata + class GetOnlineFeaturesResponseMetadata(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor FEATURE_NAMES_FIELD_NUMBER: builtins.int + FEATURE_VIEW_METADATA_FIELD_NUMBER: builtins.int + @property + def feature_names(self) -> global___FeatureList: + """Clean feature names without @v2 syntax""" @property - def feature_names(self) -> global___FeatureList: ... + def feature_view_metadata(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___FeatureViewMetadata]: + """Only populated when requested""" def __init__( self, *, feature_names: global___FeatureList | None = ..., + feature_view_metadata: collections.abc.Iterable[global___FeatureViewMetadata] | None = ..., ) -> None: ... def HasField(self, field_name: typing_extensions.Literal["feature_names", b"feature_names"]) -> builtins.bool: ... - def ClearField(self, field_name: typing_extensions.Literal["feature_names", b"feature_names"]) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["feature_names", b"feature_names", "feature_view_metadata", b"feature_view_metadata"]) -> None: ... global___GetOnlineFeaturesResponseMetadata = GetOnlineFeaturesResponseMetadata diff --git a/sdk/python/feast/repo_config.py b/sdk/python/feast/repo_config.py index 02a0f13c733..93fb2070cfd 100644 --- a/sdk/python/feast/repo_config.py +++ b/sdk/python/feast/repo_config.py @@ -167,6 +167,12 @@ class RegistryConfig(FeastBaseModel): Once this is set to True, it cannot be reverted back to False. Reverting back to False will only reset the project but not all the projects""" + enable_online_feature_view_versioning: StrictBool = False + """ bool: Enable versioned online store tables and version-qualified reads + (e.g., 'fv@v2:feature'). When True, each schema version gets its own + online store table and can be queried independently. Version history + tracking in the registry is always active regardless of this setting. """ + @field_validator("path") def validate_path(cls, path: str, values: ValidationInfo) -> str: if values.data.get("registry_type") == "sql": diff --git a/sdk/python/feast/repo_operations.py b/sdk/python/feast/repo_operations.py index 1a6de75b2e4..68e8be2cb3e 100644 --- a/sdk/python/feast/repo_operations.py +++ b/sdk/python/feast/repo_operations.py @@ -347,6 +347,7 @@ def apply_total_with_repo_instance( repo: RepoContents, skip_source_validation: bool, skip_feature_view_validation: bool = False, + no_promote: bool = False, ): if not skip_source_validation: provider = store._get_provider() @@ -384,7 +385,11 @@ def apply_total_with_repo_instance( # Apply phase store._apply_diffs( - registry_diff, infra_diff, new_infra, progress_ctx=progress_ctx + registry_diff, + infra_diff, + new_infra, + progress_ctx=progress_ctx, + no_promote=no_promote, ) click.echo(infra_diff.to_string()) else: @@ -394,6 +399,7 @@ def apply_total_with_repo_instance( objects_to_delete=all_to_delete, partial=False, skip_feature_view_validation=skip_feature_view_validation, + no_promote=no_promote, ) log_infra_changes(views_to_keep, views_to_delete) finally: @@ -441,6 +447,7 @@ def apply_total( repo_path: Path, skip_source_validation: bool, skip_feature_view_validation: bool = False, + no_promote: bool = False, ): os.chdir(repo_path) repo = _get_repo_contents(repo_path, repo_config.project, repo_config) @@ -462,6 +469,7 @@ def apply_total( repo, skip_source_validation, skip_feature_view_validation, + no_promote=no_promote, ) diff --git a/sdk/python/feast/stream_feature_view.py b/sdk/python/feast/stream_feature_view.py index b8f410f9a48..2773484ecbb 100644 --- a/sdk/python/feast/stream_feature_view.py +++ b/sdk/python/feast/stream_feature_view.py @@ -12,6 +12,7 @@ from feast import flags_helper, utils from feast.aggregation import Aggregation +from feast.base_feature_view import BaseFeatureView from feast.data_source import DataSource from feast.entity import Entity from feast.feature_view import FeatureView @@ -122,6 +123,7 @@ def __init__( enable_tiling: bool = False, tiling_hop_size: Optional[timedelta] = None, enable_validation: bool = False, + version: str = "latest", ): if not flags_helper.is_test(): warnings.warn( @@ -186,6 +188,7 @@ def __init__( mode=mode, sink_source=sink_source, enable_validation=enable_validation, + version=version, ) def get_feature_transformation(self) -> Optional[Transformation]: @@ -206,6 +209,35 @@ def get_feature_transformation(self) -> Optional[Transformation]: f"Unsupported transformation mode: {self.mode} for StreamFeatureView" ) + def _schema_or_udf_changed(self, other: "BaseFeatureView") -> bool: + """Check for StreamFeatureView schema/UDF changes.""" + if super()._schema_or_udf_changed(other): + return True + + if not isinstance(other, StreamFeatureView): + return True + + # UDF changes + if self.udf and other.udf: + self_code = getattr(self.udf, "__code__", None) + other_code = getattr(other.udf, "__code__", None) + if self_code and other_code: + if self_code.co_code != other_code.co_code: + return True + elif self.udf != other.udf: # One is None + return True + + if self.udf_string != other.udf_string: + return True + if self.aggregations != other.aggregations: + return True + if self.timestamp_field != other.timestamp_field: + return True + if self.mode != other.mode: + return True + + return False + def __eq__(self, other): if not isinstance(other, StreamFeatureView): raise TypeError("Comparisons should only involve StreamFeatureViews") @@ -282,6 +314,7 @@ def to_proto(self): enable_tiling=self.enable_tiling, tiling_hop_size=tiling_hop_size_duration, enable_validation=self.enable_validation, + version=self.version, ) return StreamFeatureViewProto(spec=spec, meta=meta) @@ -344,6 +377,7 @@ def from_proto(cls, sfv_proto): else None ), enable_validation=sfv_proto.spec.enable_validation, + version=sfv_proto.spec.version or "latest", ) if batch_source: @@ -352,6 +386,16 @@ def from_proto(cls, sfv_proto): if stream_source: stream_feature_view.stream_source = stream_source + # Restore current_version_number from meta. + spec_version = sfv_proto.spec.version + cvn = sfv_proto.meta.current_version_number + if cvn > 0: + stream_feature_view.current_version_number = cvn + elif cvn == 0 and spec_version and spec_version.lower() != "latest": + stream_feature_view.current_version_number = 0 + else: + stream_feature_view.current_version_number = None + stream_feature_view.entities = list(sfv_proto.spec.entities) stream_feature_view.features = [ @@ -398,6 +442,7 @@ def __copy__(self): udf_string=self.udf_string, feature_transformation=self.feature_transformation, enable_validation=self.enable_validation, + version=self.version, ) fv.entities = self.entities fv.features = copy.copy(self.features) @@ -424,6 +469,7 @@ def stream_feature_view( mode: Optional[str] = "spark", timestamp_field: Optional[str] = "", enable_validation: bool = False, + version: str = "latest", ): """ Creates an StreamFeatureView object with the given user function as udf. @@ -456,6 +502,7 @@ def decorator(user_function): mode=mode, timestamp_field=timestamp_field, enable_validation=enable_validation, + version=version, ) functools.update_wrapper(wrapper=stream_feature_view_obj, wrapped=user_function) return stream_feature_view_obj diff --git a/sdk/python/feast/templates/athena/feature_repo/test_workflow.py b/sdk/python/feast/templates/athena/feature_repo/test_workflow.py index 8d6479da80e..8bbdb07f161 100644 --- a/sdk/python/feast/templates/athena/feature_repo/test_workflow.py +++ b/sdk/python/feast/templates/athena/feature_repo/test_workflow.py @@ -50,6 +50,7 @@ def test_end_to_end(): ], online=True, source=driver_hourly_stats, + version="latest", ) # apply repository diff --git a/sdk/python/feast/templates/aws/feature_repo/feature_definitions.py b/sdk/python/feast/templates/aws/feature_repo/feature_definitions.py index dd5a9c925b7..8d4faf4c74c 100644 --- a/sdk/python/feast/templates/aws/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/aws/feature_repo/feature_definitions.py @@ -57,6 +57,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -119,6 +120,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/cassandra/feature_repo/feature_definitions.py b/sdk/python/feast/templates/cassandra/feature_repo/feature_definitions.py index 131f1bcaa61..21b2985409e 100644 --- a/sdk/python/feast/templates/cassandra/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/cassandra/feature_repo/feature_definitions.py @@ -52,6 +52,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -114,6 +115,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/couchbase/feature_repo/feature_definitions.py b/sdk/python/feast/templates/couchbase/feature_repo/feature_definitions.py index 363ba3c4664..802f251ca5a 100644 --- a/sdk/python/feast/templates/couchbase/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/couchbase/feature_repo/feature_definitions.py @@ -47,6 +47,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -109,6 +110,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/gcp/feature_repo/feature_definitions.py b/sdk/python/feast/templates/gcp/feature_repo/feature_definitions.py index 81e06c72018..5eda02ea5d2 100644 --- a/sdk/python/feast/templates/gcp/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/gcp/feature_repo/feature_definitions.py @@ -61,6 +61,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -123,6 +124,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/hazelcast/feature_repo/feature_definitions.py b/sdk/python/feast/templates/hazelcast/feature_repo/feature_definitions.py index 131f1bcaa61..21b2985409e 100644 --- a/sdk/python/feast/templates/hazelcast/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/hazelcast/feature_repo/feature_definitions.py @@ -52,6 +52,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -114,6 +115,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/hbase/feature_repo/feature_definitions.py b/sdk/python/feast/templates/hbase/feature_repo/feature_definitions.py index 131f1bcaa61..21b2985409e 100644 --- a/sdk/python/feast/templates/hbase/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/hbase/feature_repo/feature_definitions.py @@ -52,6 +52,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -114,6 +115,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/local/feature_repo/feature_definitions.py b/sdk/python/feast/templates/local/feature_repo/feature_definitions.py index 6fe94a5fa59..74199b42072 100644 --- a/sdk/python/feast/templates/local/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/local/feature_repo/feature_definitions.py @@ -72,6 +72,7 @@ # feature view tags={"team": "driver_performance"}, enable_validation=True, + version="latest", ) # Define a request data source which encodes features / information only @@ -140,6 +141,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/milvus/feature_repo/feature_definitions.py b/sdk/python/feast/templates/milvus/feature_repo/feature_definitions.py index e2fd0a891cf..31f3af3c26d 100644 --- a/sdk/python/feast/templates/milvus/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/milvus/feature_repo/feature_definitions.py @@ -58,6 +58,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -123,6 +124,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/postgres/feature_repo/feature_definitions.py b/sdk/python/feast/templates/postgres/feature_repo/feature_definitions.py index 0d1783e1e5e..073f18e43f5 100644 --- a/sdk/python/feast/templates/postgres/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/postgres/feature_repo/feature_definitions.py @@ -44,6 +44,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -106,6 +107,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/pytorch_nlp/feature_repo/example_repo.py b/sdk/python/feast/templates/pytorch_nlp/feature_repo/example_repo.py index ee49bea2899..80d1b9aa7bd 100644 --- a/sdk/python/feast/templates/pytorch_nlp/feature_repo/example_repo.py +++ b/sdk/python/feast/templates/pytorch_nlp/feature_repo/example_repo.py @@ -96,6 +96,7 @@ online=True, source=sentiment_source, tags={"team": "nlp", "domain": "sentiment_analysis"}, + version="latest", ) # Feature view for user-level aggregations @@ -123,6 +124,7 @@ online=True, source=sentiment_source, tags={"team": "nlp", "domain": "user_behavior"}, + version="latest", ) # Request source for real-time inference diff --git a/sdk/python/feast/templates/ray/feature_repo/feature_definitions.py b/sdk/python/feast/templates/ray/feature_repo/feature_definitions.py index 0b2df66de34..046ecb03ac7 100644 --- a/sdk/python/feast/templates/ray/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/ray/feature_repo/feature_definitions.py @@ -59,6 +59,7 @@ online=True, source=driver_hourly_stats, tags={"team": "driver_performance", "processing": "ray"}, + version="latest", ) customer_daily_profile_view = FeatureView( @@ -73,6 +74,7 @@ online=True, source=customer_daily_profile, tags={"team": "customer_analytics", "processing": "ray"}, + version="latest", ) diff --git a/sdk/python/feast/templates/snowflake/feature_repo/driver_repo.py b/sdk/python/feast/templates/snowflake/feature_repo/driver_repo.py index dd05dac8455..7526d096ef5 100644 --- a/sdk/python/feast/templates/snowflake/feature_repo/driver_repo.py +++ b/sdk/python/feast/templates/snowflake/feature_repo/driver_repo.py @@ -64,6 +64,7 @@ # Tags are user defined key/value pairs that are attached to each # feature view tags={"team": "driver_performance"}, + version="latest", ) # Define a request data source which encodes features / information only @@ -126,6 +127,7 @@ def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: online=True, source=driver_stats_push_source, # Changed from above tags={"team": "driver_performance"}, + version="latest", ) diff --git a/sdk/python/feast/templates/spark/feature_repo/feature_definitions.py b/sdk/python/feast/templates/spark/feature_repo/feature_definitions.py index 8ad48f53fc4..e89d9b0fc1e 100644 --- a/sdk/python/feast/templates/spark/feature_repo/feature_definitions.py +++ b/sdk/python/feast/templates/spark/feature_repo/feature_definitions.py @@ -54,6 +54,7 @@ online=True, source=driver_hourly_stats, tags={}, + version="latest", ) customer_daily_profile_view = FeatureView( name="customer_daily_profile", @@ -67,6 +68,7 @@ online=True, source=customer_daily_profile, tags={}, + version="latest", ) driver_stats_fs = FeatureService( diff --git a/sdk/python/feast/utils.py b/sdk/python/feast/utils.py index 898cda45967..ce45bb0862e 100644 --- a/sdk/python/feast/utils.py +++ b/sdk/python/feast/utils.py @@ -60,6 +60,55 @@ USER_AGENT = "{}/{}".format(APPLICATION_NAME, get_version()) +def _parse_feature_ref(ref: str) -> Tuple[str, Optional[int], str]: + """Parse 'fv_name@version:feature' into (fv_name, version_number, feature_name). + + If no @version is present, version_number is None (meaning 'latest'). + Examples: + 'driver_stats:trips' -> ('driver_stats', None, 'trips') + 'driver_stats@v2:trips' -> ('driver_stats', 2, 'trips') + 'driver_stats@latest:trips' -> ('driver_stats', None, 'trips') + """ + import re + + colon_idx = ref.find(":") + if colon_idx < 0: + raise ValueError( + f"Invalid feature reference '{ref}'. Expected format: ':' " + f"or '@:'" + ) + + fv_part = ref[:colon_idx] + feature_name = ref[colon_idx + 1 :] + + at_idx = fv_part.find("@") + if at_idx < 0: + return (fv_part, None, feature_name) + + fv_name = fv_part[:at_idx] + version_str = fv_part[at_idx + 1 :] + + if not version_str or version_str.lower() == "latest": + return (fv_name, None, feature_name) + + # Parse version number from formats like "v2", "V2" + match = re.match(r"^[vV](\d+)$", version_str) + if not match: + # Not a recognized version format — treat entire fv_part as the name + return (fv_part, None, feature_name) + + return (fv_name, int(match.group(1)), feature_name) + + +def _strip_version_from_ref(ref: str) -> str: + """Strip @version from a feature reference, returning 'fv_name:feature'. + + Used to produce clean refs for output column naming. + """ + fv_name, _, feature_name = _parse_feature_ref(ref) + return f"{fv_name}:{feature_name}" + + def get_user_agent(): return USER_AGENT @@ -150,9 +199,12 @@ def _get_requested_feature_views_to_features_dict( ) for ref in feature_refs: - ref_parts = ref.split(":") - feature_view_from_ref = ref_parts[0] - feature_from_ref = ref_parts[1] + fv_name, version_num, feature_from_ref = _parse_feature_ref(ref) + # Build the key that matches projection.name_to_use() + if version_num is not None: + feature_view_from_ref = f"{fv_name}@v{version_num}" + else: + feature_view_from_ref = fv_name found = False for fv in feature_views: @@ -525,7 +577,7 @@ def _validate_feature_refs(feature_refs: List[str], full_feature_names: bool = F ref for ref, occurrences in Counter(feature_refs).items() if occurrences > 1 ] else: - feature_names = [ref.split(":")[1] for ref in feature_refs] + feature_names = [_parse_feature_ref(ref)[2] for ref in feature_refs] collided_feature_names = [ ref for ref, occurrences in Counter(feature_names).items() @@ -572,7 +624,12 @@ def _group_feature_refs( on_demand_view_features = defaultdict(set) for ref in features: - view_name, feat_name = ref.split(":") + fv_name, version_num, feat_name = _parse_feature_ref(ref) + # Build the key that matches projection.name_to_use() + if version_num is not None: + view_name = f"{fv_name}@v{version_num}" + else: + view_name = fv_name if view_name in view_index: if hasattr(view_index[view_name], "write_to_online_store"): tmp_feat_name = [ @@ -716,7 +773,7 @@ def _augment_response_with_on_demand_transforms( odfv_feature_refs = defaultdict(list) for feature_ref in feature_refs: - view_name, feature_name = feature_ref.split(":") + view_name, _, feature_name = _parse_feature_ref(feature_ref) if view_name in requested_odfv_feature_names: odfv_feature_refs[view_name].append( f"{requested_odfv_map[view_name].projection.name_to_use()}__{feature_name}" @@ -1085,6 +1142,7 @@ def _populate_response_from_feature_data( requested_features: Iterable[str], table: "FeatureView", output_len: int, + include_feature_view_version_metadata: bool = False, ): """Populate the GetOnlineFeaturesResponse with feature data. @@ -1106,13 +1164,29 @@ def _populate_response_from_feature_data( output_len: The number of result rows in `online_features_response`. """ # Add the feature names to the response. + # Use name_to_use() which includes version tag (e.g. "fv@v2") when a + # version-qualified ref was used, so multi-version queries produce + # distinct column names like "fv@v1__feat" and "fv@v2__feat". table_name = table.projection.name_to_use() + clean_table_name = table.projection.name_alias or table.projection.name requested_feature_refs = [ f"{table_name}__{feature_name}" if full_feature_names else feature_name for feature_name in requested_features ] online_features_response.metadata.feature_names.val.extend(requested_feature_refs) + # Add version metadata if requested + if include_feature_view_version_metadata: + # Check if this feature view already exists in metadata to avoid duplicates + existing_names = [ + fvm.name for fvm in online_features_response.metadata.feature_view_metadata + ] + if clean_table_name not in existing_names: + fv_metadata = online_features_response.metadata.feature_view_metadata.add() + fv_metadata.name = clean_table_name + # Extract version from the table's current_version_number attribute + fv_metadata.version = getattr(table, "current_version_number", 0) or 0 + # Process each feature vector in a single pass for timestamp_vector, statuses_vector, values_vector in feature_data: response_vector = construct_response_feature_vector( @@ -1261,16 +1335,47 @@ def _get_feature_views_to_use( if isinstance(features, FeatureService): feature_views = [ - (projection.name, projection) + (projection.name, None, projection) for projection in features.feature_view_projections ] else: assert features is not None - feature_views = [(feature.split(":")[0], None) for feature in features] # type: ignore[misc] + # Parse version-qualified refs: 'fv@v2:feat' -> ('fv', 2, None) + parsed = [] + seen = set() + for feature in features: + fv_name, version_num, _ = _parse_feature_ref(feature) + key = (fv_name, version_num) + if key not in seen: + seen.add(key) + parsed.append((fv_name, version_num, None)) + feature_views = parsed # type: ignore[assignment] fvs_to_use, od_fvs_to_use = [], [] - for name, projection in feature_views: - fv = registry.get_any_feature_view(name, project, allow_cache) + for name, version_num, projection in feature_views: + if version_num is not None: + if not getattr(registry, "enable_online_versioning", False): + raise ValueError( + f"Version-qualified ref '{name}@v{version_num}' not supported: " + f"online versioning is disabled. Set 'enable_online_feature_view_versioning: true' " + f"under 'registry' in feature_store.yaml." + ) + # Version-qualified reference: look up the specific version snapshot + try: + fv = registry.get_feature_view_by_version( + name, project, version_num, allow_cache + ) + except NotImplementedError: + # Fall back for v0 on registries that don't implement versioned lookup + if version_num == 0: + fv = registry.get_any_feature_view(name, project, allow_cache) + else: + raise + # Set version_tag on the projection so name_to_use() returns versioned key + if hasattr(fv, "projection") and fv.projection is not None: + fv.projection.version_tag = version_num + else: + fv = registry.get_any_feature_view(name, project, allow_cache) if isinstance(fv, OnDemandFeatureView): od_fvs_to_use.append( @@ -1302,9 +1407,11 @@ def _get_feature_views_to_use( ): fv.entities = [] # type: ignore[attr-defined] fv.entity_columns = [] # type: ignore[attr-defined] - fvs_to_use.append( - fv.with_projection(copy.copy(projection)) if projection else fv - ) + if projection: + fv = fv.with_projection(copy.copy(projection)) + if version_num is not None: + fv.projection.version_tag = version_num + fvs_to_use.append(fv) return (fvs_to_use, od_fvs_to_use) @@ -1346,13 +1453,20 @@ def _get_online_request_context( requested_on_demand_feature_views, ) - requested_result_row_names = { - feat_ref.replace(":", "__") for feat_ref in _feature_refs - } - if not full_feature_names: - requested_result_row_names = { - name.rpartition("__")[-1] for name in requested_result_row_names - } + # Build expected result names, including version tag when present so + # multi-version queries (e.g. fv@v1:feat, fv@v2:feat) match the response. + requested_result_row_names = set() + for feat_ref in _feature_refs: + fv_name, version_num, feature_name = _parse_feature_ref(feat_ref) + if full_feature_names: + if version_num is not None: + requested_result_row_names.add( + f"{fv_name}@v{version_num}__{feature_name}" + ) + else: + requested_result_row_names.add(f"{fv_name}__{feature_name}") + else: + requested_result_row_names.add(feature_name) feature_views = list(view for view, _ in grouped_refs) diff --git a/sdk/python/feast/version_utils.py b/sdk/python/feast/version_utils.py new file mode 100644 index 00000000000..5811e89e936 --- /dev/null +++ b/sdk/python/feast/version_utils.py @@ -0,0 +1,51 @@ +import re +import uuid +from typing import Tuple + +LATEST_VERSION = "latest" +_VERSION_PATTERN = re.compile(r"^v(?:ersion)?(\d+)$", re.IGNORECASE) + + +def parse_version(version: str) -> Tuple[bool, int]: + """Parse a version string into (is_latest, version_number). + + Accepts "latest", "vN", or "versionN" (case-insensitive). + Returns (True, 0) for "latest", (False, N) for pinned versions. + + Raises: + ValueError: If the version string is invalid. + """ + if not version or version.lower() == LATEST_VERSION: + return True, 0 + + match = _VERSION_PATTERN.match(version) + if not match: + raise ValueError( + f"Invalid version string '{version}'. " + f"Expected 'latest', 'vN', or 'versionN' (e.g. 'v2', 'version3')." + ) + return False, int(match.group(1)) + + +def normalize_version_string(version: str) -> str: + """Normalize a version string for comparison. + + Empty string and "latest" both normalize to "latest". + "v2" and "version2" both normalize to "v2". + """ + if not version or version.lower() == LATEST_VERSION: + return LATEST_VERSION + is_latest, num = parse_version(version) + if is_latest: + return LATEST_VERSION + return version_tag(num) + + +def version_tag(n: int) -> str: + """Convert an integer version number to the canonical short form 'vN'.""" + return f"v{n}" + + +def generate_version_id() -> str: + """Generate a UUID for a version record.""" + return str(uuid.uuid4()) diff --git a/sdk/python/tests/foo_provider.py b/sdk/python/tests/foo_provider.py index a04ff3cc456..82cfc7fb513 100644 --- a/sdk/python/tests/foo_provider.py +++ b/sdk/python/tests/foo_provider.py @@ -155,6 +155,7 @@ def retrieve_online_documents( query: List[float], top_k: int, distance_metric: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], @@ -174,6 +175,7 @@ def retrieve_online_documents_v2( top_k: int, distance_metric: Optional[str] = None, query_string: Optional[str] = None, + include_feature_view_version_metadata: bool = False, ) -> List[ Tuple[ Optional[datetime], @@ -206,6 +208,7 @@ def get_online_features( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: pass @@ -220,6 +223,7 @@ async def get_online_features_async( registry: BaseRegistry, project: str, full_feature_names: bool = False, + include_feature_view_version_metadata: bool = False, ) -> OnlineResponse: pass diff --git a/sdk/python/tests/integration/registration/test_versioning.py b/sdk/python/tests/integration/registration/test_versioning.py new file mode 100644 index 00000000000..32143f9dccc --- /dev/null +++ b/sdk/python/tests/integration/registration/test_versioning.py @@ -0,0 +1,1418 @@ +"""Integration tests for feature view versioning.""" + +import os +import tempfile +from datetime import timedelta +from pathlib import Path + +import pytest + +from feast import FeatureStore +from feast.entity import Entity +from feast.errors import FeatureViewPinConflict, FeatureViewVersionNotFound +from feast.feature_service import FeatureService +from feast.feature_view import FeatureView +from feast.field import Field +from feast.infra.online_stores.sqlite import SqliteOnlineStoreConfig +from feast.infra.registry.registry import Registry +from feast.repo_config import RegistryConfig, RepoConfig +from feast.stream_feature_view import StreamFeatureView +from feast.types import Float32, Int64 +from feast.value_type import ValueType + + +@pytest.fixture +def registry(): + """Create a file-based Registry for testing. Version history is always-on.""" + with tempfile.TemporaryDirectory() as tmpdir: + registry_path = Path(tmpdir) / "registry.pb" + config = RegistryConfig(path=str(registry_path)) + reg = Registry("test_project", config, None) + yield reg + + +@pytest.fixture +def registry_no_online_versioning(): + """Create a file-based Registry without online versioning (default).""" + with tempfile.TemporaryDirectory() as tmpdir: + registry_path = Path(tmpdir) / "registry.pb" + config = RegistryConfig(path=str(registry_path)) + reg = Registry("test_project", config, None) + yield reg + + +@pytest.fixture +def entity(): + return Entity( + name="driver_id", + join_keys=["driver_id"], + value_type=ValueType.INT64, + ) + + +@pytest.fixture +def make_fv(entity): + def _make(description="test feature view", version="latest", **kwargs): + return FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + ], + description=description, + version=version, + **kwargs, + ) + + return _make + + +@pytest.fixture +def make_sfv(entity): + def _make(description="test stream feature view", udf=None, **kwargs): + from feast.data_source import PushSource + from feast.infra.offline_stores.file_source import FileSource + + def default_udf(df): + return df + + # Create batch source + batch_source = FileSource(name="test_batch_source", path="test.parquet") + + # Create a simple push source for testing + source = PushSource(name="test_push_source", batch_source=batch_source) + + return StreamFeatureView( + name="driver_stats_stream", + entities=[entity], + ttl=timedelta(hours=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + description=description, + udf=udf or default_udf, + source=source, + **kwargs, + ) + + return _make + + +# OnDemandFeatureView tests removed due to transformation comparison issues + + +class TestFileRegistryVersioning: + def test_first_apply_creates_v0(self, registry, make_fv): + fv = make_fv() + registry.apply_feature_view(fv, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 + assert versions[0]["version"] == "v0" + assert versions[0]["version_number"] == 0 + + def test_modify_and_reapply_creates_new_version(self, registry, make_fv, entity): + fv1 = make_fv(description="version one") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create a schema change by adding a new feature + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_feature", dtype=Float32), # Schema change + ], + description="version two", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 2 + assert versions[0]["version"] == "v0" + assert versions[1]["version"] == "v1" + + def test_idempotent_apply_no_new_version(self, registry, make_fv): + fv = make_fv(description="same definition") + registry.apply_feature_view(fv, "test_project", commit=True) + + # Apply identical FV again + fv_same = make_fv(description="same definition") + registry.apply_feature_view(fv_same, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 # No new version created + + def test_pin_to_v0(self, registry, make_fv, entity): + # Create v0 + fv1 = make_fv(description="original") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), # Schema change + ], + description="updated", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Pin to v0 (definition must match active FV, only version changes) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), # Keep current schema + ], + description="updated", + version="v0", + ) + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + # Verify active entry has v0's content + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.description == "original" + assert active_fv.version == "v0" + + def test_explicit_version_creates_when_not_exists(self, registry, make_fv): + """Explicit version on a new FV creates that version (forward declaration).""" + fv = make_fv(description="forward declared v1", version="v1") + registry.apply_feature_view(fv, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 + assert versions[0]["version_number"] == 1 + + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.current_version_number == 1 + + def test_explicit_version_reverts_when_exists(self, registry, make_fv, entity): + """Explicit version on an existing FV reverts to that snapshot (pin/revert).""" + # Create v0 + fv1 = make_fv(description="original") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), + ], + description="updated", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Pin to v0 (definition must match active FV, only version changes) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), + ], + description="updated", + version="v0", + ) + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.description == "original" + assert active_fv.version == "v0" + + def test_forward_declare_nonexistent_version(self, registry, make_fv): + """Forward-declaring a version that doesn't exist creates it.""" + fv = make_fv() + registry.apply_feature_view(fv, "test_project", commit=True) + + # Forward-declare v5 — should create it, not raise + fv_v5 = make_fv(description="forward declared v5", version="v5") + registry.apply_feature_view(fv_v5, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + version_numbers = [v["version_number"] for v in versions] + assert 5 in version_numbers + + # The active FV should now be the forward-declared v5 + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.current_version_number == 5 + assert active_fv.description == "forward declared v5" + + def test_apply_after_pin_creates_new_version(self, registry, make_fv, entity): + # Create v0 + fv1 = make_fv(description="v0 desc") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="v1_field", dtype=Float32), # Schema change + ], + description="v1 desc", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Pin to v0 (definition must match active FV, only version changes) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="v1_field", dtype=Float32), # Keep current schema + ], + description="v1 desc", + version="v0", + ) + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + # Apply new content with another schema change (should create new version) + fv3 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="v1_field", dtype=Float32), + Field(name="v2_field", dtype=Float32), # Another schema change + ], + description="v2 desc after pin", + ) + registry.apply_feature_view(fv3, "test_project", commit=True) + + versions = registry.list_feature_view_versions("driver_stats", "test_project") + # Should have v0, v1, and potentially more versions + assert len(versions) >= 2 + + def test_pin_with_modified_definition_raises(self, registry, make_fv, entity): + # Create v0 + fv1 = make_fv(description="original") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), # Schema change + ], + description="updated", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Attempt to pin to v0 while also changing schema (sneaky change) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), + Field(name="sneaky_field", dtype=Float32), # Sneaky schema change + ], + description="updated", + version="v0", + ) + with pytest.raises(FeatureViewPinConflict): + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + def test_pin_without_modification_succeeds(self, registry, make_fv, entity): + # Create v0 + fv1 = make_fv(description="original") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), # Schema change + ], + description="updated", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Pin to v0 with same definition as active (only version changes) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), # Keep current schema + ], + description="updated", + version="v0", + ) + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + # Verify active entry has v0's content + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.description == "original" + assert active_fv.version == "v0" + + def test_get_feature_view_by_version(self, registry, make_fv, entity): + # Create v0 + fv1 = make_fv(description="version zero") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 with schema change and different description + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="v1_field", dtype=Float32), # Schema change + ], + description="version one", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Retrieve v0 snapshot + fv_v0 = registry.get_feature_view_by_version("driver_stats", "test_project", 0) + assert fv_v0.description == "version zero" + assert fv_v0.current_version_number == 0 + + # Retrieve v1 snapshot + fv_v1 = registry.get_feature_view_by_version("driver_stats", "test_project", 1) + assert fv_v1.description == "version one" + assert fv_v1.current_version_number == 1 + + def test_get_feature_view_by_version_not_found(self, registry, make_fv): + fv = make_fv() + registry.apply_feature_view(fv, "test_project", commit=True) + + with pytest.raises(FeatureViewVersionNotFound): + registry.get_feature_view_by_version("driver_stats", "test_project", 99) + + def test_version_in_proto_roundtrip(self, registry, make_fv): + fv = make_fv(version="v3") + # Manually set version number for testing + fv.current_version_number = 3 + + proto = fv.to_proto() + assert proto.spec.version == "v3" + assert proto.meta.current_version_number == 3 + + fv2 = FeatureView.from_proto(proto) + assert fv2.version == "v3" + assert fv2.current_version_number == 3 + + +class TestRefinedVersioningBehavior: + """Test that only schema and UDF changes create new versions.""" + + def test_metadata_changes_no_new_version(self, registry, make_fv): + """Verify metadata changes don't create new versions.""" + fv = make_fv(description="original description", tags={"team": "ml"}) + registry.apply_feature_view(fv, "test_project", commit=True) + + # Modify only metadata + fv_updated = make_fv( + description="updated description", + tags={"team": "ml", "env": "prod"}, + owner="new_owner@company.com", + ) + registry.apply_feature_view(fv_updated, "test_project", commit=True) + + # Should not create new version + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 # Still just v0 + assert versions[0]["version_number"] == 0 + + def test_schema_changes_create_new_version(self, registry, make_fv, entity): + """Verify schema changes create new versions.""" + fv = make_fv() + registry.apply_feature_view(fv, "test_project", commit=True) + + # Add a new feature (schema change) + fv_with_new_feature = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_feature", dtype=Float32), # New field + ], + description="same description", # Keep same metadata + ) + registry.apply_feature_view(fv_with_new_feature, "test_project", commit=True) + + # Should create new version + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 2 # v0 and v1 + assert versions[1]["version_number"] == 1 + + def test_configuration_changes_no_new_version(self, registry, make_fv): + """Verify configuration changes don't create new versions.""" + fv = make_fv(online=True, offline=True) + registry.apply_feature_view(fv, "test_project", commit=True) + + # Change configuration fields + fv_config_updated = make_fv( + online=False, # Configuration change + offline=False, # Configuration change + description="same description", # Keep same metadata + ) + registry.apply_feature_view(fv_config_updated, "test_project", commit=True) + + # Should not create new version + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 # Still just v0 + assert versions[0]["version_number"] == 0 + + def test_entity_changes_create_new_version(self, registry, make_fv): + """Verify entity changes create new versions.""" + fv = make_fv() + registry.apply_feature_view(fv, "test_project", commit=True) + + # Create new entity and add it (schema change) + new_entity = Entity( + name="vehicle_id", + join_keys=["vehicle_id"], + value_type=ValueType.INT64, # Match the field type + ) + + fv_with_new_entity = FeatureView( + name="driver_stats", + entities=[ + Entity( + name="driver_id", + join_keys=["driver_id"], + value_type=ValueType.INT64, + ), + new_entity, + ], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="vehicle_id", dtype=Int64), # New entity field + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + ], + description="same description", + ) + registry.apply_feature_view(fv_with_new_entity, "test_project", commit=True) + + # Should create new version due to entity change + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 2 # v0 and v1 + assert versions[1]["version_number"] == 1 + + def test_stream_feature_view_udf_changes_create_new_version( + self, registry, make_sfv + ): + """Verify UDF changes create new versions (StreamFeatureView).""" + + def original_transform(df): + return df + + def updated_transform(df): + df["new_col"] = df["trips_today"] * 2 + return df + + sfv = make_sfv(udf=original_transform) + registry.apply_feature_view(sfv, "test_project", commit=True) + + sfv_updated = make_sfv( + udf=updated_transform, + description="same description", # Keep same metadata + ) + registry.apply_feature_view(sfv_updated, "test_project", commit=True) + + # Should create new version due to UDF change + versions = registry.list_feature_view_versions( + "driver_stats_stream", "test_project" + ) + assert len(versions) == 2 # v0 and v1 + + # TODO: Add tests for OnDemandFeatureView once transformation comparison issues are resolved + # The current issue is that PythonTransformation.__eq__ has strict type checking + # that prevents proper comparison between objects created at different times + + +class TestVersionMetadataIntegration: + """Integration tests for version metadata functionality in responses.""" + + def test_version_metadata_disabled_by_default(self, registry, make_fv): + """Test that version metadata is not included by default.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + # Create and register a versioned feature view + fv = make_fv(description="test version metadata") + registry.apply_feature_view(fv, "test_project", commit=True) + + # Get the feature view with version info + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert hasattr(active_fv, "current_version_number") + + # Mock response generation without version metadata + response = GetOnlineFeaturesResponse() + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=True, + requested_features=["trips_today"], + table=active_fv, + output_len=0, + include_feature_view_version_metadata=False, # Default behavior + ) + + # Verify no version metadata is included + assert len(response.metadata.feature_view_metadata) == 0 + # Feature names should still be populated + assert len(response.metadata.feature_names.val) == 1 + + def test_version_metadata_included_when_requested(self, registry, make_fv, entity): + """Test that version metadata is included when requested.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + # Create v0 + fv1 = make_fv(description="first version") + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create v1 by modifying schema + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="total_earnings", dtype=Float32), # New field + ], + description="second version", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Get v1 (latest version) + active_fv = registry.get_feature_view("driver_stats", "test_project") + assert active_fv.current_version_number == 1 + + # Mock response generation with version metadata + response = GetOnlineFeaturesResponse() + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=False, # Test without prefixes + requested_features=["trips_today", "total_earnings"], + table=active_fv, + output_len=0, + include_feature_view_version_metadata=True, # Enable metadata + ) + + # Verify version metadata is included + assert len(response.metadata.feature_view_metadata) == 1 + fv_metadata = response.metadata.feature_view_metadata[0] + assert fv_metadata.name == "driver_stats" + assert fv_metadata.version == 1 + + # Verify feature names are clean (no @v1 suffix) + feature_names = list(response.metadata.feature_names.val) + assert feature_names == ["trips_today", "total_earnings"] + assert all("@" not in name for name in feature_names) + + def test_version_metadata_clean_names_with_prefixes(self, registry, make_fv): + """Test that feature names are clean even with full_feature_names=True.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + # Create versioned feature view + fv = make_fv(description="test clean names") + registry.apply_feature_view(fv, "test_project", commit=True) + active_fv = registry.get_feature_view("driver_stats", "test_project") + + # Test with full feature names (prefixed) + response = GetOnlineFeaturesResponse() + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=True, # Enable prefixes + requested_features=["trips_today"], + table=active_fv, + output_len=0, + include_feature_view_version_metadata=True, + ) + + # Feature names should be prefixed but clean (no @v0) + feature_names = list(response.metadata.feature_names.val) + assert len(feature_names) == 1 + assert feature_names[0] == "driver_stats__trips_today" # Clean prefix + assert "@" not in feature_names[0] # No version in name + + # Version metadata should be separate + assert len(response.metadata.feature_view_metadata) == 1 + assert response.metadata.feature_view_metadata[0].name == "driver_stats" + assert response.metadata.feature_view_metadata[0].version == 0 + + def test_version_metadata_multiple_feature_views(self, registry, entity): + """Test version metadata with multiple feature views.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + # Create first feature view + fv1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + description="driver features", + ) + registry.apply_feature_view(fv1, "test_project", commit=True) + + # Create second feature view + fv2 = FeatureView( + name="user_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="total_bookings", dtype=Int64), + ], + description="user features", + ) + registry.apply_feature_view(fv2, "test_project", commit=True) + + # Modify user_stats to create v1 + fv2_v1 = FeatureView( + name="user_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="total_bookings", dtype=Int64), + Field(name="cancellation_rate", dtype=Float32), # New field + ], + description="user features v1", + ) + registry.apply_feature_view(fv2_v1, "test_project", commit=True) + + # Get feature views + driver_fv = registry.get_feature_view("driver_stats", "test_project") # v0 + user_fv = registry.get_feature_view("user_stats", "test_project") # v1 + + # Simulate processing multiple feature views in response + response = GetOnlineFeaturesResponse() + + # Process first feature view + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=False, + requested_features=["trips_today"], + table=driver_fv, + output_len=0, + include_feature_view_version_metadata=True, + ) + + # Process second feature view + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=False, + requested_features=["total_bookings", "cancellation_rate"], + table=user_fv, + output_len=0, + include_feature_view_version_metadata=True, + ) + + # Verify both feature views are in metadata + assert len(response.metadata.feature_view_metadata) == 2 + + fv_metadata_by_name = { + fvm.name: fvm for fvm in response.metadata.feature_view_metadata + } + assert "driver_stats" in fv_metadata_by_name + assert "user_stats" in fv_metadata_by_name + + # Check versions + assert fv_metadata_by_name["driver_stats"].version == 0 + assert fv_metadata_by_name["user_stats"].version == 1 + + # Verify feature names are clean + feature_names = list(response.metadata.feature_names.val) + assert feature_names == ["trips_today", "total_bookings", "cancellation_rate"] + assert all("@" not in name for name in feature_names) + + def test_version_metadata_prevents_duplicates(self, registry, make_fv): + """Test that duplicate feature view metadata is not added.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + fv = make_fv(description="test duplicates") + registry.apply_feature_view(fv, "test_project", commit=True) + active_fv = registry.get_feature_view("driver_stats", "test_project") + + response = GetOnlineFeaturesResponse() + + # Process same feature view twice (simulating multiple features from same view) + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=False, + requested_features=["trips_today"], + table=active_fv, + output_len=0, + include_feature_view_version_metadata=True, + ) + + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=False, + requested_features=["avg_rating"], + table=active_fv, + output_len=0, + include_feature_view_version_metadata=True, + ) + + # Should only have one metadata entry despite processing twice + assert len(response.metadata.feature_view_metadata) == 1 + assert response.metadata.feature_view_metadata[0].name == "driver_stats" + + # But should have both feature names + feature_names = list(response.metadata.feature_names.val) + assert len(feature_names) == 2 + assert "trips_today" in feature_names + assert "avg_rating" in feature_names + + def test_version_metadata_backward_compatibility(self, registry, make_fv): + """Test that existing code without version metadata still works.""" + from feast.protos.feast.serving.ServingService_pb2 import ( + GetOnlineFeaturesResponse, + ) + from feast.utils import _populate_response_from_feature_data + + fv = make_fv(description="backward compatibility test") + registry.apply_feature_view(fv, "test_project", commit=True) + active_fv = registry.get_feature_view("driver_stats", "test_project") + + # Test calling without the new parameter (should default to False) + response = GetOnlineFeaturesResponse() + _populate_response_from_feature_data( + feature_data=[], + indexes=[], + online_features_response=response, + full_feature_names=True, + requested_features=["trips_today"], + table=active_fv, + output_len=0, + # Note: include_feature_view_version_metadata parameter omitted + ) + + # Should work and not include version metadata + assert len(response.metadata.feature_view_metadata) == 0 + assert len(response.metadata.feature_names.val) == 1 + + +class TestOnlineVersioningDisabled: + """Tests that online versioning guard works for version-qualified refs.""" + + def test_version_qualified_ref_raises_when_online_versioning_disabled( + self, registry_no_online_versioning, make_fv, entity + ): + """Using @v2 refs raises ValueError when online versioning is disabled.""" + from feast.utils import _get_feature_views_to_use + + fv = make_fv(description="test fv") + registry_no_online_versioning.apply_feature_view( + fv, "test_project", commit=True + ) + + # Create v1 with schema change + fv2 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_field", dtype=Float32), + ], + description="version one", + ) + registry_no_online_versioning.apply_feature_view( + fv2, "test_project", commit=True + ) + + # Version-qualified ref should raise + with pytest.raises(ValueError, match="online versioning is disabled"): + _get_feature_views_to_use( + registry=registry_no_online_versioning, + project="test_project", + features=["driver_stats@v1:trips_today"], + allow_cache=False, + hide_dummy_entity=False, + ) + + +class TestFeatureServiceVersioningGates: + """Tests that feature services are gated when referencing versioned feature views.""" + + @pytest.fixture + def versioned_fv_and_entity(self): + """Create a versioned feature view (v1) and its entity.""" + entity = Entity( + name="driver_id", + join_keys=["driver_id"], + value_type=ValueType.INT64, + ) + # v0 definition + fv_v0 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + description="v0", + ) + # v1 definition (schema change) + fv_v1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + ], + description="v1", + ) + return entity, fv_v0, fv_v1 + + @pytest.fixture + def unversioned_fv_and_entity(self): + """Create an unversioned feature view (v0 only) and its entity.""" + entity = Entity( + name="driver_id", + join_keys=["driver_id"], + value_type=ValueType.INT64, + ) + fv = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + description="only version", + ) + return entity, fv + + def _make_store(self, tmpdir, enable_versioning=False): + """Create a FeatureStore with optional online versioning.""" + registry_path = os.path.join(tmpdir, "registry.db") + online_path = os.path.join(tmpdir, "online.db") + return FeatureStore( + config=RepoConfig( + registry=RegistryConfig( + path=registry_path, + enable_online_feature_view_versioning=enable_versioning, + ), + project="test_project", + provider="local", + online_store=SqliteOnlineStoreConfig(path=online_path), + entity_key_serialization_version=3, + ) + ) + + def test_feature_service_apply_succeeds_with_versioned_fv_when_flag_off( + self, versioned_fv_and_entity + ): + """Apply a feature service referencing a versioned FV with flag off -> succeeds.""" + entity, fv_v0, fv_v1 = versioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=False) + + # Apply v0 first, then v1 to create version history + store.apply([entity, fv_v0]) + store.apply([entity, fv_v1]) + + # Now create a feature service referencing the versioned FV + fs = FeatureService( + name="driver_service", + features=[fv_v1], + ) + store.apply([fs]) # Should not raise + + def test_feature_service_apply_succeeds_with_versioned_fv_when_flag_on( + self, versioned_fv_and_entity + ): + """Apply a feature service referencing a versioned FV with flag on -> succeeds.""" + entity, fv_v0, fv_v1 = versioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=True) + + # Apply v0 first, then v1 to create version history + store.apply([entity, fv_v0]) + store.apply([entity, fv_v1]) + + # Feature service referencing versioned FV should succeed + fs = FeatureService( + name="driver_service", + features=[fv_v1], + ) + store.apply([fs]) # Should not raise + + def test_feature_service_retrieval_succeeds_with_versioned_fv_when_flag_off( + self, versioned_fv_and_entity + ): + """get_online_features with a feature service referencing a versioned FV, flag off -> succeeds.""" + entity, fv_v0, fv_v1 = versioned_fv_and_entity + from feast.utils import _get_feature_views_to_use + + with tempfile.TemporaryDirectory() as tmpdir: + # First apply with flag on so the feature service can be registered + store_on = self._make_store(tmpdir, enable_versioning=True) + store_on.apply([entity, fv_v0]) + store_on.apply([entity, fv_v1]) + fs = FeatureService( + name="driver_service", + features=[fv_v1], + ) + store_on.apply([fs]) + + # Now create a store with the flag off to test retrieval + store_off = self._make_store(tmpdir, enable_versioning=False) + registered_fs = store_off.registry.get_feature_service( + "driver_service", "test_project" + ) + + fvs, _ = _get_feature_views_to_use( + registry=store_off.registry, + project="test_project", + features=registered_fs, + allow_cache=False, + hide_dummy_entity=False, + ) + + assert len(fvs) == 1 + + def test_feature_service_with_unversioned_fv_succeeds( + self, unversioned_fv_and_entity + ): + """Feature service with v0 FV works fine regardless of flag.""" + entity, fv = unversioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=False) + + # Apply unversioned FV and feature service + fs = FeatureService( + name="driver_service", + features=[fv], + ) + store.apply([entity, fv, fs]) # Should not raise + + def test_feature_service_serves_versioned_fv_when_flag_on( + self, versioned_fv_and_entity + ): + """With online versioning on, FeatureService projections do not carry version_tag; + the FV in the registry carries current_version_number.""" + from feast.utils import _get_feature_views_to_use + + entity, fv_v0, fv_v1 = versioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=True) + + # Apply v0 then v1 to create version history + store.apply([entity, fv_v0]) + store.apply([entity, fv_v1]) + + # Create and apply a feature service referencing the versioned FV + fs = FeatureService( + name="driver_service", + features=[fv_v1], + ) + store.apply([fs]) + + # Retrieve the registered feature service + registered_fs = store.registry.get_feature_service( + "driver_service", "test_project" + ) + + fvs, _ = _get_feature_views_to_use( + registry=store.registry, + project="test_project", + features=registered_fs, + allow_cache=False, + hide_dummy_entity=False, + ) + + assert len(fvs) == 1 + assert fvs[0].projection.version_tag is None + assert fvs[0].projection.name_to_use() == "driver_stats" + + # Verify the FV in the registry has the correct version + fv_from_registry = store.registry.get_feature_view( + "driver_stats", "test_project" + ) + assert fv_from_registry.current_version_number == 1 + + def test_feature_service_feature_refs_are_plain_when_flag_on( + self, versioned_fv_and_entity + ): + """With online versioning on, _get_features() produces plain (non-versioned) refs for FeatureService.""" + from feast.utils import _get_features + + entity, fv_v0, fv_v1 = versioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=True) + + # Apply v0 then v1 to create version history + store.apply([entity, fv_v0]) + store.apply([entity, fv_v1]) + + # Create and apply a feature service referencing the versioned FV + fs = FeatureService( + name="driver_service", + features=[fv_v1], + ) + store.apply([fs]) + + # Retrieve the registered feature service + registered_fs = store.registry.get_feature_service( + "driver_service", "test_project" + ) + + refs = _get_features( + registry=store.registry, + project="test_project", + features=registered_fs, + allow_cache=False, + ) + + # Refs should be plain (no version qualifier) + for ref in refs: + assert "@v" not in ref, f"Expected plain ref, got: {ref}" + + # Check specific ref format + assert "driver_stats:trips_today" in refs + + def test_unpin_from_versioned_to_latest(self, versioned_fv_and_entity): + """Pin a FV to v1, then apply with version='latest' (no schema change) -> unpinned.""" + entity, fv_v0, fv_v1 = versioned_fv_and_entity + + with tempfile.TemporaryDirectory() as tmpdir: + store = self._make_store(tmpdir, enable_versioning=True) + + # Apply v0 then v1 to create version history (v1 has schema change) + store.apply([entity, fv_v0]) + store.apply([entity, fv_v1]) + + # Verify it's pinned to v1 + reloaded = store.registry.get_feature_view("driver_stats", "test_project") + assert reloaded.current_version_number == 1 + + # Now re-apply the same schema with version="latest" to unpin + fv_latest = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + ], + version="latest", + description="v1", + ) + store.apply([entity, fv_latest]) + + # Reload and verify unpinned + reloaded = store.registry.get_feature_view("driver_stats", "test_project") + assert reloaded.current_version_number is None + assert reloaded.version == "latest" + + +class TestNoPromote: + """Tests for the no_promote flag on apply_feature_view.""" + + def test_no_promote_saves_version_without_updating_active( + self, registry, make_fv, entity + ): + """Apply v0, then schema change with no_promote=True. + Version record for v1 should exist, but active FV keeps v0's schema.""" + fv0 = make_fv(description="original v0") + registry.apply_feature_view(fv0, "test_project", commit=True) + + # Schema change with no_promote + fv1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="new_feature", dtype=Float32), # Schema change + ], + description="staged v1", + ) + registry.apply_feature_view(fv1, "test_project", commit=True, no_promote=True) + + # Version v1 should exist in history + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 2 + assert versions[0]["version_number"] == 0 + assert versions[1]["version_number"] == 1 + + # Active FV should still be v0 (initial apply with version="latest" + # has current_version_number=None since proto 0 maps to None for latest) + active = registry.get_feature_view("driver_stats", "test_project") + assert active.current_version_number is None + assert active.description == "original v0" + # v0 schema has 3 fields (driver_id, trips_today, avg_rating) + feature_names = {f.name for f in active.schema} + assert "new_feature" not in feature_names + + def test_no_promote_then_regular_apply_promotes(self, registry, make_fv, entity): + """Apply with no_promote, then re-apply the same schema change without + no_promote. The new version should now be promoted to active.""" + fv0 = make_fv(description="original") + registry.apply_feature_view(fv0, "test_project", commit=True) + + # Schema change with no_promote + fv1_schema = [ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="extra", dtype=Float32), + ] + fv1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=fv1_schema, + description="staged v1", + ) + registry.apply_feature_view(fv1, "test_project", commit=True, no_promote=True) + + # Now apply same schema change without no_promote + fv1_promote = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=fv1_schema, + description="promoted v1", + ) + registry.apply_feature_view( + fv1_promote, "test_project", commit=True, no_promote=False + ) + + # Active FV should now have the new schema + active = registry.get_feature_view("driver_stats", "test_project") + feature_names = {f.name for f in active.schema} + assert "extra" in feature_names + + def test_no_promote_then_explicit_pin_promotes(self, registry, make_fv, entity): + """Apply with no_promote, then pin to v1. Active should now be v1.""" + fv0 = make_fv(description="original") + registry.apply_feature_view(fv0, "test_project", commit=True) + + # Schema change with no_promote + fv1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="pinned_feature", dtype=Float32), + ], + description="staged v1", + ) + registry.apply_feature_view(fv1, "test_project", commit=True, no_promote=True) + + # Active is still v0 (initial apply with version="latest" + # has current_version_number=None since proto 0 maps to None for latest) + active = registry.get_feature_view("driver_stats", "test_project") + assert active.current_version_number is None + + # Pin to v1 (user's definition must match current active, only version changes) + fv_pin = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + ], + description="original", + version="v1", + ) + registry.apply_feature_view(fv_pin, "test_project", commit=True) + + # Active should now be v1's snapshot + active = registry.get_feature_view("driver_stats", "test_project") + assert active.current_version_number == 1 + feature_names = {f.name for f in active.schema} + assert "pinned_feature" in feature_names + + def test_no_promote_noop_without_schema_change(self, registry, make_fv): + """Apply with no_promote but no schema change — metadata-only update, + no new version should be created.""" + fv0 = make_fv(description="original") + registry.apply_feature_view(fv0, "test_project", commit=True) + + # Same schema, different description (metadata-only) + fv_same = make_fv(description="updated description only") + registry.apply_feature_view( + fv_same, "test_project", commit=True, no_promote=True + ) + + # Still only v0 + versions = registry.list_feature_view_versions("driver_stats", "test_project") + assert len(versions) == 1 + assert versions[0]["version_number"] == 0 + + def test_no_promote_version_accessible_by_explicit_ref( + self, registry, make_fv, entity + ): + """After no_promote apply, the new version should be accessible via + get_feature_view_by_version().""" + fv0 = make_fv(description="original") + registry.apply_feature_view(fv0, "test_project", commit=True) + + # Schema change with no_promote + fv1 = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + Field(name="avg_rating", dtype=Float32), + Field(name="explicit_feature", dtype=Float32), + ], + description="staged v1", + ) + registry.apply_feature_view(fv1, "test_project", commit=True, no_promote=True) + + # Should be accessible by explicit version ref + v1_fv = registry.get_feature_view_by_version("driver_stats", "test_project", 1) + assert v1_fv.current_version_number == 1 + feature_names = {f.name for f in v1_fv.schema} + assert "explicit_feature" in feature_names + + # v0 should also still be accessible + v0_fv = registry.get_feature_view_by_version("driver_stats", "test_project", 0) + assert v0_fv.current_version_number == 0 + feature_names_v0 = {f.name for f in v0_fv.schema} + assert "explicit_feature" not in feature_names_v0 + + +class TestFeatureViewNameValidation: + """Tests that feature view names with reserved characters are rejected on apply.""" + + def test_apply_feature_view_with_at_sign_raises(self, registry, entity): + """Applying a feature view with '@' in its name should raise ValueError.""" + fv = FeatureView( + name="my_weirdly_@_named_fv", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + ) + with pytest.raises(ValueError, match="must not contain '@'"): + registry.apply_feature_view(fv, "test_project", commit=True) + + def test_apply_feature_view_with_colon_raises(self, registry, entity): + """Applying a feature view with ':' in its name should raise ValueError.""" + fv = FeatureView( + name="my:weird:fv", + entities=[entity], + ttl=timedelta(days=1), + schema=[ + Field(name="driver_id", dtype=Int64), + Field(name="trips_today", dtype=Int64), + ], + ) + with pytest.raises(ValueError, match="must not contain ':'"): + registry.apply_feature_view(fv, "test_project", commit=True) diff --git a/sdk/python/tests/unit/test_feature_view_versioning.py b/sdk/python/tests/unit/test_feature_view_versioning.py new file mode 100644 index 00000000000..80c2bc808ea --- /dev/null +++ b/sdk/python/tests/unit/test_feature_view_versioning.py @@ -0,0 +1,558 @@ +import pytest + +from feast.utils import _parse_feature_ref, _strip_version_from_ref +from feast.version_utils import ( + generate_version_id, + normalize_version_string, + parse_version, + version_tag, +) + + +class TestParseVersion: + def test_latest_string(self): + is_latest, num = parse_version("latest") + assert is_latest is True + assert num == 0 + + def test_empty_string(self): + is_latest, num = parse_version("") + assert is_latest is True + assert num == 0 + + def test_latest_case_insensitive(self): + is_latest, num = parse_version("Latest") + assert is_latest is True + + def test_v_format(self): + is_latest, num = parse_version("v2") + assert is_latest is False + assert num == 2 + + def test_version_format(self): + is_latest, num = parse_version("version3") + assert is_latest is False + assert num == 3 + + def test_case_insensitive_v(self): + is_latest, num = parse_version("V5") + assert is_latest is False + assert num == 5 + + def test_case_insensitive_version(self): + is_latest, num = parse_version("Version10") + assert is_latest is False + assert num == 10 + + def test_v0(self): + is_latest, num = parse_version("v0") + assert is_latest is False + assert num == 0 + + def test_invalid_format(self): + with pytest.raises(ValueError, match="Invalid version string"): + parse_version("abc") + + def test_invalid_format_no_number(self): + with pytest.raises(ValueError, match="Invalid version string"): + parse_version("v") + + def test_invalid_format_negative(self): + with pytest.raises(ValueError, match="Invalid version string"): + parse_version("v-1") + + +class TestNormalizeVersionString: + def test_empty_to_latest(self): + assert normalize_version_string("") == "latest" + + def test_latest_unchanged(self): + assert normalize_version_string("latest") == "latest" + + def test_v2_canonical(self): + assert normalize_version_string("v2") == "v2" + + def test_version2_to_v2(self): + assert normalize_version_string("version2") == "v2" + + def test_V3_to_v3(self): + assert normalize_version_string("V3") == "v3" + + +class TestVersionTag: + def test_simple(self): + assert version_tag(0) == "v0" + assert version_tag(5) == "v5" + assert version_tag(100) == "v100" + + +class TestGenerateVersionId: + def test_is_uuid(self): + vid = generate_version_id() + assert len(vid) == 36 + assert vid.count("-") == 4 + + def test_unique(self): + v1 = generate_version_id() + v2 = generate_version_id() + assert v1 != v2 + + +class TestFeatureViewVersionField: + def test_feature_view_default_version(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + assert fv.version == "latest" + assert fv.current_version_number is None + + def test_feature_view_explicit_version(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v2", + ) + assert fv.version == "v2" + + def test_feature_view_proto_roundtrip(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v3", + ) + fv.current_version_number = 3 + + proto = fv.to_proto() + assert proto.spec.version == "v3" + assert proto.meta.current_version_number == 3 + + fv2 = FeatureView.from_proto(proto) + assert fv2.version == "v3" + assert fv2.current_version_number == 3 + + def test_feature_view_proto_roundtrip_v0(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v0", + ) + fv.current_version_number = 0 + + proto = fv.to_proto() + assert proto.spec.version == "v0" + assert proto.meta.current_version_number == 0 + + fv2 = FeatureView.from_proto(proto) + assert fv2.version == "v0" + assert fv2.current_version_number == 0 + + def test_feature_view_proto_roundtrip_latest_zero(self): + """version='latest' with current_version_number=None is preserved as + None through proto roundtrip (proto default 0 without spec.version + is treated as None for backward compatibility).""" + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + # default version="latest", current_version_number=None + ) + assert fv.current_version_number is None + + proto = fv.to_proto() + fv2 = FeatureView.from_proto(proto) + assert fv2.version == "latest" + # Proto default 0 without spec.version is treated as None + assert fv2.current_version_number is None + + def test_feature_view_equality_with_version(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv1 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v2", + ) + fv2 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="version2", + ) + # v2 and version2 should be equivalent + assert fv1 == fv2 + + def test_feature_view_inequality_different_version(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv1 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="latest", + ) + fv2 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v2", + ) + assert fv1 != fv2 + + def test_feature_view_empty_version_equals_latest(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv1 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + fv2 = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="latest", + ) + assert fv1 == fv2 + + def test_feature_view_copy_preserves_version(self): + import copy + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + version="v5", + ) + fv_copy = copy.copy(fv) + assert fv_copy.version == "v5" + + +class TestOnDemandFeatureViewVersionField: + def test_odfv_default_version(self): + from feast.data_source import RequestSource + from feast.field import Field + from feast.on_demand_feature_view import OnDemandFeatureView + from feast.types import Float32 + + request_source = RequestSource( + name="vals_to_add", + schema=[ + Field(name="val_to_add", dtype=Float32), + Field(name="val_to_add_2", dtype=Float32), + ], + ) + odfv = OnDemandFeatureView( + name="test_odfv", + sources=[request_source], + schema=[Field(name="output", dtype=Float32)], + feature_transformation=_dummy_transformation(), + mode="python", + ) + assert odfv.version == "latest" + + def test_odfv_proto_roundtrip(self): + from feast.data_source import RequestSource + from feast.field import Field + from feast.on_demand_feature_view import OnDemandFeatureView + from feast.types import Float32 + + request_source = RequestSource( + name="vals_to_add", + schema=[ + Field(name="val_to_add", dtype=Float32), + Field(name="val_to_add_2", dtype=Float32), + ], + ) + odfv = OnDemandFeatureView( + name="test_odfv", + sources=[request_source], + schema=[Field(name="output", dtype=Float32)], + feature_transformation=_dummy_transformation(), + mode="python", + version="v1", + ) + odfv.current_version_number = 1 + + proto = odfv.to_proto() + assert proto.spec.version == "v1" + assert proto.meta.current_version_number == 1 + + odfv2 = OnDemandFeatureView.from_proto(proto) + assert odfv2.version == "v1" + assert odfv2.current_version_number == 1 + + +class TestParseFeatureRef: + def test_bare_ref(self): + fv, version, feat = _parse_feature_ref("driver_stats:trips") + assert fv == "driver_stats" + assert version is None + assert feat == "trips" + + def test_versioned_ref(self): + fv, version, feat = _parse_feature_ref("driver_stats@v2:trips") + assert fv == "driver_stats" + assert version == 2 + assert feat == "trips" + + def test_latest_ref(self): + fv, version, feat = _parse_feature_ref("driver_stats@latest:trips") + assert fv == "driver_stats" + assert version is None + assert feat == "trips" + + def test_v0_ref(self): + fv, version, feat = _parse_feature_ref("driver_stats@v0:trips") + assert fv == "driver_stats" + assert version == 0 + assert feat == "trips" + + def test_uppercase_v(self): + fv, version, feat = _parse_feature_ref("driver_stats@V3:trips") + assert fv == "driver_stats" + assert version == 3 + assert feat == "trips" + + def test_invalid_no_colon(self): + with pytest.raises(ValueError, match="Invalid feature reference"): + _parse_feature_ref("driver_stats_trips") + + def test_unrecognized_version_falls_back(self): + """Unrecognized version format falls back to treating full fv_part as the name.""" + fv, version, feat = _parse_feature_ref("driver_stats@abc:trips") + assert fv == "driver_stats@abc" + assert version is None + assert feat == "trips" + + def test_empty_version(self): + fv, version, feat = _parse_feature_ref("driver_stats@:trips") + assert fv == "driver_stats" + assert version is None + assert feat == "trips" + + def test_at_sign_in_fv_name_falls_back_gracefully(self): + """Legacy FV name with @ falls back to treating whole pre-colon string as name.""" + fv, version, feat = _parse_feature_ref("my@weird:feature") + assert fv == "my@weird" + assert version is None + assert feat == "feature" + + def test_at_sign_with_valid_version_still_parses(self): + """A valid @v suffix still parses as a version.""" + fv, version, feat = _parse_feature_ref("stats@v2:trips") + assert fv == "stats" + assert version == 2 + assert feat == "trips" + + +class TestEnsureValidRejectsReservedChars: + def test_at_sign_in_name_raises(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="my@weird_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + with pytest.raises(ValueError, match="must not contain '@'"): + fv.ensure_valid() + + def test_colon_in_name_raises(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="my:weird_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + with pytest.raises(ValueError, match="must not contain ':'"): + fv.ensure_valid() + + def test_valid_name_passes(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="driver_stats", + entities=[entity], + ttl=timedelta(days=1), + ) + fv.ensure_valid() # Should not raise + + +class TestStripVersionFromRef: + def test_bare_ref(self): + assert _strip_version_from_ref("driver_stats:trips") == "driver_stats:trips" + + def test_versioned_ref(self): + assert _strip_version_from_ref("driver_stats@v2:trips") == "driver_stats:trips" + + def test_latest_ref(self): + assert ( + _strip_version_from_ref("driver_stats@latest:trips") == "driver_stats:trips" + ) + + +class TestTableId: + def test_no_version(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + from feast.infra.online_stores.sqlite import _table_id + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + assert _table_id("my_project", fv) == "my_project_test_fv" + + def test_v0_no_suffix(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + from feast.infra.online_stores.sqlite import _table_id + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + fv.current_version_number = 0 + assert _table_id("my_project", fv) == "my_project_test_fv" + + def test_v1_with_suffix(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + from feast.infra.online_stores.sqlite import _table_id + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + fv.current_version_number = 1 + assert ( + _table_id("my_project", fv, enable_versioning=True) + == "my_project_test_fv_v1" + ) + + def test_v5_with_suffix(self): + from datetime import timedelta + + from feast.entity import Entity + from feast.feature_view import FeatureView + from feast.infra.online_stores.sqlite import _table_id + + entity = Entity(name="entity_id", join_keys=["entity_id"]) + fv = FeatureView( + name="test_fv", + entities=[entity], + ttl=timedelta(days=1), + ) + fv.current_version_number = 5 + assert ( + _table_id("my_project", fv, enable_versioning=True) + == "my_project_test_fv_v5" + ) + + +class TestValidateFeatureRefsVersioned: + def test_versioned_refs_no_collision_with_full_names(self): + from feast.utils import _validate_feature_refs + + # Different versions of the same feature should not collide with full names + refs = ["driver_stats@v1:trips", "driver_stats@v2:trips"] + _validate_feature_refs(refs, full_feature_names=True) # Should not raise + + def test_versioned_refs_collision_without_full_names(self): + from feast.errors import FeatureNameCollisionError + from feast.utils import _validate_feature_refs + + # Same feature name from different versions collides without full names + refs = ["driver_stats@v1:trips", "driver_stats@v2:trips"] + with pytest.raises(FeatureNameCollisionError): + _validate_feature_refs(refs, full_feature_names=False) + + +def _dummy_transformation(): + from feast.transformation.python_transformation import PythonTransformation + + def identity(features_df): + return features_df + + return PythonTransformation( + udf=identity, + udf_string="def identity(features_df):\n return features_df\n", + ) diff --git a/ui/public/projects-list.json b/ui/public/projects-list.json index 238df4b5b41..4868adf6d88 100644 --- a/ui/public/projects-list.json +++ b/ui/public/projects-list.json @@ -3,7 +3,7 @@ { "name": "Credit Score Project", "description": "Project for credit scoring team and associated models.", - "id": "credit_score_project", + "id": "credit_scoring_aws", "registryPath": "/registry.db" }, { diff --git a/ui/public/registry.db b/ui/public/registry.db index ae9a05a4a97..0c16e405ccb 100644 Binary files a/ui/public/registry.db and b/ui/public/registry.db differ diff --git a/ui/src/pages/feature-views/FeatureViewListingTable.tsx b/ui/src/pages/feature-views/FeatureViewListingTable.tsx index e865abe6e74..7537f8122c9 100644 --- a/ui/src/pages/feature-views/FeatureViewListingTable.tsx +++ b/ui/src/pages/feature-views/FeatureViewListingTable.tsx @@ -49,6 +49,13 @@ const FeatureViewListingTable = ({ return features.length; }, }, + { + name: "Version", + render: (item: genericFVType) => { + const ver = (item.object as any)?.meta?.currentVersionNumber; + return ver != null && ver > 0 ? `v${ver}` : "—"; + }, + }, ]; // Add Project column when viewing all projects diff --git a/ui/src/pages/feature-views/FeatureViewVersionsTab.tsx b/ui/src/pages/feature-views/FeatureViewVersionsTab.tsx new file mode 100644 index 00000000000..1e5e44d6804 --- /dev/null +++ b/ui/src/pages/feature-views/FeatureViewVersionsTab.tsx @@ -0,0 +1,256 @@ +import React, { useContext, useState, useMemo } from "react"; +import { + EuiBasicTable, + EuiText, + EuiPanel, + EuiTitle, + EuiHorizontalRule, + EuiCodeBlock, + EuiSpacer, + EuiFlexGroup, + EuiFlexItem, + EuiBadge, +} from "@elastic/eui"; +import RegistryPathContext from "../../contexts/RegistryPathContext"; +import useLoadRegistry from "../../queries/useLoadRegistry"; +import { feast } from "../../protos"; +import { toDate } from "../../utils/timestamp"; +import { useParams } from "react-router-dom"; + +interface FeatureViewVersionsTabProps { + featureViewName: string; +} + +interface DecodedVersion { + record: feast.core.IFeatureViewVersionRecord; + features: feast.core.IFeatureSpecV2[]; + entities: string[]; + description: string; + udfBody: string | null; +} + +const decodeVersionProto = ( + record: feast.core.IFeatureViewVersionRecord, +): DecodedVersion => { + const result: DecodedVersion = { + record, + features: [], + entities: [], + description: "", + udfBody: null, + }; + + if (!record.featureViewProto || record.featureViewProto.length === 0) { + return result; + } + + try { + const bytes = + record.featureViewProto instanceof Uint8Array + ? record.featureViewProto + : new Uint8Array(record.featureViewProto); + + if (record.featureViewType === "on_demand_feature_view") { + const odfv = feast.core.OnDemandFeatureView.decode(bytes); + result.features = odfv.spec?.features || []; + result.description = odfv.spec?.description || ""; + result.udfBody = + odfv.spec?.featureTransformation?.userDefinedFunction?.bodyText || + odfv.spec?.userDefinedFunction?.bodyText || + null; + } else if (record.featureViewType === "stream_feature_view") { + const sfv = feast.core.StreamFeatureView.decode(bytes); + result.features = sfv.spec?.features || []; + result.entities = sfv.spec?.entities || []; + result.description = sfv.spec?.description || ""; + } else { + const fv = feast.core.FeatureView.decode(bytes); + result.features = fv.spec?.features || []; + result.entities = fv.spec?.entities || []; + result.description = fv.spec?.description || ""; + } + } catch (e) { + console.error("Failed to decode version proto:", e); + } + + return result; +}; + +const VersionDetail = ({ decoded }: { decoded: DecodedVersion }) => { + return ( + + {decoded.description && ( + + + {decoded.description} + + + )} + {decoded.udfBody && ( + + + +

Transformation

+
+ + + {decoded.udfBody} + +
+
+ )} + + + + +

Features ({decoded.features.length})

+
+ + {decoded.features.length > 0 ? ( + + feast.types.ValueType.Enum[vt], + }, + ]} + /> + ) : ( + No features in this version. + )} +
+
+ {decoded.entities.length > 0 && ( + + + +

Entities

+
+ + + {decoded.entities.map((entity) => ( + + {entity} + + ))} + +
+
+ )} +
+
+ ); +}; + +const FeatureViewVersionsTab = ({ + featureViewName, +}: FeatureViewVersionsTabProps) => { + const registryUrl = useContext(RegistryPathContext); + const { projectName } = useParams(); + const registryQuery = useLoadRegistry(registryUrl, projectName); + const [expandedRows, setExpandedRows] = useState>({}); + + const records = + registryQuery.data?.objects?.featureViewVersionHistory?.records?.filter( + (r: feast.core.IFeatureViewVersionRecord) => + r.featureViewName === featureViewName, + ) || []; + + const decodedVersions = useMemo( + () => records.map(decodeVersionProto), + [records], + ); + + if (records.length === 0) { + return No version history for this feature view.; + } + + const toggleRow = (versionNumber: number) => { + setExpandedRows((prev) => ({ + ...prev, + [versionNumber]: !prev[versionNumber], + })); + }; + + const columns = [ + { + field: "record.versionNumber", + name: "Version", + render: (_: unknown, item: DecodedVersion) => + `v${item.record.versionNumber}`, + sortable: true, + width: "80px", + }, + { + name: "Features", + render: (item: DecodedVersion) => `${item.features.length}`, + width: "80px", + }, + { + field: "record.featureViewType", + name: "Type", + render: (_: unknown, item: DecodedVersion) => + item.record.featureViewType || "—", + }, + { + field: "record.createdTimestamp", + name: "Created", + render: (_: unknown, item: DecodedVersion) => + item.record.createdTimestamp + ? toDate(item.record.createdTimestamp).toLocaleString() + : "—", + }, + { + field: "record.versionId", + name: "Version ID", + render: (_: unknown, item: DecodedVersion) => + item.record.versionId || "—", + }, + ]; + + const itemIdToExpandedRowMap: Record = {}; + decodedVersions.forEach((decoded) => { + const vn = decoded.record.versionNumber!; + if (expandedRows[vn]) { + itemIdToExpandedRowMap[String(vn)] = ; + } + }); + + return ( + String(item.record.versionNumber)} + itemIdToExpandedRowMap={itemIdToExpandedRowMap} + columns={[ + { + isExpander: true, + width: "40px", + render: (item: DecodedVersion) => { + const vn = item.record.versionNumber!; + return ( + + ); + }, + }, + ...columns, + ]} + /> + ); +}; + +export default FeatureViewVersionsTab; diff --git a/ui/src/pages/feature-views/OnDemandFeatureViewInstance.tsx b/ui/src/pages/feature-views/OnDemandFeatureViewInstance.tsx index 5a4b48f6d6d..70824219aaa 100644 --- a/ui/src/pages/feature-views/OnDemandFeatureViewInstance.tsx +++ b/ui/src/pages/feature-views/OnDemandFeatureViewInstance.tsx @@ -1,11 +1,12 @@ import React from "react"; import { Route, Routes, useNavigate } from "react-router-dom"; import { useParams } from "react-router-dom"; -import { EuiPageTemplate } from "@elastic/eui"; +import { EuiBadge, EuiPageTemplate } from "@elastic/eui"; import { FeatureViewIcon } from "../../graphics/FeatureViewIcon"; -import { useMatchExact } from "../../hooks/useMatchSubpath"; +import { useMatchExact, useMatchSubpath } from "../../hooks/useMatchSubpath"; import OnDemandFeatureViewOverviewTab from "./OnDemandFeatureViewOverviewTab"; +import FeatureViewVersionsTab from "./FeatureViewVersionsTab"; import { useOnDemandFeatureViewCustomTabs, @@ -29,7 +30,17 @@ const OnDemandFeatureInstance = ({ data }: OnDemandFeatureInstanceProps) => { + {featureViewName} + {data?.meta?.currentVersionNumber != null && + data.meta.currentVersionNumber > 0 && ( + + v{data.meta.currentVersionNumber} + + )} + + } tabs={[ { label: "Overview", @@ -38,6 +49,13 @@ const OnDemandFeatureInstance = ({ data }: OnDemandFeatureInstanceProps) => { navigate(""); }, }, + { + label: "Versions", + isSelected: useMatchSubpath("versions"), + onClick: () => { + navigate("versions"); + }, + }, ...customNavigationTabs, ]} /> @@ -47,6 +65,12 @@ const OnDemandFeatureInstance = ({ data }: OnDemandFeatureInstanceProps) => { path="/" element={} /> + + } + /> {CustomTabRoutes} diff --git a/ui/src/pages/feature-views/RegularFeatureViewInstance.tsx b/ui/src/pages/feature-views/RegularFeatureViewInstance.tsx index 48d61e45f8f..a3c831b315f 100644 --- a/ui/src/pages/feature-views/RegularFeatureViewInstance.tsx +++ b/ui/src/pages/feature-views/RegularFeatureViewInstance.tsx @@ -1,12 +1,13 @@ import React, { useContext } from "react"; import { Route, Routes, useNavigate } from "react-router-dom"; -import { EuiPageTemplate } from "@elastic/eui"; +import { EuiBadge, EuiPageTemplate } from "@elastic/eui"; import { FeatureViewIcon } from "../../graphics/FeatureViewIcon"; import { useMatchExact, useMatchSubpath } from "../../hooks/useMatchSubpath"; import RegularFeatureViewOverviewTab from "./RegularFeatureViewOverviewTab"; import FeatureViewLineageTab from "./FeatureViewLineageTab"; +import FeatureViewVersionsTab from "./FeatureViewVersionsTab"; import { useRegularFeatureViewCustomTabs, @@ -57,6 +58,14 @@ const RegularFeatureInstance = ({ }); } + tabs.push({ + label: "Versions", + isSelected: useMatchSubpath("versions"), + onClick: () => { + navigate("versions"); + }, + }); + tabs.push(...customNavigationTabs); const TabRoutes = useRegularFeatureViewCustomTabRoutes(); @@ -66,7 +75,17 @@ const RegularFeatureInstance = ({ + {data?.spec?.name} + {data?.meta?.currentVersionNumber != null && + data.meta.currentVersionNumber > 0 && ( + + v{data.meta.currentVersionNumber} + + )} + + } tabs={tabs} /> @@ -84,6 +103,12 @@ const RegularFeatureInstance = ({ path="/lineage" element={} /> + + } + /> {TabRoutes} diff --git a/ui/src/pages/feature-views/StreamFeatureViewInstance.tsx b/ui/src/pages/feature-views/StreamFeatureViewInstance.tsx index 0e22a6c2e5d..c0b9627bca5 100644 --- a/ui/src/pages/feature-views/StreamFeatureViewInstance.tsx +++ b/ui/src/pages/feature-views/StreamFeatureViewInstance.tsx @@ -1,11 +1,12 @@ import React from "react"; import { Route, Routes, useNavigate } from "react-router-dom"; import { useParams } from "react-router-dom"; -import { EuiPageTemplate } from "@elastic/eui"; +import { EuiBadge, EuiPageTemplate } from "@elastic/eui"; import { FeatureViewIcon } from "../../graphics/FeatureViewIcon"; -import { useMatchExact } from "../../hooks/useMatchSubpath"; +import { useMatchExact, useMatchSubpath } from "../../hooks/useMatchSubpath"; import StreamFeatureViewOverviewTab from "./StreamFeatureViewOverviewTab"; +import FeatureViewVersionsTab from "./FeatureViewVersionsTab"; import { useStreamFeatureViewCustomTabs, @@ -30,7 +31,17 @@ const StreamFeatureInstance = ({ data }: StreamFeatureInstanceProps) => { restrictWidth paddingSize="l" iconType={FeatureViewIcon} - pageTitle={`${featureViewName}`} + pageTitle={ + <> + {featureViewName} + {data?.meta?.currentVersionNumber != null && + data.meta.currentVersionNumber > 0 && ( + + v{data.meta.currentVersionNumber} + + )} + + } tabs={[ { label: "Overview", @@ -39,6 +50,13 @@ const StreamFeatureInstance = ({ data }: StreamFeatureInstanceProps) => { navigate(""); }, }, + { + label: "Versions", + isSelected: useMatchSubpath("versions"), + onClick: () => { + navigate("versions"); + }, + }, ...customNavigationTabs, ]} /> @@ -48,6 +66,12 @@ const StreamFeatureInstance = ({ data }: StreamFeatureInstanceProps) => { path="/" element={} /> + + } + /> {CustomTabRoutes}