Skip to content

tdfs4ds.dataset.read_at

tdfs4ds.dataset.read_at

Read a registered dataset at a business date, with no DDL (0.3.8.0).

dataset_sql(name, as_of=...) returns the dataset's own query for one business date; read_dataset(name, as_of=...) runs it. Nothing is created and no TimeManager cursor moves: the date is a literal in the query. The query is the one the dataset view holds (read_dataset_spec reads the view's DDL, the dataset catalog stands in when the text cannot be read), with its temporal mode replaced by AS OF <literal> - same select list, joins, offsets, grouping and nested levels. A historical dataset is refused: filter the history view itself.

What a bare date means. build_dataset(as_of='2024-03-31') reads the date at midnight in the SESSION's time zone. Here the date is a BUSINESS date, read at midnight in the zone the store's dates are written in:

  • a dataset that follows a TimeManager: the zone of that calendar's dates;
  • otherwise the data domain's clock calendar, when the domain has one;
  • with neither: +00:00.

A calendar of DATE / TIMESTAMP without zone stores no zone: its dates were stamped in the session zone of the run, and the manager's own scalar is cast in the session zone too, so the literal gets no offset (same reading as a moved cursor). A timestamp that carries an offset is used as given.

AS_OF module-attribute

AS_OF = 'AS_OF'

HISTORY module-attribute

HISTORY = 'HISTORY'

TIME_MANAGER module-attribute

TIME_MANAGER = 'TIME_MANAGER'

DatasetTime

The resolved temporal mode of one dataset view.

Holds what the SQL needs (outer_qualifier, sub_qualifier) and what the catalog records (mode, as_of, the TimeManager's location).

mode instance-attribute

mode = mode

as_of instance-attribute

as_of = as_of

tm_database instance-attribute

tm_database = tm_database

tm_view instance-attribute

tm_view = tm_view

tm_table instance-attribute

tm_table = tm_table

window instance-attribute

window = window

tm_view_sql property

tm_view_sql

outer_qualifier property

outer_qualifier: str

sub_qualifier property

sub_qualifier: str

business_date_sql property

business_date_sql: str

The manager's business date as a scalar sub-query (TIME_MANAGER only).

period_predicate property

period_predicate: str

Leading WHERE conjuncts selecting the valid instant, or ''.

Only the TIME_MANAGER mode needs one (see the module docstring for why it is not an AS OF sub-query); for the other modes the qualifier alone selects the instant, and the SQL is byte-identical to before.

__init__

__init__(mode=CURRENT, as_of=None, tm_database=None, tm_view=None, tm_table=None, window=None)

__repr__

__repr__()

__eq__

__eq__(other)

instant_sql

instant_sql(offset=None) -> str

The dataset's valid instant moved by offset, as a constant expression.

CURRENT: the query time; AS_OF: the literal; TIME_MANAGER: the manager's business date, the shift inside the scalar sub-query so that it stays one single-row read resolved once. Shifting the constant (never the ValidStart / ValidEnd columns) keeps partition elimination: the arithmetic is folded into a literal in the plan (verified on Vantage 20).

catalog_validtime

catalog_validtime() -> str

The value written to DATASET_VALIDTIME (VARCHAR(255)).

CURRENT VALIDTIME or VALIDTIME AS OF TIMESTAMP '...' — the qualifier the view carries — or TIME_MANAGER <db>.<view> for a dataset following a TimeManager. A very long quoted manager name could overflow the column, so it then degrades to the mode name; the build table holds the full location anyway.

describe

describe() -> str

logger_safe

logger_safe(level, message, *args, **kwargs)

Wrapper around the global logger that only emits logs when tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.

format_timestamp_literal

format_timestamp_literal(value) -> str

Normalise value to the body of a Teradata TIMESTAMP '...' literal.

Returns 'YYYY-MM-DD HH:MI:SS[.ffffff][+HH:MM]'. A time part is always present: Teradata rejects TIMESTAMP '2024-03-31' (Error 3706, verified live), so a bare date becomes midnight. Fractional seconds and a time-zone offset are kept when given (both verified accepted in VALIDTIME AS OF); without an offset the literal is read in the session time zone, exactly as tdfs4ds.FEATURE_STORE_TIME is when features are ingested.

Accepted inputs: ISO strings ('2024-03-31', '2024-03-31 23:59', '2024-03-31T23:59:59.5Z', '2024-03-31 23:59:59+0200'), datetime.datetime, datetime.date, pandas.Timestamp and numpy.datetime64. Anything else — including ambiguous forms such as '03/31/2024' — raises ValueError naming the accepted formats, rather than being guessed.

calendar_offset

calendar_offset(time_manager) -> str | None

The offset shared by the dates of a WITH TIME ZONE calendar, else None (0.3.7.28). One small read; fail-open (None).

has_zone

has_zone(text) -> bool

Whether a timestamp text ends with a UTC offset (+01:00, -0500, Z). Pure.

is_zoned_type

is_zoned_type(type_text) -> bool

Whether a calendar type carries a time zone (... WITH TIME ZONE). Pure.

literal_with_zone

literal_with_zone(literal: str, data_type, offset: str | None = None) -> str

literal for a calendar of type data_type (0.3.7.28). Pure.

A WITH TIME ZONE calendar given a date with no zone would take the session's zone (a Central European session stored 2026-11-30 23:00 UTC for 2026-12-01). The date gets offset (the one the calendar's dates share), else +00:00. A literal that carries a zone, or another type of calendar, is returned as is.

_has_explicit_zone

_has_explicit_zone(value) -> bool

business_date_literal

business_date_literal(as_of, data_type=None, offset=None, calendar=False) -> str

The TIMESTAMP literal body a business date reads at (pure).

calendar: a calendar (TimeManager) drives the zone. With no calendar a date without an offset gets +00:00. With a calendar of a WITH TIME ZONE type it gets offset (the one its dates share), else +00:00; another type gets none (the session's zone, like the manager's own scalar). An explicit offset always wins.

_calendar_manager

_calendar_manager(spec)

(TimeManager or None, source): the manager whose zone applies.

_calendar_type

_calendar_type(tm)

The exact SQL type of the calendar's BUSINESS_DATE (TYPE(), one small read).

TimeManager.data_type keeps teradataml's spelling for a manager rebuilt from its view (TIMESTAMP for TIMESTAMP(0) WITH TIME ZONE: seen live), which hides the zone.

dataset_spec_at

dataset_spec_at(name, as_of, *, view_schema=None)

The dataset's DatasetSpec with its time set to AS OF the business date as_of.

_key_filter_for

_key_filter_for(spec, entity)

dataset_sql

dataset_sql(name, as_of, entity=None, *, view_schema=None) -> str

SQL text of the dataset name at the business date as_of (nothing is executed or created).

as_of is a BUSINESS date: a bare date ('2024-03-31', datetime.date) is read at midnight in the zone the store's dates are written in (the dataset's TimeManager calendar, else the domain clock's, else +00:00), NOT in the session's zone as build_dataset(as_of=...) does. A timestamp with an offset is used as given. entity: optional key filter, {column: value} (or a list of such dicts), pushed into every storage-table read.

read_dataset

read_dataset(name, as_of, entity=None, as_pandas=False, *, view_schema=None)

Rows of the dataset name at the business date as_of: stateless, no view, no cursor moved.

Returns a teradataml DataFrame (lazy), or a pandas frame with as_pandas=True (one raw statement). See dataset_sql for what a bare date means and entity=. The TimeManager of a time-driven dataset is NOT moved: the date is a literal in the query.