Skip to content

Commit 4699d58

Browse files
authored
Make created timestamp column optional (#1108)
* Make created timestamp column optional Signed-off-by: Khor Shu Heng <[email protected]> * Fix argument for FileSource under e2e tests Signed-off-by: Khor Shu Heng <[email protected]> Co-authored-by: Khor Shu Heng <[email protected]>
1 parent 4396d0f commit 4699d58

13 files changed

Lines changed: 55 additions & 64 deletions

File tree

docs/user-guide/feature-retrieval.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ feature_refs = [
3636
# Define entity source
3737
entity_source = FileSource(
3838
"event_timestamp",
39-
"created_timestamp",
40-
"parquet",
39+
ParquetFormat(),
4140
"gs://some-bucket/customer"
4241
)
4342

sdk/python/feast/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,7 @@ def get_historical_features(features: str, entity_df_path: str, destination: str
485485

486486
entity_df["event_timestamp"] = pandas.to_datetime(entity_df["event_timestamp"])
487487

488-
uploaded_df = client.stage_dataframe(
489-
entity_df, "event_timestamp", "created_timestamp"
490-
)
488+
uploaded_df = client.stage_dataframe(entity_df, "event_timestamp")
491489

492490
job = client.get_historical_features(features.split(","), uploaded_df,)
493491
print(job.get_output_file_uri())

sdk/python/feast/client.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,11 @@ def get_historical_features(
881881
882882
Examples:
883883
>>> from feast import Client
884+
>>> from feast.data_format import ParquetFormat
884885
>>> from datetime import datetime
885886
>>> feast_client = Client(core_url="localhost:6565")
886887
>>> feature_refs = ["bookings:bookings_7d", "bookings:booking_14d"]
887-
>>> entity_source = FileSource("event_timestamp", "parquet", "gs://some-bucket/customer")
888+
>>> entity_source = FileSource("event_timestamp", ParquetFormat(), "gs://some-bucket/customer")
888889
>>> feature_retrieval_job = feast_client.get_historical_features(
889890
>>> feature_refs, entity_source, project="my_project")
890891
>>> output_file_uri = feature_retrieval_job.get_output_file_uri()
@@ -916,10 +917,7 @@ def get_historical_features(
916917
df_export_path.name, bucket, entity_staging_uri.path.lstrip("/")
917918
)
918919
entity_source = FileSource(
919-
"event_timestamp",
920-
"created_timestamp",
921-
ParquetFormat(),
922-
entity_staging_uri.geturl(),
920+
"event_timestamp", ParquetFormat(), entity_staging_uri.geturl(),
923921
)
924922

925923
return start_historical_feature_retrieval_job(
@@ -955,12 +953,13 @@ def get_historical_features_df(
955953
956954
Examples:
957955
>>> from feast import Client
956+
>>> from feast.data_format import ParquetFormat
958957
>>> from datetime import datetime
959958
>>> from pyspark.sql import SparkSession
960959
>>> spark = SparkSession.builder.getOrCreate()
961960
>>> feast_client = Client(core_url="localhost:6565")
962961
>>> feature_refs = ["bookings:bookings_7d", "bookings:booking_14d"]
963-
>>> entity_source = FileSource("event_timestamp", "parquet", "gs://some-bucket/customer")
962+
>>> entity_source = FileSource("event_timestamp", ParquetFormat, "gs://some-bucket/customer")
964963
>>> df = feast_client.get_historical_features(
965964
>>> feature_refs, entity_source, project="my_project")
966965
"""
@@ -1011,11 +1010,6 @@ def start_stream_to_online_ingestion(
10111010
return start_stream_to_online_ingestion(feature_table, extra_jars or [], self)
10121011

10131012
def stage_dataframe(
1014-
self,
1015-
df: pd.DataFrame,
1016-
event_timestamp_column: str,
1017-
created_timestamp_column: str,
1013+
self, df: pd.DataFrame, event_timestamp_column: str,
10181014
) -> FileSource:
1019-
return stage_dataframe(
1020-
df, event_timestamp_column, created_timestamp_column, self
1021-
)
1015+
return stage_dataframe(df, event_timestamp_column, self)

sdk/python/feast/data_source.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ class DataSource:
348348
def __init__(
349349
self,
350350
event_timestamp_column: str,
351-
created_timestamp_column: str,
352-
field_mapping: Optional[Dict[str, str]] = dict(),
351+
created_timestamp_column: Optional[str] = "",
352+
field_mapping: Optional[Dict[str, str]] = None,
353353
date_partition_column: Optional[str] = "",
354354
):
355355
self._event_timestamp_column = event_timestamp_column
356356
self._created_timestamp_column = created_timestamp_column
357-
self._field_mapping = field_mapping
357+
self._field_mapping = field_mapping if field_mapping else {}
358358
self._date_partition_column = date_partition_column
359359

360360
def __eq__(self, other):
@@ -409,7 +409,7 @@ def created_timestamp_column(self):
409409
@created_timestamp_column.setter
410410
def created_timestamp_column(self, created_timestamp_column):
411411
"""
412-
Sets the event timestamp column of this data source
412+
Sets the created timestamp column of this data source
413413
"""
414414
self._created_timestamp_column = created_timestamp_column
415415

@@ -498,10 +498,10 @@ class FileSource(DataSource):
498498
def __init__(
499499
self,
500500
event_timestamp_column: str,
501-
created_timestamp_column: str,
502501
file_format: FileFormat,
503502
file_url: str,
504-
field_mapping: Optional[Dict[str, str]] = dict(),
503+
created_timestamp_column: Optional[str] = "",
504+
field_mapping: Optional[Dict[str, str]] = None,
505505
date_partition_column: Optional[str] = "",
506506
):
507507
super().__init__(
@@ -555,9 +555,9 @@ class BigQuerySource(DataSource):
555555
def __init__(
556556
self,
557557
event_timestamp_column: str,
558-
created_timestamp_column: str,
559558
table_ref: str,
560-
field_mapping: Optional[Dict[str, str]] = dict(),
559+
created_timestamp_column: Optional[str] = "",
560+
field_mapping: Optional[Dict[str, str]] = None,
561561
date_partition_column: Optional[str] = "",
562562
):
563563
super().__init__(

sdk/python/feast/pyspark/abc.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,7 @@ def start_stream_to_online_ingestion(
458458

459459
@abc.abstractmethod
460460
def stage_dataframe(
461-
self,
462-
df: pandas.DataFrame,
463-
event_timestamp_column: str,
464-
created_timestamp_column: str,
461+
self, df: pandas.DataFrame, event_timestamp_column: str,
465462
) -> FileSource:
466463
"""
467464
Upload a pandas dataframe so it is available to the Spark cluster.

sdk/python/feast/pyspark/historical_feature_retrieval_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def __init__(
8686
format: str,
8787
path: str,
8888
event_timestamp_column: str,
89-
created_timestamp_column: Optional[str] = None,
89+
created_timestamp_column: Optional[str] = "",
9090
field_mapping: Optional[Dict[str, str]] = None,
9191
options: Optional[Dict[str, str]] = None,
9292
):

sdk/python/feast/pyspark/launcher.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,6 @@ def start_stream_to_online_ingestion(
243243
)
244244

245245

246-
def stage_dataframe(
247-
df, event_timestamp_column: str, created_timestamp_column: str, client: "Client"
248-
) -> FileSource:
246+
def stage_dataframe(df, event_timestamp_column: str, client: "Client") -> FileSource:
249247
launcher = resolve_launcher(client._config)
250-
return launcher.stage_dataframe(
251-
df, event_timestamp_column, created_timestamp_column,
252-
)
248+
return launcher.stage_dataframe(df, event_timestamp_column)

sdk/python/feast/pyspark/launchers/aws/emr.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ def start_stream_to_online_ingestion(
291291

292292
return EmrStreamIngestionJob(self._emr_client(), job_ref)
293293

294-
def stage_dataframe(
295-
self, df: pandas.DataFrame, event_timestamp: str, created_timestamp_column: str
296-
) -> FileSource:
294+
def stage_dataframe(self, df: pandas.DataFrame, event_timestamp: str) -> FileSource:
297295
with tempfile.NamedTemporaryFile() as f:
298296
df.to_parquet(f)
299297
file_url = _s3_upload(
@@ -304,7 +302,6 @@ def stage_dataframe(
304302
)
305303
return FileSource(
306304
event_timestamp_column=event_timestamp,
307-
created_timestamp_column=created_timestamp_column,
308305
file_format=ParquetFormat(),
309306
file_url=file_url,
310307
)

sdk/python/feast/pyspark/launchers/gcloud/dataproc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def start_stream_to_online_ingestion(
205205
cancel_fn = partial(self.dataproc_cancel, operation.metadata.job_id)
206206
return DataprocStreamingIngestionJob(operation, cancel_fn)
207207

208-
def stage_dataframe(
209-
self, df, event_timestamp_column: str, created_timestamp_column: str,
210-
):
208+
def stage_dataframe(self, df, event_timestamp_column: str):
211209
raise NotImplementedError
212210

213211
def get_job_by_id(self, job_id: str) -> SparkJob:

sdk/python/feast/pyspark/launchers/standalone/local.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ def start_stream_to_online_ingestion(
224224
ui_port,
225225
)
226226

227-
def stage_dataframe(
228-
self, df, event_timestamp_column: str, created_timestamp_column: str,
229-
):
227+
def stage_dataframe(self, df, event_timestamp_column: str):
230228
raise NotImplementedError
231229

232230
def get_job_by_id(self, job_id: str) -> SparkJob:

0 commit comments

Comments
 (0)