Skip to main content

Introduction to Saver

The Saver is used for saving SFrames into the database. This functionality is particularly useful when working with feature views. By utilizing the Saver, you can ensure that the transformed and processed data is securely stored in the database for future access, analysis, or further processing.

How It Works

The Saver uses the SaveConfig dataclass, which accepts a list of configs. Each config specifies the configuration for a table and an SFrame.

Example of SaveConfig

To save an SFrame to a database, you need to define the save configurations and then create a saver instance with those configurations.

from seshat.source.saver.base import SaveConfig
from seshat.source.saver.database import Saver
from seshat.transformer.schema import Schema
from seshat.transformer.schema import Col


saver = Saver(
url="postgresql://db_admin",
save_configs=[
SaveConfig(
sf_key="sf name",
table="table name",
strategy="update",
schema=Schema(
cols=[
Col("address", is_id=True),
Col("contract_address", "token", is_id=True),
Col("symbol"),
Col("score", dtype="Double", update_func="replace")
],
),
indexes=["address"],
)
]
)

By calling the saver instance, the saving process will start.

SaveConfig Components

  • sf_key: This key is used to specify which frame in a GroupSFrame is being saved.
  • table: This parameter defines the table name in the database where the data will be saved. It is crucial to ensure that this table exists in the database schema.
  • schema: The schema parameter is an instance of the Schema class, which defines the columns and their types that will be saved.
  • strategy: The strategy defines how the data will be saved. Common strategies include "update" and "insert". In this example, the "update" strategy is used, meaning that existing records will be updated with the new data.

Benefits of Using Saver

  • Data Integrity: Ensures that the transformed and processed data is securely stored in the database.
  • Flexibility: Supports various saving strategies such as "update" and "insert".
  • Scalability: Can handle multiple SFrames and configurations, making it suitable for complex data workflows.
  • Consistency: Maintains a consistent approach to saving data, integrating seamlessly with feature views and other data processing components.

By understanding how to configure and use the SaveConfig and Saver, you can effectively manage the storage of your processed data, ensuring it is readily available for future use and analysis.