()
| 2 | |
| 3 | |
| 4 | def bootstrap(): |
| 5 | # Bootstrap() will automatically be called from the init_repo() during `feast init` |
| 6 | |
| 7 | import pathlib |
| 8 | from datetime import datetime, timedelta |
| 9 | |
| 10 | import pyarrow as pa |
| 11 | import pyarrow.parquet as pq |
| 12 | |
| 13 | from feast.driver_test_data import create_driver_hourly_stats_df |
| 14 | |
| 15 | repo_path = pathlib.Path(__file__).parent.absolute() / "feature_repo" |
| 16 | project_name = pathlib.Path(__file__).parent.absolute().name |
| 17 | data_path = repo_path / "data" |
| 18 | data_path.mkdir(exist_ok=True) |
| 19 | |
| 20 | end_date = datetime.now().replace(microsecond=0, second=0, minute=0) |
| 21 | start_date = end_date - timedelta(days=15) |
| 22 | |
| 23 | driver_entities = [1001, 1002, 1003, 1004, 1005] |
| 24 | driver_df = create_driver_hourly_stats_df(driver_entities, start_date, end_date) |
| 25 | |
| 26 | driver_stats_path = data_path / "driver_stats.parquet" |
| 27 | driver_df.to_parquet(path=str(driver_stats_path), allow_truncated_timestamps=True) |
| 28 | |
| 29 | # Create an empty parquet file for the label view batch source |
| 30 | # Use explicit pyarrow schema to ensure proper column types even with zero rows |
| 31 | label_schema = pa.schema( |
| 32 | [ |
| 33 | ("driver_id", pa.int64()), |
| 34 | ("is_reliable", pa.int64()), |
| 35 | ("quality_score", pa.float32()), |
| 36 | ("reviewer_notes", pa.string()), |
| 37 | ("labeler", pa.string()), |
| 38 | ("event_timestamp", pa.timestamp("ns")), |
| 39 | ] |
| 40 | ) |
| 41 | label_table = pa.table( |
| 42 | {field.name: pa.array([], type=field.type) for field in label_schema}, |
| 43 | schema=label_schema, |
| 44 | ) |
| 45 | label_data_path = data_path / "driver_quality_labels.parquet" |
| 46 | pq.write_table(label_table, str(label_data_path)) |
| 47 | |
| 48 | example_py_file = repo_path / "feature_definitions.py" |
| 49 | replace_str_in_file(example_py_file, "%PROJECT_NAME%", str(project_name)) |
| 50 | replace_str_in_file( |
| 51 | example_py_file, "%PARQUET_PATH%", str(driver_stats_path.relative_to(repo_path)) |
| 52 | ) |
| 53 | replace_str_in_file( |
| 54 | example_py_file, "%LOGGING_PATH%", str(data_path.relative_to(repo_path)) |
| 55 | ) |
| 56 | replace_str_in_file( |
| 57 | example_py_file, |
| 58 | "%LABEL_DATA_PATH%", |
| 59 | str(label_data_path.relative_to(repo_path)), |
| 60 | ) |
| 61 |
no test coverage detected