Skip to main content
Version: 0.9

materialization_context

Summary​

Used as a default value for a Feature View or Transformation with a materialization context parameter.

context.start_time and context.end_time return a datetime.datetime object equal to the beginning and end of the period being materialized respectively. For example for a batch feature view materializing data from May 1st, 2022, context.start_time = datetime(2022, 5, 1) and context.end_time = datetime(2022, 5, 2).

The datetimes can be used in SQL query strings directly (the datetime object will be cast to an atom-formatted timestamp string and inlined as a constant in the SQL query).

Example​

from tecton import batch_feature_view, materialization_context
from datetime import datetime, timedelta


@batch_feature_view(
sources=[transactions],
entities=[user],
mode="spark_sql",
batch_schedule=timedelta(days=1),
feature_start_time=datetime(2020, 10, 10),
)
def user_last_transaction_amount(transactions, context=materialization_context()):
return f"""
SELECT
USER_ID,
AMOUNT,
TIMESTAMP
FROM
{transactions}
WHERE TIMESTAMP >= TO_TIMESTAMP("{context.start_time}") -- e.g. TO_TIMESTAMP("2022-05-01T00:00:00+00:00")
AND TIMESTAMP < TO_TIMESTAMP("{context.end_time}") -- e.g. TO_TIMESTAMP("2022-05-02T00:00:00+00:00")
"""

Was this page helpful?