Skip to content

fs-dataset

Resolve feature versions and build a denormalised dataset view.


name: "Feature Store: Dataset" description: "For a developer who needs generated Python code. Generate code to explore available entities and features in the tdfs4ds feature store, select specific feature versions, and build a denormalised snapshot view ready for model development. Invoke when the user wants to build or refresh a dataset view. SKIP when the user is asking which existing datasets contain a feature (use ca-dataset) or wants a conversational agent-driven creation flow (use ca-build-dataset)." argument-hint: "[entity-name][feature-list] [dataset-view-name]" allowed-tools: "Read, Edit, Write, Bash, Glob, Grep"


Generate Python code to explore the tdfs4ds feature store, select feature versions, and build a denormalised snapshot dataset view.

User context: $ARGUMENTS

Step Skill Why
Before fs-upload Features must be registered before a dataset can reference them.
Inspect fs-inspect List entities, features, processes, and follow-up runs to pick what to include.
After fs-document Document the dataset (document_dataset_incremental) so it appears in the consumer agent.
After fs-lineage Visualise where the dataset's features come from.

Demos: demos/notebooks/03 - Build a Dataset.ipynb (snapshot, join types, grouped) and 06 - Datasets in time.ipynb.

Choose the time of the dataset

The store keeps every value with its validity period, so a dataset can be read at any date. This is what keeps a training set honest. Demo store: customer 1606 made their last purchase on 29 May 2023. Read at the latest business date (31 Oct) the dataset says 155 days since the last purchase; as of 30 June it says 32. A churn model labelled at the end of June must see 32: the current value contains four months that came after the label (leakage).

Mode Call Returns Use it for
Current build_dataset(...) the latest values scoring now, dashboards
Frozen build_dataset(..., as_of='2023-06-30') the values valid at that instant; entities that did not exist yet are absent a reproducible training set at a label date
Moving build_dataset(..., time_manager=tm) the values at the TimeManager's current date; tm.update() moves the view, no rebuild backtesting over many dates; scoring at the scheduler's business date
History build_historical_dataset(..., start=, end=) one row per entity and period of constant values (ValidStart included, ValidEnd excluded) sequence models, survival, point-in-time joins with labels

Real outputs on the demo store (DS_CUSTOMER_MONTHLY current vs DS_CUSTOMER_2023_06 as of 30 June): customer 9795, still buying, has 124 purchases in the current dataset and 71 in the June one; customer 26371, first purchase on 10 July, has no row in the June one. The moving dataset returns 1,562 / 1,911 / 1,958 customers with the cursor on 31 March / 30 June / 31 October. At any instant the history equals the as_of dataset (checked: 0 rows differ).

The dataset a process creates itself (upload_features(..., dataset_view_name=...)) follows the process's manager by default when it has one (0.3.7.19; the domain clock when the process reads a soft clone of it; dataset_time_manager=False keeps it current); an existing current one is converted with rebuild_dataset(..., time_manager=tm, replace=True). tdfs4ds.dataset_time_managers() lists which manager each dataset follows (clock / clone / own). A new dataset from an existing one with another grouping, join or valid time: rebuild_dataset('db.ds', target_view_name='DS_V2', grouped=True) (or as_of= / time_manager= / current=True / a history window); the source is not changed.

With a domain clock (0.3.6.0, set_domain_time_manager), let the dataset follow the clock (time_manager='<DATABASE>.<CLOCK>'): roll_out(data_domain=...) moves it with every process's clone. The admin app's dataset builder lists the domain clocks first.

Use the same TimeManager for the processes and a moving dataset: then features and dataset agree on the date (see fs-rollout).

Read a dataset at a business date (no view, no cursor)

To see a registered dataset at one business date, do not move a shared TimeManager and do not build a view:

rows = tdfs4ds.read_dataset('<DATABASE>.<DATASET>', as_of='2024-03-31')                  # teradataml DataFrame
rows = tdfs4ds.read_dataset('<DATABASE>.<DATASET>', as_of='2024-03-31', as_pandas=True)  # one raw statement
one  = tdfs4ds.read_dataset('<DATABASE>.<DATASET>', as_of='2024-03-31', entity={'CUSTOMER_ID': 42})
sql  = tdfs4ds.dataset_sql('<DATABASE>.<DATASET>', as_of='2024-03-31')                   # the SQL text only
  • Stateless: the dataset's own query (read from the view, else rebuilt from the catalog) with its valid time replaced by AS OF <date>. No DDL, no cursor moved; lags/leads, grouped and nested datasets work. A historical dataset is refused (filter the history view: WHERE ValidStart <= d AND ValidEnd > d).
  • A bare date is a business date. It is read at midnight in the zone the store's dates are written in: the zone of the dataset's TimeManager calendar, else the domain clock's, else +00:00. build_dataset(as_of='2024-03-31') reads it in the SESSION's zone. A calendar of type DATE or TIMESTAMP without a zone stores no zone (its dates were stamped in the session zone of the run): the date is then read in the session zone, like the manager's own cursor. A timestamp with an offset ('2024-03-31 00:00:00+02:00') is used as given.
  • entity= takes {column: value} (or a list of such dicts) and pushes the key into every storage-table read.

Features stored with a wider entity key (primary index grain)

The pattern in one line: one key list for the grain, a wider entity_id only to segment or partition: upload_features(..., entity_id=['KEY', 'BUCKET'], primary_index=['KEY']), then build_dataset(entity_id=['KEY'], ...).

A process may add columns to entity_id only to segment (a FilterManager) or to partition. Its primary index stays the real grain, e.g. entity_id=['CUSTOMER_ID', 'ENTITY_BUCKET'], primary_index=['CUSTOMER_ID']. A dataset keyed on exactly the primary-index columns uses such a feature, with no new parameter:

build_dataset(entity_id=['CUSTOMER_ID'], selected_features=['amount', 'visits'], view_name='DS_CUSTOMER')
  • A feature stored at exactly the dataset's entity always wins; a feature whose primary index is not exactly the dataset's entity is not found (the error names it and its primary index).
  • Before the view is created ONE statement checks that every such feature has one value per CUSTOMER_ID (at the dataset's valid time; over the whole history for a historical dataset, a TimeManager or lags/leads). A feature that is not unique refuses the build with its count and an example; an unreadable table refuses it too.
  • The check reads through the statistics on (primary index, FEATURE_ID); on a table created before 0.3.7.35 add them with tdfs4ds.check_storage_statistics(tables=[...], add_missing=True).
  • Data changes after the build: the opt-in dataset_rows part of the sanity check re-runs the same statement (dataset_grain_not_unique). The admin app's dataset builder shows these features with the badge "stored with ENTITY_BUCKET, read at CUSTOMER_ID".

Features at several entity levels (nested entities)

Features of one domain often sit at entities that include one another: amount at CUSTOMER_ID, units at (CUSTOMER_ID, PRODUCT_ID), price at PRODUCT_ID. Key the dataset on the LONGEST entity; there is no new parameter, a feature stored at a subset of the entity is simply selected:

build_dataset(entity_id=['CUSTOMER_ID', 'PRODUCT_ID'], selected_features=['units', 'amount', 'price'],
              view_name='DS_SALES', join_type='FULL OUTER')
  • Which rows. The keys of the features stored at the full entity (units), combined with join_type exactly as without coarser features. A coarser feature never adds a row: LEFT JOIN under FULL OUTER (a key without a value gets NULL), INNER JOIN under INNER. Its value repeats on every row sharing its key.
  • Refused. A selection with no feature at the full entity (a cross join is never built), a feature whose entity is not a subset of the dataset's (stock at (PRODUCT_ID, STORE_ID): the error names where it is stored), and, for a historical dataset, join_type='FULL OUTER' or lags/leads with a coarser feature (history INNER works; use a snapshot for the others).
  • Same name at several levels. The full entity wins; give a process id to pick another level (never two levels of one feature).
  • Primary index grain still applies at each level: a feature stored (CUSTOMER_ID, BUCKET) with primary index CUSTOMER_ID can be the coarser feature of a (CUSTOMER_ID, PRODUCT_ID) dataset; its uniqueness check runs once, as above.
  • Offsets, aliases, as-of, TimeManager, grouped and batch lookups (retrieve_batch) work per sub-query. The view's DDL stays the authority: parse_dataset_ddl, rebuild_dataset, build_grouped_dataset and restore_dataset_catalog read each feature's level back from it. The catalog records the full entity.
  • In the admin app's dataset builder the entity lists "+ N from coarser levels"; they appear in a group From coarser levels with the columns they join on, the page says which rows the dataset has and how they attach, and a refusal shows before Create.

Several versions and column names (aliases)

A feature computed by several processes has several versions (FEATURE_VERSION = the process). Put them side by side, and name any column, through the version value of selected_features:

selected = {'amount': [{'process_id': pid_v1, 'alias': 'amount_old'},
                       {'process_id': pid_v2, 'alias': 'amount_new'}],
            'churn': {'process_id': pid_c, 'alias': 'churned'},       # one version, renamed
            'nb_transactions': pid_tx}                                 # unchanged form

Without alias the names are the historical ones (<feature>, or <feature>_<process view> for several versions). An alias must be a plain identifier and unique (refused otherwise, never renamed); offsets are suffixed to it.

Lags and leads (forecasting, autoregressive inputs)

feature_offsets reads a feature at other instants than the dataset's own, in every mode above (and in build_historical_dataset). Each offset is a column; the same feature can appear several times:

tdfs4ds.build_dataset(['CustomerID'], {'amount': pid_a, 'churn': pid_c}, 'DS_CHURN_TRAIN',
                      time_manager=tm,
                      feature_offsets={'amount': ['0', '-1 day', '-7 days', '-1 month'],   # lags (inputs)
                                       'churn':  ['+1 month']})                            # lead (target)
# CustomerID, amount, amount_LAG_1D, amount_LAG_7D, amount_LAG_1MO, churn_LEAD_1MO
  • The sign is required: '-1 day' = the value one day BEFORE the instant (lag), '+1 month' = one month AFTER (lead), '0' = the instant (listing a feature drops its plain column unless '0' is listed).
  • Units: year, month, week, day, hour, minute, second; ISO '-P1D' works. Months are calendar months (ADD_MONTHS). No fractions of a second: valid periods are stored to the second.
  • A lead is NULL until its instant is reached (database time): an open stored period is not an observation of the future. So a CURRENT snapshot cannot carry a lead (refused with INNER); use as_of, a TimeManager or a history. The cut-off is real time, not the last business date: on a store replaying past dates, end the window one horizon before the last business date (a lead after it reads the last stored value).
  • Default offset_strategy='PIVOT' reads each storage table once for all its offset columns (measured: 32 columns as fast as 8 plain grouped ones); don't suggest 'PER_OFFSET' (31 s parse on 32 columns).
  • Traced: tdfs4ds.get_dataset_offsets() (one row per offset column); rebuild_dataset, restore and migration keep the offsets; documentation gives each column its feature's description with "1 day before the dataset's instant —" in front.
  • For model work: split train/test by time (ValidStart of a history, or the TimeManager dates), score with the same dataset without its lead columns. See docs User guide → Lags and leads.
  • Train / score / monitor recipe (worked end to end in the repo's notebook dev/propensity):
  • training: build_historical_dataset(..., end=<training date>) with lags as inputs and a +1 month lead as the label; the window ends at the training date so every lead is known; drop the rows whose lead is NULL;
  • scoring: build_dataset(..., time_manager=tm) with the same lags and no lead, so it follows the business date of each run;
  • monitoring: a snapshot with a lag on the stored score next to the realised label.
  • Join type with offsets (snapshot and history alike; the dataset is correct, the choice is yours):
  • FULL OUTER keeps an entity as soon as one column has a value, so two kinds of row appear: an entity new at the instant has NULL lag columns (it had no value then), and an entity that had a value at a lag instant but none now has NULL current columns. A view feeding a model (e.g. an ONNX/BYOM scoring process) usually COALESCEs the lags with the convention used at training and keeps only rows with current values (WHERE <current feature> IS NOT NULL);
  • INNER keeps only entities with a value at every instant: new entities are silently dropped;
  • monthly lags: use a TimeManager on month starts (see fs-rollout: ADD_MONTHS clamps month ends).

Ask for any missing values before generating code: - Entity name — the entity whose features go into the dataset (e.g. 'CustomerID'). - Feature list — names of the features to include. - Dataset view name — name for the output Teradata view (e.g. 'DATASET_CUSTOMER'). - Comment — optional description stored in the dataset catalog. - Point-in-time — current state (default), a fixed date (as_of='2024-03-31'), or a TimeManager the dataset should follow (time_manager=tm). - Join type — 'INNER' (default, keeps only entities that have every selected feature) or 'FULL OUTER' (keeps all entities, NULL for missing features). - Grouped strategy — suggest grouped=True when the dataset has many features (> ~10) that share the same source table; it collapses N JOINs into one sub-query per (table, version) group using MAX(CASE WHEN) pivoting, which reduces JOIN fan-out and often improves EXPLAIN scores significantly.

Emit the following pattern, substituting real values for every <PLACEHOLDER>:

import tdfs4ds                                  # reads the TDFS4DS_* settings of .env
tdfs4ds.reconnect_teradata(raise_error=True)    # teradataml context from TDFS4DS_TD_HOST / _USERNAME / _PASSWORD
tdfs4ds.connect(database='<DATABASE>')
tdfs4ds.select_data_domain('<DATA_DOMAIN>')
import teradataml as tdml


# ---------------------------------------------------------------------------
# 1. Discover available entities and features
# ---------------------------------------------------------------------------
from tdfs4ds.feature_store.feature_query_retrieval import (
    get_list_entity,
    get_available_features,
    get_feature_versions,
)

get_list_entity()

entity = '<ENTITY_NAME>'
get_available_features(entity_id=[entity])

# ---------------------------------------------------------------------------
# 2. Choose the features
#    Names alone: build_dataset finds each feature's version (one catalog query).
#    A feature computed by several processes needs its version: build_dataset
#    then raises FeatureSelectionError with the processes and the dict to write,
#    e.g. {'<FEATURE_1>': '<process uuid>', '<FEATURE_2>': None}.
#    get_feature_versions(entity_name=entity, features=[...]) lists the versions.
# ---------------------------------------------------------------------------
feature_selection = ['<FEATURE_1>', '<FEATURE_2>', '<FEATURE_3>']

# ---------------------------------------------------------------------------
# 3. Inspect the generated DDL before creating the view (optional)
# ---------------------------------------------------------------------------
# sql = build_dataset(
#     entity_id=[entity],
#     selected_features=feature_selection,
#     view_name='<DATASET_VIEW_NAME>',
#     return_query=True,   # returns DDL string without executing
# )
# print(sql)

# ---------------------------------------------------------------------------
# 4. Build the dataset view
# ---------------------------------------------------------------------------
from tdfs4ds import build_dataset

dataset = build_dataset(
    entity_id=[entity],
    selected_features=feature_selection,
    view_name='<DATASET_VIEW_NAME>',
    comment='<DESCRIPTION>',
    # join_type='INNER',    # default — drop entities missing any feature
    # join_type='FULL OUTER',  # keep all entities, NULL for missing features
    # grouped=False,        # default — one sub-query per feature (classic multi-join)
    # grouped=True,         # recommended for wide datasets: MAX(CASE WHEN) pivot
    #                       # reduces N JOINs to N_distinct_(table,version) groups
    # as_of='2024-03-31',   # frozen at a date (ISO string, datetime, date, pd.Timestamp)
    # time_manager=tm,      # follows a TimeManager: tm.update(i) moves the dataset
)

dataset
dataset.shape

# Grouped copy of an existing dataset (same rows, shorter SQL), or the same
# dataset at another date — built from the view's own DDL:
# tdfs4ds.build_grouped_dataset('<DATASET_VIEW_NAME>')            # -> <name>_GROUPED
# tdfs4ds.rebuild_dataset('<DATASET_VIEW_NAME>', target_view_name='<NEW_NAME>', as_of='2023-12-31')

# ---------------------------------------------------------------------------
# 5. Historical dataset (optional) — one row per entity per period of
#    constant values: <entity>, ValidPeriod, ValidStart, ValidEnd, <features>
# ---------------------------------------------------------------------------
# from tdfs4ds import build_historical_dataset
# history = build_historical_dataset(
#     entity_id=[entity],
#     selected_features=feature_selection,
#     view_name='<DATASET_VIEW_NAME>_HISTORY',
#     # no window argument          -> full history up to now
#     # start='2024-01-01', end='2024-04-01'   -> fixed window, end EXCLUDED
#     # duration='12 months'                   -> last 12 months, slides with time
#     # duration='12 months', delay='1 day'    -> [now - 1 day - 12 months, now - 1 day)
#     # join_type='FULL OUTER'                 -> keep periods where only some features exist
# )
# history[history.CustomerID == 42].sort('ValidStart')

# Check / repair the dataset catalog (dry run unless dry_run=False). Run it once with dry_run=False on a store
# with datasets built before 0.3.7.35: it records their columns, so their views can be rebuilt later:
# tdfs4ds.restore_dataset_catalog()

# Recreate a dataset view that was dropped, from the catalog alone (dry run returns the DDL):
# tdfs4ds.rebuild_dataset_view('<DATABASE>.<DATASET_VIEW_NAME>', dry_run=False)
# or every lost view at once: tdfs4ds.restore_dataset_catalog(recreate_views=True, dry_run=False)

# Remove a dataset (defective, or no longer wanted) from the catalog, with its
# documentation, index entries and lineage; dry run first, view kept by default:
# tdfs4ds.remove_dataset('<DATABASE>.<DATASET_VIEW_NAME>')
# tdfs4ds.remove_dataset('<DATABASE>.<DATASET_VIEW_NAME>', dry_run=False)            # drop_view=True also drops the view

# Reuse in future sessions without rebuild:
# dataset = tdml.DataFrame(tdml.in_schema('<DATABASE>', '<DATASET_VIEW_NAME>'))

Training and scoring data from the store

A project that builds its model data by hand usually shows one of these. Each has a framework form:

The project does Why it is a problem Replace with
a loop of build_dataset(..., as_of=date), one view per snapshot date N views of the store; the label is then joined by hand from the next date's view one build_historical_dataset read at each snapshot instant, the label as a lead
the label read by joining the next date's dataset the offset between inputs and label is hidden in SQL and easy to get wrong for one date feature_offsets={'<LABEL>': ['+1 month']}
every feature of the entity copied into a training table a wide, expensive read for a model that keeps a fraction of it; a copy that drifts from the store select on a snapshot, train on a history of the selected features, read views, not a table
QUALIFY ROW_NUMBER() to drop extra rows of one entity it hides a defect an entity on several rows at one instant is a finding: report it, never filter it away

1. Select on a snapshot. Read every candidate feature once, at one or two dates, for a sample of entities (all positives and some negatives), and run the model project's feature gate (NULL share, near-duplicates, stability) on that result. Per-feature statistics need no wide join:

snap = tdfs4ds.build_dataset(['<ENTITY>'], CANDIDATES, '<DATABASE>.DS_SELECTION',
                             as_of='<SNAPSHOT_DATE> 12:00:00', join_type='FULL OUTER', grouped=True)
stats = tdfs4ds.feature_extremes('<FEATURE>', entity='<ENTITY>', as_of='<SNAPSHOT_DATE> 12:00:00')

2. Train on a history of the selected features. The label is a lead, a source that arrives late is a lag, and no second dataset is joined:

tdfs4ds.build_historical_dataset(['<ENTITY>'], SELECTED, '<DATABASE>.DS_TRAIN_HISTORY', join_type='FULL OUTER',
                                 start='<FIRST_SNAPSHOT>', end='<LAST_OUTCOME_DATE>',
                                 feature_offsets={'<LABEL>': ['+1 month'], '<LATE_FEATURE>': ['-1 month']})

A training row is the history at one instant of each snapshot date: WHERE ValidStart <= TIMESTAMP '<SNAPSHOT> 12:00:00' AND ValidEnd > TIMESTAMP '<SNAPSHOT> 12:00:00'. Read at noon, never at midnight: a bare date is midnight, and a time-zone shift moves it onto the previous day. Sample with a deterministic view over the history (for example QUALIFY ROW_NUMBER() OVER (ORDER BY HASHROW(<key>, <seed>)) <= n).

When a snapshot is frozen at a date (training or scoring), put first the feature that defines the population, so each entity appears once.

3. Score with the same offsets on a snapshot at the scoring date (as_of=, or time_manager= to follow the clock), with the lags and without the lead.

4. Keep a model record instead of a training table: the window, the features with their process ids, the offsets, the sampling seed. The process versions behind the window come from tdfs4ds.history_versions('<DATABASE>.DS_TRAIN_HISTORY'); process_version=True is refused when the history has offsets.

Time alignment. - Features are aligned when every process runs on the domain clock: at any instant each one shows the value of the same business date (fs-rollout). - A missing date breaks it silently: a snapshot or a history then shows that process's previous value. Before reading, check that follow_up_report(process_id=...) has a COMPLETED row for every process at every date of the window and at the outcome date. - A source that arrives after the scoring run is read with the same lag in training and in scoring. Take the list from the scoring run's freshness check and store it with the model. - A lead exists only in the past, so the last business date is an outcome date, never a training snapshot.

Depth and cost. - The depth is bounded by the dates the clock holds, minus the outcome horizon, and by how far back the sources go: the oldest date needs its whole look-back window. - Choose the depth like any model decision: enough positives per snapshot, stable rates, and no regime change inside the window. history_versions shows whether the window spans several process versions, that is, a logic change. - With a history, more depth is only an earlier start. The cost grows with the number of value changes in the window and with the number of features, so keep the history to the selected ones. - A FULL OUTER history joins each feature on the cut timeline, and a grouped snapshot of a few hundred features is still a large query. - Every read of a wide view runs it again: read it once (for a sample of entities) and work on the result. Check pruning with EXPLAIN on the real store, and measure timings at production size (a trial system gives correctness, not timings).

Checks before switching (with fs-modernize-verify): one row per entity at each instant; at each snapshot the history equals build_dataset(..., as_of=...); the lead equals the next date's value and the lag the previous one; every process COMPLETED at every date. A different population rule (for example "absent next month" read as "no row next month" versus "the lead is NULL") is a business decision, not a detail.

Dataset builder (admin app, Explore › Dataset builder)

The same build without code: choose an entity, tick features (several versions of a feature are offered when several processes compute it), then the kind (current / as of / TimeManager / history window) and the join type. - Per feature: a Lags / leads field (0, -1 day, +1 month, presets) and a column-name field per chosen version (the alias). The resulting column names are shown as you type; a bad offset or name is shown in red and blocks creation. - Show SQL renders the view's SQL; Sample 20 rows runs it on 20 rows; neither creates anything. - Show Python (0.3.4.0) gives the tdfs4ds.build_dataset / build_historical_dataset call that Create dataset makes for the same form, preceded by the connection and DATA_DOMAIN, with one explanation per argument and a Copy button. The password is never written (the code asks with getpass). Point a user who designed a dataset in the app and wants it in a notebook or a scheduled job here, rather than retyping the selection by hand. - Create dataset checks the name again (an existing dataset or object is never replaced), creates the view, registers it and records its lineage; Document it adds the LLM documentation when a model is configured. - The panel needs a feature store selected: without one it says "No feature store is selected" (Settings › Parameters, or TDFS4DS_SCHEMA).

Serve rows for a list of keys

Scoring or an application needs the dataset's rows for given entities, not the whole view:

rows = tdfs4ds.retrieve_batch('<DATABASE>.<DATASET_VIEW_NAME>',
                              [(1001,), (1002,), (1003,)])     # one tuple per entity, in entity-column order
# method='auto' (default): an IN list for small batches, a volatile key table joined on the storage
# tables' primary index for large ones (keys sent as data: no SQL-size limit). columns=[...] selects features.

The keys are pushed into every storage-table read (pushdown='auto'), so a batch reads only its entities' rows. To measure what serving costs on this system (single key, batches, concurrency, time travel), run report = tdfs4ds.run_benchmark('<DATABASE>.<DATASET_VIEW_NAME>') and write it with tdfs4ds.write_benchmark_report(report) (HTML). It stops early when the view alone takes longer than max_parse_ms (default 5 s) to parse.

Join a dataset with a documented table or view

A dataset only holds features. To put the columns of a reference table, a customer master or a label table next to them, find the objects that carry the dataset's key and build an ordinary view over the dataset (it is not a feature-store dataset: no dataset-catalog row).

# 1. The tables and views documented in the business dictionary or attached to the feature store
#    whose real columns hold the dataset's entity columns (never a scan of the databases).
candidates = tdfs4ds.find_joinable_objects(dataset='DS_CUSTOMER_SPEND')          # MATCH full / subset
candidates = tdfs4ds.find_joinable_objects(dataset='DS_CUSTOMER_SPEND', purpose='fiber loss')   # narrowed on the documentation
print(candidates[['OBJECT_NAME', 'MATCH', 'JOIN_COLUMNS', 'UNIQUENESS', 'ACCESS', 'COLUMN_MEANINGS']])

# 2. Optional: are the join columns unique in the object? Dictionary first; the count runs only after its
#    EXPLAIN stays within the sample limits (state 'not_verified' above them, unless force=True).
tdfs4ds.check_join_uniqueness('SRC.CUSTOMER_MASTER', ['CUSTOMER_ID'])

# 3. The SQL first (nothing is created), then the view.
tdfs4ds.create_joined_view('DS_CUSTOMER_SPEND', 'SRC.CUSTOMER_MASTER', 'DS_CUSTOMER_SPEND_JOINED',
                           columns=['SEGMENT'], return_query=True)['sql']
tdfs4ds.create_joined_view('DS_CUSTOMER_SPEND', 'SRC.CUSTOMER_MASTER', 'DS_CUSTOMER_SPEND_JOINED',
                           columns=['SEGMENT'], check_unique=True, attach=True)
  • The dataset drives (LEFT JOIN); it keeps its own valid time, versions and offsets. The outside object is read as it is now. A temporal object is refused.
  • Check that the join columns mean the same thing in both objects: a name match is not a meaning match (COLUMN_MEANINGS).
  • Uniqueness is opt-in (check_unique=False reads no row): without proof of a unique index a warning says rows may multiply. check_unique=True refuses duplicates.
  • A column colliding with a dataset column needs aliases={'COL': 'NEW_NAME'}. The view name may not be a dataset's or a process view's.
  • attach=True (default) attaches the view to the feature store: lineage, documentation, removal guards, the agent. A process can then read it (upload_features(sql_query='SELECT ... FROM <view>')).
  • Admin app: Build › Dataset builder, Join with a table or view…; chat: "which tables can I join with <dataset>?" (the agent lists, it does not create).

Rules

  • Value types that MAX() refuses (PERIOD, ST_GEOMETRY and other user-defined types, legacy XML): grouped=True and the lag/lead pivot aggregate with MAX(CASE ...), so since 0.3.5.17 a dataset holding such a feature is built multi-join and/or with one sub-query per lag/lead column, with a warning naming the features (before, the view creation failed with Error 6976 / 6945). Nothing changes for other types.

  • A dataset is a view over the feature store's tables, never a copy: it costs no storage, and two datasets sharing a feature always read the same values. Build one dataset per usage (training, scoring, a dashboard) rather than one wide dataset for everything.

  • selected_features is the list of feature names; write a version ({feature: '<process uuid>' | None}) only for a feature several processes compute. Never invent a process uuid: take it from the FeatureSelectionError message or get_feature_versions(). With read-only stores attached, only the first store holding a feature counts: the same feature in two stores raises nothing, and get_feature_versions() lists the first store's versions. To read a later store's version, take its process id from process_catalog() (FEATURE_STORE column).
  • build_dataset creates a view, not a table. By default it reads CURRENT VALIDTIME; pass as_of= for a fixed date or time_manager= to follow a TimeManager (mutually exclusive). Setting tdfs4ds.FEATURE_STORE_TIME alone does NOT time-travel a dataset — it needs feature_store_time=True; prefer as_of=.
  • as_of accepts ISO strings, datetime, date, pandas.Timestamp; a bare date means midnight. Never hand-format the literal.
  • Multiple entities cannot be combined in one build_dataset call — join the resulting views manually.
  • All catalog queries are scoped to DATA_DOMAIN — always set it before querying.
  • Use grouped=True for wide datasets (many features from the same source table). It shortens the view SQL and so the parse/optimise time paid on every query (measured: 10 features, 5.8k -> 3.0k chars, EXPLAIN 627 -> 190 ms, single-entity lookup ~455 -> ~248 ms), with exactly the same rows. The gain shrinks when every feature comes from a different table/process.
  • To convert an existing dataset, use build_grouped_dataset / rebuild_dataset — they reuse the view's own DDL, so nothing depends on DATA_DOMAIN.
  • Use join_type='FULL OUTER' only when downstream models tolerate NULL feature values. Default 'INNER' is safer — it drops entities that lack any selected feature, keeping the dataset clean.
  • Use return_query=True to review the generated DDL before running it — useful for performance review or when working with fs-analyze.
  • Use build_historical_dataset when the model needs how features evolved (sequences, survival, point-in-time training rows over many dates), not just their value at one instant. It is a view too; now is evaluated at query time, so a duration/delay window slides by itself. INNER keeps a period only where every feature has a value, FULL OUTER every period where at least one has — at any instant the history equals build_dataset(as_of=<instant>) with the same join type. FULL OUTER costs about twice the time of INNER. No grouped option for histories. Its window is in the catalog: tdfs4ds.get_dataset_window() (FS_V_FS_DATASET_WINDOW, LEFT OUTER JOIN on DATASET_ID; snapshots have no row) gives the definition and WINDOW_START/WINDOW_END, the bounds at query time (WINDOW_START NULL = from the earliest value).
  • A dataset can stay in the catalog after its view was dropped, or after an object it reads went away. In the admin app (Dataset builder › Existing datasets) a failed sample or Check all marks it Defective with the cause; Remove from catalog (admin view) previews then removes it. In Python: tdfs4ds.remove_dataset(name) — drop_dataset(dataset_id) removes only the catalog rows and leaves its documentation and index entries behind. Since 0.3.3.27 remove_dataset(..., dry_run=False) refuses when process views read the dataset (DependentObjectsError, dependents in removal order); tdfs4ds.write_removal_script(tdfs4ds.plan_removal(['<db>.<dataset>'])) removes them in order.
  • For hyper-segmented ML: to make a partition column (e.g. region) available in the dataset, it must have been registered as a feature at upload time — SELECTed in the view SQL and listed in feature_names in upload_features(). Once registered, include it in get_feature_versions() like any other feature; no manual join to the source table is needed.