Skip to content

← Tutorials overview

10. Catalogs and datasets

Reference

The reference for this topic is Datasets.

Everything registered in the previous modules (features, processes, datasets) lives in one of three catalogs. They are what makes tdfs4ds a feature store rather than a pile of views: they record what was registered, when, and with which versions.

import dataclasses
import getpass
import os

import tdfs4ds                      # importing it first also loads a .env file, if you have one
import teradataml as tdml

# 1. Open the Teradata session. Host and user come from the environment (TDFS4DS_TD_HOST,
#    TDFS4DS_TD_USERNAME), the password from TDFS4DS_TD_PASSWORD or a prompt: nothing secret
#    is written on this page.
host = os.environ["TDFS4DS_TD_HOST"]
user = os.environ["TDFS4DS_TD_USERNAME"]
password = os.environ.get("TDFS4DS_TD_PASSWORD") or getpass.getpass("Teradata password: ")
tdml.create_context(host=host, username=user, password=password)

# 2. Pick your industry. This is the ONLY line to change: retail, banking, healthcare, pharma,
#    manufacturing, assembly, energy or transportation. Every name below comes from S.
S = tdfs4ds.tutorial_scenario("retail")

# 3. Connect to the feature store (created when missing) and choose a data domain. disposable=True
#    records that this domain is an experiment, so the last page removes it in one call.
DATABASE = os.environ.get("TDFS4DS_TD_DATABASE") or user
tdfs4ds.connect(database=DATABASE, create_if_missing=True)
tdfs4ds.create_data_domain(f"TUTORIAL_{S.name.upper()}", disposable=True)   # an experiment: removable in one call

# 4. The tutorial data: three tables written once; a second run keeps them.
try:
    S = tdfs4ds.create_tutorial_data(S.name, DATABASE)
except ValueError:
    S = dataclasses.replace(S, database=DATABASE)


def register_entity_features():
    """Page 1 in one call: (re)register the entity features and return the process id."""
    sql = f"""
        SELECT {S.entity}, COUNT(*) AS nb_events, SUM({S.amount}) AS total_amount,
               AVG({S.amount}) AS avg_amount, COUNT(DISTINCT {S.partner}) AS nb_partners
        FROM {S.table('events')}
        GROUP BY 1"""
    return tdfs4ds.upload_features(
        df=None, sql_query=sql, target_view_name=f"{S.database}.{S.name}_entity_features",
        entity_id=[S.entity], feature_names=["nb_events", "total_amount", "avg_amount", "nb_partners"],
        replace=True, document=False, optimize_query=False, return_process_id=True)

process_id = register_entity_features()
dataset = tdfs4ds.build_dataset(
    entity_id=[S.entity],
    selected_features=["nb_events", "total_amount", "avg_amount", "nb_partners"],
    view_name=f"{S.database}.{S.name}_entity_dataset",
)

You should see a process id and the dataset built (about 2,000 rows), as in the first dataset page.

The three catalogs

features = tdfs4ds.feature_catalog(as_pandas=True)
processes = tdfs4ds.process_catalog(as_pandas=True)
datasets = tdfs4ds.dataset_catalog(as_pandas=True)

print(features[["DATA_DOMAIN", "ENTITY_NAME", "FEATURE_NAME"]])
print(processes[["PROCESS_ID", "VIEW_NAME"]])
print(datasets[["DATASET_ID", "DATASET_NAME"]])

Output with scenario='retail' after the modules 6 to 9 (shortened to the first rows of each; the order is not fixed): the features of the domain (the four entity features, plus those of the modules you ran), the processes with their views, and the datasets.

       DATA_DOMAIN               ENTITY_NAME           FEATURE_NAME
0  TUTORIAL_RETAIL         CustomerID,Region       nb_events_region
1  TUTORIAL_RETAIL                MerchantID      partner_nb_events
2  TUTORIAL_RETAIL                CustomerID      nb_events_to_date
...
                             PROCESS_ID                               VIEW_NAME
0  <process id>  "my_database"."retail_bucketed_features"
1  <process id>    "my_database"."retail_region_features"
2  <process id>    "my_database"."retail_entity_features"
...
                             DATASET_ID                   DATASET_NAME
0  <dataset id>          retail_entity_dataset
1  <dataset id>          retail_region_dataset
2  <dataset id>         retail_partner_dataset
...
Catalog Stores Use it to
Feature FEATURE_NAME, ENTITY_NAME, FEATURE_TYPE, DATA_DOMAIN, storage table Discover which features exist and where the values land
Process PROCESS_ID, VIEW_NAME, the SQL, the registered metadata Re-run a feature engineering step, inspect its DDL
Dataset DATASET_ID, DATASET_NAME, DATASET_DATABASE Find a dataset and look up its features

All three are temporal, in real time: a row is valid from the moment it was registered, so VALIDTIME AS OF a past instant shows the store as it was then (an audit). FEATURE_STORE_TIME is a business date for the values; it never moves the catalogs.

What a dataset is, and why it matters

A dataset is a registered view that joins features across the store into one wide table. It is never materialised: the view reads the per-feature storage tables and is evaluated each time it is queried. Four advantages:

  1. Composition. Any subset of features in one build_dataset(...) call.
  2. Versioning. Each feature reference is pinned to a process_id, the version of the logic that produced it; a new process does not change the dataset until you rebuild it.
  3. Time travel. The storage tables are temporal, so every dataset inherits it (as_of=, a TimeManager, a history).
  4. Governance. The dataset catalog is the single source of truth for "which datasets exist and what do they contain".

Look inside a dataset

entry = datasets[datasets["DATASET_NAME"].str.lower().str.contains(f"{S.name}_entity_dataset")].iloc[0]
members = tdfs4ds.get_dataset_features(entry["DATASET_ID"]).to_pandas()
print(members)

Output (6 columns, shortened): one row per feature of the dataset with its feature id (and the version, the process id, in the dataset's view text); here four rows. The Inspect & monitor page covers the rest of the read-only surface.

Two versions of one feature

When two processes compute the same feature name, a dataset needs to say which one:

versions = tdfs4ds.get_feature_versions(S.entity, ["nb_events", "total_amount"])
print(versions)

Output: {feature name: process id}:

{'nb_events': '<process id>', 'total_amount': '<process id>'}

With several processes for one name, build_dataset lists them and you pass the one you want in selected_features.

Clean up

A dataset is dropped with tdfs4ds.drop_dataset(dataset_id); it is a view, so no data is lost. Module 13 lists everything the tutorials create.

Learn more

  • Data model: catalog schemas, hidden-table pattern, how the public views are built on top.
  • Datasets: build_dataset, grouped strategies, time-travel snapshots.
  • Inspect & monitor: read-only catalog helpers and follow-up reports.
  • First dataset: the end-to-end walkthrough.