Sub topic 6
Data sources and event timestamps
A data source tells Feast where the raw feature values live and which column says when each value was true. This chapter covers both parts. It assumes you can read a pandas DataFrame and have read the earlier chapters on entities and on offline and online features. You don't need a running Feast repository yet, because the examples use a local Parquet file.
What a data source is
A data source is a pointer plus a description. The pointer is a file path, a table name or a query. The description names the timestamp columns and, optionally, how source column names map to feature names. Feast doesn't copy the data when you declare a source. It reads the source when you build a training set or materialize features.
Every feature view takes exactly one batch source. The source supplies:
- The entity join key columns, such as
driver_id. - The feature value columns.
- An event timestamp column.
- Optionally, a created timestamp column.
Event timestamps
The event timestamp records when the feature value became true in the real world. It does not record when the row was written. For a feature like conv_rate, it is the end of the hour the rate was computed for.
Feast uses this column in three places:
- Point-in-time joins. For each training row, Feast finds the latest feature value whose event timestamp is at or before that row's timestamp.
- TTL checks. A value is usable only if its event timestamp falls within the feature view's TTL window.
- Materialization windows.
feast materializecopies rows whose event timestamps fall inside the requested time range.
A wrong event timestamp therefore causes wrong training data, not an error. If you store the load time as the event time, the joins stay consistent with themselves but no longer match reality.
The created timestamp
The created timestamp records when the row was written to the source. It matters when two rows share the same entity key and the same event timestamp. That happens when a pipeline reruns or a value is corrected. Feast keeps the row with the later created timestamp.
| Column | Question it answers | Used for |
|---|---|---|
| `timestamp_field` | When was this value true? | Point-in-time joins, TTL, materialization windows |
| `created_timestamp_column` | When was this row written? | Breaking ties between rows with the same key and event time |
If you don't set a created timestamp column, you must make sure the source has at most one row per key and event timestamp. Otherwise the result Feast picks isn't something you can rely on.
A worked example
This script writes a small Parquet file in which driver 1001 has a corrected row. It needs pandas and pyarrow.
from pathlib import Path
import pandas as pd
Path("data").mkdir(exist_ok=True)
df = pd.DataFrame(
{
"driver_id": [1001, 1001, 1001, 1002],
"event_timestamp": pd.to_datetime(
[
"2025-01-01 10:00",
"2025-01-01 11:00",
"2025-01-01 11:00",
"2025-01-01 10:30",
],
utc=True,
),
"created": pd.to_datetime(
[
"2025-01-01 10:05",
"2025-01-01 11:05",
"2025-01-01 11:40",
"2025-01-01 10:35",
],
utc=True,
),
"conv_rate": [0.10, 0.20, 0.25, 0.30],
"acc_rate": [0.90, 0.85, 0.86, 0.70],
"avg_daily_trips": [12, 14, 14, 9],
}
)
df.to_parquet("data/driver_stats.parquet")
print(df)Rows 2 and 3 describe driver 1001 at 11:00. The third row was written at 11:40, after the pipeline recomputed the value. With created_timestamp_column="created" set, Feast uses conv_rate = 0.25 for that hour.
The matching source definition is the one from the topic plan:
from feast import FileSource
driver_stats_source = FileSource(
name="driver_hourly_stats_source",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
)name lets other definitions refer to the source. path is relative to the feature repository directory.
How the timestamps are used
For training, "in range" means the event timestamp is at or before the entity row's timestamp and within the TTL. For materialization, it means the event timestamp falls inside the window you pass to the command.
Common source types
The source class depends on your offline store. The timestamp options work the same way across them.
| Source class | Reads from | Notes |
|---|---|---|
| `FileSource` | Parquet files | Good for local work and tests |
| `BigQuerySource` | A table or a SQL query | Needs the GCP extra |
| `SnowflakeSource` | A table or a SQL query | Needs the Snowflake extra |
| `RedshiftSource` | A table or a SQL query | Needs the AWS extra |
Warehouse sources accept a query instead of a table. This lets you do light cleanup in SQL, but it also makes the source more expensive to scan. Prefer pointing at a table that a transformation job already produces.
Mapping column names
If the source column names differ from the names you want for features, use field_mapping. The keys are source columns and the values are the names Feast exposes.
from feast import FileSource
renamed_source = FileSource(
name="driver_stats_renamed_source",
path="data/driver_stats.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created",
field_mapping={"conv_rate": "conversion_rate"},
)The feature view schema must then use the mapped name, conversion_rate. Mapping is useful when several teams own the source tables and you can't change their column names.
Gotchas
Time zones
Use timezone-aware UTC timestamps everywhere, as the script above does. Mixing naive and aware datetimes, or local time with UTC, shifts values by hours. The shift is silent: joins still succeed, but they pick the wrong rows. Convert at the edge of your pipeline and store UTC.
Event time and load time
If a batch job runs at 02:00 and processes yesterday's data, the event timestamp should be yesterday's time. If you stamp every row with 02:00, a training row at 23:00 yesterday won't see those values. A training row at 03:00 will see them as if they had been known all along, which is label leakage in the other direction.
Late data
A row can arrive after the materialization window that should have included it. Incremental materialization only looks forward from its last run, so a late row with an old event timestamp can be skipped for the online store. It will still appear in historical retrieval, because that path reads the source directly. This is one cause of online and offline values disagreeing, which a later chapter on freshness covers in more detail.
Duplicates without a created timestamp
Two rows with the same key and event timestamp are ambiguous when no created column is set. Deduplicate upstream or add the column.
Missing timestamp column
If the column named in timestamp_field doesn't exist in the source, the error appears when Feast reads the data, not when you declare the source. Run a small get_historical_features call after feast apply to catch typos early.
Checklist for a new source
- Confirm there is one row per entity key and event timestamp, or add a created timestamp column.
- Store event timestamps in UTC.
- Check that the event timestamp means "when the value was true", not "when it was loaded".
- Make sure the join key columns match the entity's
join_keys. - Pull a few rows through
get_historical_featuresand compare them with the raw data.
Exercise
A source has two rows for driver 1005 with the same eventtimestamp of 2025-03-01 08:00 UTC. One has created = 08:10 and convrate = 0.40. The other has created = 09:30 and convrate = 0.45. The source is declared with createdtimestampcolumn="created". Which convrate does Feast use for that hour, and why? What would change if createdtimestampcolumn were not set?
Show answer
Feast uses 0.45, because both rows share the key and event timestamp and the row with the later created timestamp wins. Without a created timestamp column, Feast has no rule to break the tie, so which row it returns can't be relied on. You would need to deduplicate the source upstream.
Exercise
A nightly job at 02:00 recomputes yesterday's driver stats and stamps every row with the job's run time as event_timestamp. Why is this a problem for training data, and what should the event timestamp be?
Show answer
A training row from yesterday at 23:00 cannot see these values, because their event timestamps (02:00 today) are later than the row's time. Rows from later today would treat them as if they had been available all along. The event timestamp should be the time the value describes, for example the end of the hour or day it was computed for. The run time belongs in the created timestamp column.