Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add documentation
Signed-off-by: Danny Chiao <danny@tecton.ai>
  • Loading branch information
adchia committed Apr 20, 2022
commit 8e1509d73d9ede27a8aad8ffa7e0b5d85daed3e9
25 changes: 25 additions & 0 deletions docs/reference/data-sources/postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# PostgreSQL

## Description

**NOTE**: The Postgres plugin is a contrib plugin. This means it may not be fully stable.


The PostgreSQL data source allows for the retrieval of historical feature values from a PostgreSQL database for building training datasets as well as materializing features into an online store.

## Examples

Defining a Postgres source

```python
from feast.infra.offline_stores.contrib.postgres_offline_store.postgres_source import (
PostgreSQLSource,
)

driver_stats_source = PostgreSQLSource(
name="feast_driver_hourly_stats",
query="SELECT * FROM feast_driver_hourly_stats",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)
```
2 changes: 1 addition & 1 deletion docs/reference/data-sources/spark.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Spark
# Spark (contrib)

## Description

Expand Down
34 changes: 34 additions & 0 deletions docs/reference/offline-stores/postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# PostgreSQL (contrib)

## Description

The PostgreSQL offline store is an offline store that provides support for reading [PostgreSQL](../data-sources/postgres.md) data sources.


**DISCLAIMER**: This PostgreSQL offline store still does not achieve full test coverage.

* Entity dataframes can be provided as a SQL query or can be provided as a Pandas dataframe. Pandas dataframes will be converted to a Spark dataframe and processed as a temporary view.
* A `SparkRetrievalJob` is returned when calling `get_historical_features()`.
* This allows you to call
* `to_df` to retrieve the pandas dataframe.
* `to_arrow` to retrieve the dataframe as a PyArrow table.

## Example

{% code title="feature_store.yaml" %}
```yaml
project: my_project
registry: data/registry.db
provider: local
offline_store:
type: postgres
host: DB_HOST
port: DB_PORT
database: DB_NAME
db_schema: DB_SCHEMA
user: DB_USERNAME
password: DB_PASSWORD
online_store:
path: data/online_store.db
```
{% endcode %}
2 changes: 1 addition & 1 deletion docs/reference/offline-stores/spark.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Spark
# Spark (contrib)

## Description

Expand Down
27 changes: 27 additions & 0 deletions docs/reference/online-stores/postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# PostgreSQL (contrib)

## Description

The PostgreSQL online store provides support for materializing feature values into a PostgreSQL database for serving online features.

* Only the latest feature values are persisted

## Example

{% code title="feature_store.yaml" %}
```yaml
project: my_feature_repo
registry: data/registry.db
provider: local
online_store:
type: postgres
host: DB_HOST
port: DB_PORT
database: DB_NAME
db_schema: DB_SCHEMA
user: DB_USERNAME
password: DB_PASSWORD
```
{% endcode %}

Configuration options are available [here](https://rtd.feast.dev/en/latest/#feast.repo_config.SqliteOnlineStoreConfig).
21 changes: 20 additions & 1 deletion sdk/python/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Trino Source
:members:
:exclude-members: TrinoOptions

PostgreSQL Source
------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres_source
:members:
:exclude-members: PostgreSQLOptions

File Source
------------------
Expand Down Expand Up @@ -192,6 +198,12 @@ Trino Offline Store
.. automodule:: feast.infra.offline_stores.contrib.trino_offline_store.trino
:members:

PostgreSQL Offline Store
-------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres
:members:


Online Store
==================
Expand Down Expand Up @@ -223,4 +235,11 @@ Redis Online Store

.. automodule:: feast.infra.online_stores.redis
:members:
:noindex:
:noindex:

PostgreSQL Online Store
------------------

.. automodule:: feast.infra.online_stores.contrib.postgres
:members:
:noindex:
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
feast.infra.offline\_stores.contrib.postgres\_offline\_store package
====================================================================

Submodules
----------

feast.infra.offline\_stores.contrib.postgres\_offline\_store.postgres module
----------------------------------------------------------------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres
:members:
:undoc-members:
:show-inheritance:

feast.infra.offline\_stores.contrib.postgres\_offline\_store.postgres\_source module
------------------------------------------------------------------------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres_source
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Subpackages
.. toctree::
:maxdepth: 4

feast.infra.offline_stores.contrib.postgres_offline_store
feast.infra.offline_stores.contrib.spark_offline_store
feast.infra.offline_stores.contrib.trino_offline_store

Expand All @@ -21,6 +22,14 @@ feast.infra.offline\_stores.contrib.contrib\_repo\_configuration module
:undoc-members:
:show-inheritance:

feast.infra.offline\_stores.contrib.postgres\_repo\_configuration module
------------------------------------------------------------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_repo_configuration
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

Expand Down
21 changes: 21 additions & 0 deletions sdk/python/docs/source/feast.infra.online_stores.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
feast.infra.online\_stores.contrib package
==========================================

Submodules
----------

feast.infra.online\_stores.contrib.postgres module
--------------------------------------------------

.. automodule:: feast.infra.online_stores.contrib.postgres
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: feast.infra.online_stores.contrib
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions sdk/python/docs/source/feast.infra.online_stores.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
feast.infra.online\_stores package
==================================

Subpackages
-----------

.. toctree::
:maxdepth: 4

feast.infra.online_stores.contrib

Submodules
----------

Expand Down
29 changes: 29 additions & 0 deletions sdk/python/docs/source/feast.infra.utils.postgres.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
feast.infra.utils.postgres package
==================================

Submodules
----------

feast.infra.utils.postgres.postgres\_config module
--------------------------------------------------

.. automodule:: feast.infra.utils.postgres.postgres_config
:members:
:undoc-members:
:show-inheritance:

feast.infra.utils.postgres.utils module
---------------------------------------

.. automodule:: feast.infra.utils.postgres.utils
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: feast.infra.utils.postgres
:members:
:undoc-members:
:show-inheritance:
8 changes: 8 additions & 0 deletions sdk/python/docs/source/feast.infra.utils.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
feast.infra.utils package
=========================

Subpackages
-----------

.. toctree::
:maxdepth: 4

feast.infra.utils.postgres

Submodules
----------

Expand Down
16 changes: 16 additions & 0 deletions sdk/python/docs/source/feast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ feast.base\_feature\_view module
:undoc-members:
:show-inheritance:

feast.batch\_feature\_view module
---------------------------------

.. automodule:: feast.batch_feature_view
:members:
:undoc-members:
:show-inheritance:

feast.cli module
----------------

Expand Down Expand Up @@ -264,6 +272,14 @@ feast.saved\_dataset module
:undoc-members:
:show-inheritance:

feast.stream\_feature\_view module
----------------------------------

.. automodule:: feast.stream_feature_view
:members:
:undoc-members:
:show-inheritance:

feast.transformation\_server module
-----------------------------------

Expand Down
21 changes: 20 additions & 1 deletion sdk/python/docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Trino Source
:members:
:exclude-members: TrinoOptions

PostgreSQL Source
------------------

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres_source
:members:
:exclude-members: PostgreSQLOptions

File Source
------------------
Expand Down Expand Up @@ -192,6 +198,12 @@ Trino Offline Store
.. automodule:: feast.infra.offline_stores.contrib.trino_offline_store.trino
:members:

PostgreSQL Offline Store
-------------------
Comment thread
adchia marked this conversation as resolved.
Outdated

.. automodule:: feast.infra.offline_stores.contrib.postgres_offline_store.postgres
:members:


Online Store
==================
Expand Down Expand Up @@ -223,4 +235,11 @@ Redis Online Store

.. automodule:: feast.infra.online_stores.redis
:members:
:noindex:
:noindex:

PostgreSQL Online Store
------------------

.. automodule:: feast.infra.online_stores.contrib.postgres
:members:
:noindex:
7 changes: 7 additions & 0 deletions sdk/python/docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
feast
=====

.. toctree::
:maxdepth: 4

feast
4 changes: 2 additions & 2 deletions sdk/python/feast/infra/utils/postgres/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _get_conn(config: PostgreSQLConfig):
return conn


def df_to_create_table_sql(entity_df, table_name) -> str:
def _df_to_create_table_sql(entity_df, table_name) -> str:
pa_table = pa.Table.from_pandas(entity_df)
columns = [
f""""{f.name}" {arrow_to_pg_type(str(f.type))}""" for f in pa_table.schema
Expand All @@ -41,7 +41,7 @@ def df_to_postgres_table(
Create a table for the data frame, insert all the values, and return the table schema
"""
with _get_conn(config) as conn, conn.cursor() as cur:
cur.execute(df_to_create_table_sql(df, table_name))
cur.execute(_df_to_create_table_sql(df, table_name))
psycopg2.extras.execute_values(
cur,
f"""
Expand Down