|
28 | 28 | from feast import Client, Entity, Feature, FeatureTable, FileSource, ValueType |
29 | 29 | from feast.core import CoreService_pb2_grpc as Core |
30 | 30 | from feast.data_format import ParquetFormat |
| 31 | +from feast.pyspark.abc import SparkJobStatus |
31 | 32 | from tests.feast_core_server import CoreServicer |
32 | 33 |
|
33 | 34 |
|
@@ -107,6 +108,26 @@ def client_with_local_spark(tmpdir): |
107 | 108 | ) |
108 | 109 |
|
109 | 110 |
|
| 111 | +@pytest.fixture() |
| 112 | +def client_with_tfrecord_output(tmpdir): |
| 113 | + import pyspark |
| 114 | + |
| 115 | + spark_staging_location = f"file://{os.path.join(tmpdir, 'staging')}" |
| 116 | + historical_feature_output_location = ( |
| 117 | + f"file://{os.path.join(tmpdir, 'historical_feature_retrieval_tfrecord_output')}" |
| 118 | + ) |
| 119 | + |
| 120 | + return Client( |
| 121 | + core_url=f"localhost:{free_port}", |
| 122 | + spark_launcher="standalone", |
| 123 | + spark_standalone_master="local", |
| 124 | + spark_home=os.path.dirname(pyspark.__file__), |
| 125 | + spark_staging_location=spark_staging_location, |
| 126 | + historical_feature_output_location=historical_feature_output_location, |
| 127 | + historical_feature_output_format="tfrecord", |
| 128 | + ) |
| 129 | + |
| 130 | + |
110 | 131 | @pytest.fixture() |
111 | 132 | def driver_entity(client): |
112 | 133 | return client.apply(Entity("driver_id", "description", ValueType.INT32)) |
@@ -466,3 +487,39 @@ def test_historical_feature_retrieval_with_pandas_dataframe_input( |
466 | 487 | by=["customer_id", "driver_id", "event_timestamp"] |
467 | 488 | ).reset_index(drop=True), |
468 | 489 | ) |
| 490 | + |
| 491 | + |
| 492 | +@pytest.mark.usefixtures( |
| 493 | + "driver_entity", |
| 494 | + "customer_entity", |
| 495 | + "bookings_feature_table", |
| 496 | + "transactions_feature_table", |
| 497 | +) |
| 498 | +def test_historical_feature_retrieval_with_tfrecord_output( |
| 499 | + client_with_tfrecord_output, |
| 500 | +): |
| 501 | + |
| 502 | + customer_driver_pairs_pandas_df = pd.DataFrame( |
| 503 | + np.array( |
| 504 | + [ |
| 505 | + [1001, 8001, datetime(year=2020, month=9, day=1, tzinfo=utc)], |
| 506 | + [2001, 8001, datetime(year=2020, month=9, day=2, tzinfo=utc)], |
| 507 | + [2001, 8002, datetime(year=2020, month=9, day=1, tzinfo=utc)], |
| 508 | + [1001, 8001, datetime(year=2020, month=9, day=2, tzinfo=utc)], |
| 509 | + [1001, 8001, datetime(year=2020, month=9, day=3, tzinfo=utc)], |
| 510 | + [1001, 8001, datetime(year=2020, month=9, day=4, tzinfo=utc)], |
| 511 | + ] |
| 512 | + ), |
| 513 | + columns=["customer_id", "driver_id", "event_timestamp"], |
| 514 | + ) |
| 515 | + customer_driver_pairs_pandas_df = customer_driver_pairs_pandas_df.astype( |
| 516 | + {"customer_id": "int32", "driver_id": "int32"} |
| 517 | + ) |
| 518 | + |
| 519 | + job_output = client_with_tfrecord_output.get_historical_features( |
| 520 | + ["transactions:total_transactions", "bookings:total_completed_bookings"], |
| 521 | + customer_driver_pairs_pandas_df, |
| 522 | + ) |
| 523 | + |
| 524 | + job_output.get_output_file_uri() |
| 525 | + assert job_output.get_status() == SparkJobStatus.COMPLETED |
0 commit comments