Repository navigation
Inferencing of Features in FeatureView and timestamp column of DataSource #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
feast-ci-bot
merged 8 commits into
feast-dev:master
from
mavysavydav:featureRepoSchemaInferencing
May 4, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
df1e9a3
Implemented the inferencing. Did cursory runs to make sure it works. …
e59c561
fixed issue with mutable default argument in FeatureView
8791013
Fix in example_feature_repo_with_inference.py file
c9484a2
Added test cases and small fixes.
6ef2afd
fixed missing import with handling for lint error
91bf53b
marked a test that needs bigquery client requesting to be an integrat…
01fd199
Code review corrections + BQSource Query arg handling + corresponding…
052abe9
CR corrections
mavysavydav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from google.protobuf.duration_pb2 import Duration | ||
|
|
||
| from feast import Entity, FeatureView, ValueType | ||
| from feast.data_source import FileSource | ||
|
|
||
| driver_hourly_stats = FileSource( | ||
| path="%PARQUET_PATH%", # placeholder to be replaced by the test | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| driver = Entity(name="driver_id", value_type=ValueType.INT64, description="driver id",) | ||
|
|
||
| # features are inferred from columns of data source | ||
| driver_hourly_stats_view = FeatureView( | ||
| name="driver_hourly_stats", | ||
| entities=["driver_id"], | ||
| ttl=Duration(seconds=86400 * 1), | ||
| online=True, | ||
| input=driver_hourly_stats, | ||
| tags={}, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import contextlib | ||
| import tempfile | ||
| from datetime import datetime, timedelta | ||
|
|
||
| import pandas as pd | ||
| import pytest | ||
| from google.cloud import bigquery | ||
|
|
||
| from feast.data_format import ParquetFormat | ||
| from feast.data_source import BigQuerySource, FileSource | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def simple_dataset_1() -> pd.DataFrame: | ||
| now = datetime.utcnow() | ||
| ts = pd.Timestamp(now).round("ms") | ||
| data = { | ||
| "id": [1, 2, 1, 3, 3], | ||
| "float_col": [0.1, 0.2, 0.3, 4, 5], | ||
| "int64_col": [1, 2, 3, 4, 5], | ||
| "string_col": ["a", "b", "c", "d", "e"], | ||
| "ts_1": [ | ||
| ts, | ||
| ts - timedelta(hours=4), | ||
| ts - timedelta(hours=3), | ||
| ts - timedelta(hours=2), | ||
| ts - timedelta(hours=1), | ||
| ], | ||
| } | ||
| return pd.DataFrame.from_dict(data) | ||
|
|
||
|
|
||
| @contextlib.contextmanager | ||
| def prep_file_source(df, event_timestamp_column="") -> FileSource: | ||
| with tempfile.NamedTemporaryFile(suffix=".parquet") as f: | ||
| f.close() | ||
| df.to_parquet(f.name) | ||
| file_source = FileSource( | ||
| file_format=ParquetFormat(), | ||
| file_url=f.name, | ||
| event_timestamp_column=event_timestamp_column, | ||
| ) | ||
| yield file_source | ||
|
|
||
|
|
||
| def simple_bq_source_using_table_ref_arg( | ||
| df, event_timestamp_column="" | ||
| ) -> BigQuerySource: | ||
| client = bigquery.Client() | ||
| gcp_project = client.project | ||
| bigquery_dataset = "ds" | ||
|
mavysavydav marked this conversation as resolved.
Resolved
|
||
| dataset = bigquery.Dataset(f"{gcp_project}.{bigquery_dataset}") | ||
| client.create_dataset(dataset, exists_ok=True) | ||
| dataset.default_table_expiration_ms = ( | ||
| 1000 | ||
| * 60 | ||
| * 60 # 60 minutes in milliseconds (seems to be minimum limit for gcloud) | ||
| ) | ||
| client.update_dataset(dataset, ["default_table_expiration_ms"]) | ||
| table_ref = f"{gcp_project}.{bigquery_dataset}.table_1" | ||
|
|
||
| job = client.load_table_from_dataframe( | ||
| df, table_ref, job_config=bigquery.LoadJobConfig() | ||
| ) | ||
| job.result() | ||
|
|
||
| return BigQuerySource( | ||
| table_ref=table_ref, event_timestamp_column=event_timestamp_column, | ||
| ) | ||
|
|
||
|
|
||
| def simple_bq_source_using_query_arg(df, event_timestamp_column="") -> BigQuerySource: | ||
| bq_source_using_table_ref = simple_bq_source_using_table_ref_arg( | ||
| df, event_timestamp_column | ||
| ) | ||
| return BigQuerySource( | ||
| query=f"SELECT * FROM {bq_source_using_table_ref.table_ref}", | ||
| event_timestamp_column=event_timestamp_column, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.