Skip to content

td-uaf-art

Register a UAF feature that lives in a secondary ART layer (art_sql, art_layers, process type uaf art view).

Source file

Lives at tdfs4ds/skills/td-uaf-art/SKILL.md.


name: "Teradata UAF ART-layer features (process type 'uaf art view')" description: "Generate Python and SQL to register a governed tdfs4ds feature whose value lives in a secondary ART (Analytical Result Table) layer of a Teradata UAF operator, such as ARIMA fit metrics (R_SQUARE, MAPE in ARTFITMETADATA), residual tests over ARTFITRESIDUALS, or TD_PACF, using the 'uaf art view' process type (art_sql + art_layers). Invoke when reaching the value takes two statements: materialise the ART, then TD_EXTRACT_RESULTS over a LAYER. SKIP when the operator's whole result is inline, such as TD_ACF or TD_DICKEY_FULLER (use td-uaf-feature), and for a plain forecast (use td-uaf-forecast)." argument-hint: "[source-table][series-id-column(s)] [row-axis-column][value-column] [operator][layer(s)]" allowed-tools: "Read, Edit, Write, Bash, Glob, Grep"


Generate code to register a UAF feature whose value lives in a secondary ART LAYER — e.g. ARIMA fit-metrics (R_SQUARE, MAPE, AIC in ARTFITMETADATA), residual-adequacy diagnostics over ARTFITRESIDUALS (TD_PORTMAN/Ljung-Box, TD_DURBIN_WATSON, TD_BREUSCH_GODFREY), or TD_PACF — as a governed, run()-recomputable tdfs4ds feature, using the 'uaf art view' process type.

User context: $ARGUMENTS

When to use this skill vs. td-uaf-feature

Situation Skill
The operator's entire result is in its inline output (TD_ACF, TD_DICKEY_FULLER stationarity, …) — one statement, servable from a single view td-uaf-feature (inline EXECUTE FUNCTION in a CTE)
The value lives in a secondary ART layer you must reach with TD_EXTRACT_RESULTS(ART_SPEC(..., LAYER(...))) — two statements (materialise the ART, then extract) this skill ('uaf art view')
A statistical forecast (SARIMA / Holt-Winters point forecast) td-uaf-forecast

A layer-based feature cannot be expressed in a single view: a CTE is not a valid TABLE_NAME, nested EXECUTE FUNCTION as an argument is a syntax error (3706), and ingestion is one CREATE VOLATILE TABLE AS (SELECT * FROM <view>) with nowhere to run the first statement. 'uaf art view' closes that gap.

Before / After Skill Why
Before fs-setup Open the Teradata context and activate a data domain.
Before fs-filter Build the FilterManager if registering per partition (recommended for large series counts / small PERM quota).
Sibling td-uaf-feature Inline-output UAF diagnostics (single view, no ART layer).
Sibling td-uaf-forecast ARIMA/Holt-Winters forecasts (a different output shape).
After fs-document LLM business description (the doc flow reads art_sql/art_layers automatically).

Ask for any missing values before generating code

  • Source table/view — one row per (series, observation).
  • Series ID column(s) — identify the series (e.g. item_id, store_id).
  • Row axis — TIMECODE (a real date/timestamp) or SEQUENCE (an integer offset).
  • Value column — the payload the operator runs on.
  • Operator + layer(s) — which operator produces the ART (e.g. TD_ARIMAESTIMATE) and which LAYER(s) hold the feature (e.g. ARTFITMETADATA for R_SQUARE/MAPE; the info-criteria layer for AIC; ARTFITRESIDUALS fed into a residual test).
  • Partitioned registration? — whether to scope per partition via a FilterManager.

The model: one feature view + art_sql + art_layers

A 'uaf art view' process stores three things:

  1. art_sql — a list of solitary statements that materialise the operator's ART using EXECUTE FUNCTION ... INTO VOLATILE ART(<name>). Session-scoped: no PERM space, no Error 2644 ("No more room"), no cleanup. Stored in the process METADATA (JSON) — no DDL migration.
  2. art_layers — the declared LAYER(...) name(s) the feature view reads. A list (one ART is multi-layer; a feature may span several — e.g. R_SQUARE from ARTFITMETADATA + AIC from the info-criteria layer). Used for documentation + lineage labelling only.
  3. the feature view (view_name) — the ordinary plain feature view, reading each layer via TD_EXTRACT_RESULTS(ART_SPEC(TABLE_NAME(<art>), LAYER(<layer>))), one CTE per layer.

run() for this type, per FilterManager partition: execute art_sql (which creates the volatile ART), then fall through to the existing, unchanged ingestion CTAS. Because art_sql and the CTAS run in the same session, the session-scoped volatile ART is visible to the CTAS's SELECT * FROM <feature view>.

Why this is safe / correct - INTO VOLATILE ART (not INTO ART) → session-scoped, zero PERM, auto-cleaned. tdfs4ds DROPs it before recreating (idempotent re-run / next partition). - Order matters in art_sql — a later statement may read an ART an earlier one created (e.g. a residual test over LAYER(ARTFITRESIDUALS) of an ARIMA fit). Statements execute in list order; never reorder them. - The store filter stays in the series-input view's scalar subquery (partition-aware, no templating — same pattern as td-uaf-feature/fs-filter). art_sql reads SERIES_SPEC(TABLE_NAME(<series-input view>)), so it recomputes for whichever partition the filter currently points at.

⚠️ Creation-time lifecycle constraint (verified live on Vantage 20). A view that references a volatile ART — ... TD_EXTRACT_RESULTS(ART_SPEC(TABLE_NAME(<art>), LAYER(...))) — cannot be REPLACE VIEW-created unless that volatile ART already exists in the session (Error 3807 "Object '' does not exist"). So the setup order is: materialise the ART once (run art_sql[0] for the current filter partition) → then REPLACE VIEW the feature view. The permanent feature view then survives across sessions (SHOW VIEW works), but reading it always needs the ART present — which run()/ingestion guarantees by re-materialising it per partition before the CTAS. (Confirmed end-to-end: same-session read works; a cold read in a fresh session errors until the ART is re-materialised, after which it reads correctly again.) Step 5 below bakes this in.


Full pattern (ARIMA fit-metrics: R_SQUARE + MAPE)

Step 1 — series-input view (carries the FilterManager scalar subquery)

tdml.execute_sql(f"""
REPLACE VIEW {DB}.vw_series_in AS
LOCKING ROW FOR ACCESS
SELECT item_id, store_id,
       ROW_NUMBER() OVER (PARTITION BY item_id, store_id ORDER BY cal_date) AS seq_no,
       sales_qty
FROM {SRC}.sales
WHERE store_id = (SELECT store_id FROM {fm.sql_view})
""")

Step 2 — capture the operator SQL once (to get the ART name + layer column names right)

Run the teradataml wrapper once (with volatile=True) purely to read its show_query() and the layer's result columns — then hand-write the art_sql and the feature view. Confirm the LAYER name and its columns empirically (they vary by operator/output format).

Step 3 — write art_sql (materialise the ART) and the feature view (read the layer)

The grammar below is live-verified on Vantage 20 for ARIMA fit-metrics. Note three things that commonly trip people up: (1) NONSEASONAL(MODEL_ORDER(p,d,q)) — not NONSEASONAL(ARIMA(P(1)...)); (2) CONSTANT and ALGORITHM are required, and FIT_METRICS(1) goes inside FUNC_PARAMS (it is what generates the ARTFITMETADATA layer) — there is no OUTPUT_FMT(FITMETRICS); (3) TD_EXTRACT_RESULTS is itself invoked via EXECUTE FUNCTION inside a derived table — a plain FROM TD_EXTRACT_RESULTS(...) is a syntax error (3707).

DB = 'MY_FS'; SRC = 'MY_SRC'

art_sql = [f"""
EXECUTE FUNCTION INTO VOLATILE ART(arima_fit)
  TD_ARIMAESTIMATE(
    SERIES_SPEC(TABLE_NAME({DB}.vw_series_in),
       ROW_AXIS(SEQUENCE(seq_no)), SERIES_ID(item_id, store_id),
       PAYLOAD(FIELDS(sales_qty), CONTENT(REAL))),
    FUNC_PARAMS(NONSEASONAL(MODEL_ORDER(1,0,0)), CONSTANT(1), ALGORITHM(MLE),
      FIT_PERCENTAGE(100), FIT_METRICS(1)))
"""]

# The ARTFITMETADATA layer has NAMED columns, one row per series: <series ids>, ROW_I, NUM_SAMPLES,
# VAR_COUNT, R_SQUARE, R_ADJ_SQUARE, STD_ERROR, STD_ERROR_DF, ME, MAE, MSE, MPE, MAPE, FSTAT_CALC,
# P_VALUE, NUM_DF, DENOM_DF, SIGNIFICANCE_LEVEL, F_CRITICAL, F_CRITICAL_P, NULL_HYPOTH.
# ARTFITRESIDUALS (with RESIDUALS(1)): <series ids>, ROW_I, ACTUAL_VALUE, CALC_VALUE, RESIDUAL.

# --- lifecycle: materialise the ART ONCE so REPLACE VIEW can resolve TABLE_NAME(arima_fit) ---
fm.update(filter_id=1)          # point the series-input view at the first partition
tdml.execute_sql(art_sql[0])    # one-off materialise (else the REPLACE VIEW below 3807s)

# feature view — read R_SQUARE + MAPE from the ARTFITMETADATA layer via TD_EXTRACT_RESULTS
tdml.execute_sql(f"""
REPLACE VIEW {DB}.vw_feat_arima_fit AS
LOCKING ROW FOR ACCESS
SELECT item_id, store_id,
       CAST(R_SQUARE AS FLOAT) AS r_square,
       CAST(MAPE     AS FLOAT) AS mape
FROM ( EXECUTE FUNCTION TD_EXTRACT_RESULTS(
         ART_SPEC(TABLE_NAME(arima_fit), LAYER(ARTFITMETADATA))) ) x
""")

Pin the exact grammar and the layer's column names against YOUR live Vantage — the TD_ARIMAESTIMATE FUNC_PARAMS grammar, the TD_EXTRACT_RESULTS/ART_SPEC spelling, and the layer's projected columns vary by operator and Vantage build. Capture them by running the operator once (see Step 2) and doing SELECT * FROM ( EXECUTE FUNCTION TD_EXTRACT_RESULTS(ART_SPEC(TABLE_NAME(<art>), LAYER(<layer>))) ) x WHERE 1=0 to read the column list. Validate a real SELECT from the feature view after materialising the ART once in the same session.

Step 4 — register with upload_features(art_sql=, art_layers=, filtermanager=)

import tdfs4ds

process_id = tdfs4ds.upload_features(
    tdml.DataFrame(tdml.in_schema(DB, 'vw_feat_arima_fit')),
    entity_id=['item_id', 'store_id'],
    feature_names=['r_square', 'mape'],
    art_sql=art_sql,             # materialised per partition, before ingestion
    art_layers=['ARTFITMETADATA'],
    filtermanager=fm,            # run() goes through the partitions
    return_process_id=True,
)

tdfs4ds then, per partition: filtermanager.update() → DROP+execute each art_sql statement (creating the volatile ART) → ingest from vw_feat_arima_fit (which reads the ART layer) → close follow-up. run(process_id, force_compute=True) re-materialises the ART and re-ingests idempotently.

run() materialises the ART itself, so a process runs in a new session, under roll_out and in each worker of a generated script (live-verified for a new session).


More patterns

Multiple layers of the SAME ART → one feature view, art_layers=[...] with several names

One ART often carries several layers. To expose features from more than one layer of the same ART, keep one art_sql statement (the ART is materialised once) and read each layer in its own CTE, LEFT JOIN-ed on the series id. Declare every layer in art_layers.

# feature view: R_SQUARE/MAPE from ARTFITMETADATA + a residual summary from ARTFITRESIDUALS
tdml.execute_sql(f"""
REPLACE VIEW {DB}.vw_feat_arima_multi AS
LOCKING ROW FOR ACCESS
WITH fitm AS (
  SELECT sid, CAST(R_SQUARE AS FLOAT) AS r_square, CAST(MAPE AS FLOAT) AS mape
  FROM ( EXECUTE FUNCTION TD_EXTRACT_RESULTS(
           ART_SPEC(TABLE_NAME(arima_fit), LAYER(ARTFITMETADATA))) ) a
),
res AS (   -- summarise the residual layer into per-series features
  SELECT sid,
         CAST(AVG(RESIDUAL)          AS FLOAT) AS resid_mean,
         CAST(STDDEV_SAMP(RESIDUAL)  AS FLOAT) AS resid_std
  FROM ( EXECUTE FUNCTION TD_EXTRACT_RESULTS(
           ART_SPEC(TABLE_NAME(arima_fit), LAYER(ARTFITRESIDUALS))) ) b
  GROUP BY sid
)
SELECT fitm.sid, fitm.r_square, fitm.mape, res.resid_mean, res.resid_std
FROM fitm LEFT JOIN res ON fitm.sid = res.sid
""")

tdfs4ds.upload_features(
    tdml.DataFrame(tdml.in_schema(DB, 'vw_feat_arima_multi')),
    entity_id=['sid'],
    feature_names=['r_square', 'mape', 'resid_mean', 'resid_std'],
    art_sql=art_sql,                                   # the SAME single ARIMA statement
    art_layers=['ARTFITMETADATA', 'ARTFITRESIDUALS'],  # declare BOTH layers read
    filtermanager=fm,
    return_process_id=True,
)

ARTFITMETADATA needs FIT_METRICS(1) in the ARIMA FUNC_PARAMS; ARTFITRESIDUALS needs RESIDUALS(1). Turn on whichever layers your view reads.

Chained operators → a SECOND art_sql statement (order matters)

A true residual-adequacy diagnostic (Ljung-Box / TD_PORTMAN, TD_DURBIN_WATSON, TD_BREUSCH_GODFREY) consumes the residual layer of a fit as its own input — this is the two-ART chain that a single view cannot express. Encode it as two ordered art_sql statements: statement 1 materialises the ARIMA ART (with RESIDUALS(1)); statement 2 reads that ART's ARTFITRESIDUALS layer via ART_SPEC(... LAYER(ARTFITRESIDUALS)) and materialises a second ART. The feature view reads the second ART.

art_sql = [
  # 1) fit + residuals
  f"""EXECUTE FUNCTION INTO VOLATILE ART(arima_fit)
       TD_ARIMAESTIMATE(SERIES_SPEC(TABLE_NAME({DB}.vw_series_in), ROW_AXIS(SEQUENCE(seq_no)),
         SERIES_ID(sid), PAYLOAD(FIELDS(val), CONTENT(REAL))),
         FUNC_PARAMS(NONSEASONAL(MODEL_ORDER(1,0,0)), CONSTANT(1), ALGORITHM(MLE),
           FIT_PERCENTAGE(100), RESIDUALS(1)))""",
  # 2) residual test — consumes ART #1's ARTFITRESIDUALS layer, emits ART #2
  f"""EXECUTE FUNCTION INTO VOLATILE ART(resid_test)
       TD_PORTMAN(ART_SPEC(TABLE_NAME(arima_fit), LAYER(ARTFITRESIDUALS), PAYLOAD(FIELDS(RESIDUAL), CONTENT(REAL))),
         FUNC_PARAMS(MAXLAG(5), TEST(LB), DEGREES_FREEDOM(1), SIGNIFICANCE_LEVEL(0.05)))""",
]
# resid_test holds <series ids>, ROW_I, NUM_SAMPLES, DEGREES_FREEDOM, SIGNIFICANCE_LEVEL, PORTMAN_VALUE,
# P_VALUE, CHISQUARE_VALUE, CRITICAL_P, NULL_HYPOTH. The feature view reads it; art_layers names the layers read.
# ORDER IS LOAD-BEARING: statement 2 depends on the ART statement 1 created — never reorder.

Confirm each operator's exact ART_SPEC/FUNC_PARAMS grammar and its output layer against your live Vantage (Step 2) — chained-operator grammars vary the most.

TD_PACF (partial autocorrelation)

TD_PACF consumes a TD_ACF ART, so it is a two-statement chain: art_sql[0] = EXECUTE FUNCTION INTO VOLATILE ART(acf) TD_ACF(SERIES_SPEC(...), FUNC_PARAMS(MAXLAGS(7))), art_sql[1] = EXECUTE FUNCTION INTO VOLATILE ART(pacf) TD_PACF(ART_SPEC(TABLE_NAME(acf)), FUNC_PARAMS(ALGORITHM(LEVINSON_DURBIN))). Its result is <series ids>, ROW_I, OUT_OUT_<payload>; the feature view pivots the lags from the pacf ART. (Plain TD_ACF alone, whose whole result is inline, does not need this skill — a single CTE-of-EXECUTE FUNCTION view registered as a denormalized view handles it; see td-uaf-feature.)


Rules

  • Use INTO VOLATILE ART, never INTO ART or a permanent table for art_sql. Session-scoped is the whole point: zero PERM, visible to the same-session ingestion CTAS, auto-cleaned. INTO ART costs PERM (Error 2644 for small users) and is a frozen snapshot.
  • art_sql is a list; order is load-bearing. A later statement may read an ART an earlier one created (chained operators: a residual test over LAYER(ARTFITRESIDUALS) of an ARIMA fit). Never sort/dedupe/reorder.
  • art_layers is required and must name the LAYER(s) the feature view reads. It is used for documentation and lineage only — it is NOT validated against the view DDL (the view is authoritative for what is computed). Keep it accurate for good docs/lineage.
  • Put the FilterManager scalar subquery in the series-input view, not around the operator. art_sql reads TABLE_NAME(<series-input view>), so filtering there makes it recompute per partition. Pass filtermanager=fm to upload_features; never write a loop over fm.update and run (see Stay inside the framework in fs-upload).
  • The feature view must be a legal view, and TD_EXTRACT_RESULTS is invoked via EXECUTE FUNCTION inside a derived table — FROM ( EXECUTE FUNCTION TD_EXTRACT_RESULTS(ART_SPEC(TABLE_NAME(<art>), LAYER(<layer>))) ) x (a plain FROM TD_EXTRACT_RESULTS(...) is Error 3707; verified live). That EXECUTE FUNCTION is fine in a view because it has no INTO — it returns an inline result set. What is NOT view-legal is INTO VOLATILE ART — never put the ART materialisation in the feature view; that is what art_sql is for.
  • Test through the real upload_features/run path, not just a bare SELECT — and remember the feature view only returns rows after art_sql has run in the same session, so a cold SELECT * FROM vw_feat_arima_fit (no ART yet) will error until you run art_sql manually or via run().
  • optimize_query is force-disabled for this type (art_sql is an opaque UAF invocation; the view EXPLAIN needs the ART materialised first). Documentation skips the view-EXPLAIN and instead grounds the layer-column descriptions in your art_sql operator + art_layers — so write clear FUNC_PARAMS.
  • Lineage traces through the ephemeral ART automatically to the series-input source (feature_view → <operator/layer node> → series_input_view) because upload_features passes art_sql/art_layers to record_process_lineage. Nothing extra to do.
  • Confirm the LAYER name and its columns empirically (show_query() + the wrapper's per-layer result columns) before hardcoding — they vary by operator and output format.