MCPcopy Index your code
hub / github.com/feast-dev/feast / bootstrap

Function bootstrap

sdk/python/feast/templates/postgres/bootstrap.py:9–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8
9def bootstrap():
10 # Bootstrap() will automatically be called from the init_repo() during `feast init`
11
12 import pathlib
13 from datetime import datetime, timedelta
14
15 from feast.driver_test_data import create_driver_hourly_stats_df
16
17 repo_path = pathlib.Path(__file__).parent.absolute() / "feature_repo"
18 config_file = repo_path / "feature_store.yaml"
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 postgres_host = click.prompt("Postgres host", default="localhost")
27 postgres_port = click.prompt("Postgres port", default="5432")
28 postgres_database = click.prompt("Postgres DB name", default="postgres")
29 postgres_schema = click.prompt("Postgres schema", default="public")
30 postgres_user = click.prompt("Postgres user")
31 postgres_password = click.prompt("Postgres password", hide_input=True)
32 postgres_sslmode = click.prompt(
33 "Postgres sslmode (disable, allow, prefer, require, verify-ca, verify-full)",
34 default="require",
35 )
36
37 if click.confirm(
38 'Should I upload example data to Postgres (overwriting "feast_driver_hourly_stats" table)?',
39 default=True,
40 ):
41 config = PostgreSQLConfig(
42 host=postgres_host,
43 port=int(postgres_port),
44 database=postgres_database,
45 db_schema=postgres_schema,
46 user=postgres_user,
47 password=postgres_password,
48 sslmode=postgres_sslmode,
49 )
50
51 db_connection = psycopg.connect(
52 conninfo=(
53 f"postgresql://{postgres_user}"
54 f":{postgres_password}"
55 f"@{postgres_host}"
56 f":{int(postgres_port)}"
57 f"/{postgres_database}"
58 ),
59 sslmode=postgres_sslmode,
60 options=f"-c search_path={postgres_schema}",
61 )
62
63 with db_connection as conn, conn.cursor() as cur:
64 cur.execute('DROP TABLE IF EXISTS "feast_driver_hourly_stats"')
65
66 df_to_postgres_table(

Callers 1

bootstrap.pyFile · 0.70

Calls 6

PostgreSQLConfigClass · 0.90
df_to_postgres_tableFunction · 0.90
replace_str_in_fileFunction · 0.90
connectMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected