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 beNone("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.
qualified
¶
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
¶
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.
normalise_selection
¶
{name: value} from any accepted form (insertion order kept).
producers_query
¶
The one catalog read: each requested feature with its location and producers.
read_feature_producers
¶
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.
_snippet
¶
The selected_features to paste: one version chosen, or all side by side.
resolve_selection
¶
(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
¶
Read the catalogs once and resolve selected_features (see the module).