tdfs4ds.feature_props.declare¶
tdfs4ds.feature_props.declare
¶
Declaring feature properties: upload_feature_properties.
Layers: :func:read_source (I/O), :func:build_declarations (pure: validation, matching to the
catalog), :func:plan_statements (pure), :func:upload_feature_properties (the only writer, and
the only creator of the property tables - at the first real declaration, never on a dry run).
_SOURCE_COLUMNS
module-attribute
¶
_SOURCE_COLUMNS = ['FEATURE_NAME', 'ENTITY_NAME', 'DATA_DOMAIN', 'PROCESS', 'VALID_MIN', 'VALID_MAX', 'ALLOWED_VALUES', 'NULLABLE', 'NULL_MEANING', 'SENSITIVE', 'SENSITIVITY_REASON']
_COMPARED
module-attribute
¶
_COMPARED = ['VALID_MIN', 'VALID_MAX', 'NULLABLE', 'NULL_MEANING', 'SENSITIVE', 'SENSITIVITY_REASON']
run_frame
¶
Run one SELECT through teradataml.execute_sql and return a frame (no DataFrame metadata).
read_source
¶
A frame from a pandas / teradataml DataFrame, a 'db.view' / 'db.table' name or SQL text.
Column names are upper-cased.
parse_allowed
¶
The allowed values of one cell: a list, a JSON array text, or a text delimited by | (else ,).
build_declarations
¶
build_declarations(rows: DataFrame, catalog: DataFrame, *, allowed: Optional[DataFrame] = None, processes: Optional[DataFrame] = None, default_domain: Optional[str] = None) -> dict
Validate the source rows and match them to registered features (pure).
Returns {'declarations': [...], 'unknown': [...], 'ambiguous': [...], 'invalid': [...]}. A
declaration is a dict with DATA_DOMAIN, ENTITY_NAME, FEATURE_NAME, PROCESS_ID, VALID_MIN, VALID_MAX,
ALLOWED (list), NULLABLE, NULL_MEANING, SENSITIVE, SENSITIVITY_REASON and type (the catalog type).
Unknown, ambiguous and invalid rows are listed and never written.
plan_statements
¶
{'written': [...], 'unchanged': [...], 'statements': [sql]} (pure). existing:
{(domain, entity, feature, process_id): {property columns..., 'ALLOWED': [...]}} of the current rows;
an identical declaration writes nothing (no history churn).
upload_feature_properties
¶
upload_feature_properties(source, *, allowed_values=None, data_domain: Optional[str] = None, author: Optional[str] = None, dry_run: bool = False) -> dict
Declare properties of registered features: a valid range, allowed values, the meaning of NULL and whether it is expected, sensitivity. One row per feature.
source: a DataFrame, a 'db.view' / 'db.table' name or SQL text with the columns FEATURE_NAME
(required), ENTITY_NAME, DATA_DOMAIN (else data_domain / tdfs4ds.DATA_DOMAIN), PROCESS (a PROCESS_ID
or process view: the declaration then holds for that process only), VALID_MIN, VALID_MAX, ALLOWED_VALUES
(JSON array, |- or ,-delimited), NULLABLE (Y/N), NULL_MEANING (zero / not_applicable / unknown),
SENSITIVE (Y/N), SENSITIVITY_REASON. A column absent from the source, or an empty cell, declares nothing
for that property; a declaration REPLACES the feature's previous one (the valid-time history keeps it).
allowed_values: a second source (FEATURE_NAME[, ENTITY_NAME, DATA_DOMAIN], ALLOWED_VALUE).
Types come from the catalog; bounds and allowed values must be valid literals of the feature's type.
Unknown features, ambiguous names (several entities / domains) and invalid rows are reported and never
written. dry_run=True returns the plan, creates and writes nothing. The tables are created by the first
real declaration. Declared properties are never checked by run(): see check_feature_properties.
Returns {written, unchanged, unknown, ambiguous, invalid, statements, created, dry_run}.