Skip to content

tdfs4ds.dataset.selection

tdfs4ds.dataset.selection

Feature selection of a dataset: names alone when a feature has one version.

build_dataset / build_historical_dataset accept selected_features as

  • a list of feature names (['amount', 'nb_tx']) or one name;
  • a dict {feature: version} whose value may be None ("the only version"), {'alias': ...} (the only version under a name of its own), or any of the explicit forms (a process id, {'process_id', 'alias'}, a list of versions side by side).

A version has to be written only for a feature that several processes compute. Everything is resolved with ONE read of the catalogs, whatever the number of features: :func:read_feature_producers (the only I/O) then the pure :func:resolve_selection, which returns the full {feature: version} dict and the storage locations in the shape get_feature_location returns.

FeatureSelectionError

Bases: ValueError

The selection names a feature that cannot be resolved unambiguously.

missing: names not registered for this entity and data domain. no_producer: registered names that no current process computes. ambiguous: {feature: [{'process_id', 'process_view_name'}]} for the features computed by several processes, with no version given.

missing instance-attribute

missing = list(missing)

no_producer instance-attribute

no_producer = list(no_producer)

ambiguous instance-attribute

ambiguous = dict(ambiguous or {})

__init__

__init__(message, missing=(), no_producer=(), ambiguous=None)

qualified

qualified(database, object_name, force=False)

Build db.obj with each part quoted only as needed.

qualified('TDB', 'FS_X') == 'TDB.FS_X' (unchanged for ordinary names); qualified('SVC@CORP', 'FS_X') == '"SVC@CORP".FS_X'. An empty/None database yields the bare object name, so unqualified callers keep working.

force=True quotes both parts unconditionally — only for the sites that have always emitted quotes and whose exact text is already persisted (dataset view DDL, returned volatile-table names).

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

_entity_key

_entity_key(entity_id)

normalise_selection

normalise_selection(selected_features)

{name: value} from any accepted form (insertion order kept).

producers_query

producers_query(entity_id, names, domain=None)

The one catalog read: each requested feature with its location and producers.

read_feature_producers

read_feature_producers(entity_id, names, domain=None)

Rows (FEATURE_NAME, FEATURE_ID, FEATURE_DATABASE, FEATURE_TABLE, PROCESS_ID, VIEW_NAME) for the requested names; PROCESS_ID is None when no process computes the feature. One query.

_clean

_clean(value)

_readable

_readable(view_name)

DB.VIEW without the identifier quotes the catalog stores.

_snippet

_snippet(selection, ambiguous)

The selected_features to paste: one version chosen, or all side by side.

resolve_selection

resolve_selection(selected_features, rows, entity=None)

(selection, locations) from selected_features and the catalog rows.

selection is the full {feature: version} dict, keyed by the catalog's spelling; locations is {qualified table: [(feature_id, version, feature_name)]}, the shape get_feature_location returns. Raises :class:FeatureSelectionError listing every problem at once. Pure.

resolve_for_build

resolve_for_build(entity_id, selected_features, domain=None)

Read the catalogs once and resolve selected_features (see the module).