context
Previously known as materialization_context()
(deprecated).
Summary​
Used as an argument in a transformation. Provides materialization context
start_time
and end_time
for BatchFeatureView
and StreamFeatureView
.
Provides realtime context request_timestamp
for RealtimeFeatureView
.
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
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):
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")
"""