tdfs4ds.process_store.process_registration_management¶
tdfs4ds.process_store.process_registration_management
¶
quote_ident
¶
Return name as a Teradata identifier, quoting it only if required.
Idempotent: an already-quoted name is returned unchanged rather than being
wrapped a second time. Embedded quotes are escaped as "".
Parameters¶
name : str
The raw object/database name.
force : bool, default False
Quote even when the name does not need it. Use only at the few sites
that have always emitted unconditional quotes and whose exact output is
already baked into persisted DDL (see
feature_store/feature_query_retrieval.py) — elsewhere forcing would
change the SQL of existing stores for no reason.
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).
split_qualified
¶
Split db.obj into (database, object), both de-quoted.
Quote-aware, so a dot inside a quoted part does not split the name:
split_qualified('"DEINF.CARLOSN"."FS_X"') == ('DEINF.CARLOSN', 'FS_X').
The naive rsplit('.', 1) this replaces returns ('"DEINF.CARLOSN"',
'"FS_X"') only by luck and ('"DEINF', 'CARLOSN"."FS_X"') in the
split('.') variant.
An unqualified name returns ('', name).
execute_query_wrapper
¶
Decorator to execute a query. It wraps around the function and adds exception handling.
This decorator is used to wrap around a function that generates a query and execute that query.
It handles exceptions during query execution and prints the error message along with the query.
The decorator works with both TeradataML's tdml and legacy tdml.get_context() execution methods,
depending on the TeradataML version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
function
|
Function to be decorated. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
function |
Decorated function. |
Example
To decorate a function that generates and executes a query:
@execute_query_wrapper def my_query_function(): return "SELECT * FROM my_table"
This decorator can be applied to functions that generate and execute queries with ease.
logger_safe
¶
Wrapper around the global logger that only emits logs when
tdfs4ds.DISPLAY_LOGS is True. level is a string like "info", "error", etc.
_warn_if_definition_ignored
¶
_warn_if_definition_ignored(process_id, recorded_pi, recorded_partitioning, primary_index, partitioning)
Warn when a re-registration passes a primary index / partitioning other than the recorded one.
The recorded one is kept: the process's storage tables were created with it, and its rows are stored there. Nothing is compared when the caller passed nothing (None / '').
register_process_view
¶
register_process_view(view_name, entity_id, feature_names, metadata={}, entity_null_substitute={}, **kwargs)
Registers a process view in the feature store or updates an existing one, based on global configuration and
specified parameters. This function serves as a wrapper that dynamically chooses the registration method
(either update-insert or merge) according to the global tdfs4ds.REGISTER_PROCESS setting. It supports
registering views with an option to return the process ID for tracking and further operations.
- view_name (str | DataFrame): The name of the view as a string or a DataFrame object. If a DataFrame is provided, it is expected that the table name will be used as the view name.
- entity_id (str): The identifier of the entity associated with this view.
- feature_names (List[str]): A list of the names of features to be included in the view.
- metadata (dict, optional): Additional metadata related to the view. Defaults to an empty dictionary.
- **kwargs: Arbitrary keyword arguments. This includes 'with_process_id', which dictates whether the process ID should be returned along with the query.
- If 'with_process_id' is specified and True, the function returns a tuple containing the main SQL query string, the process ID, the distribution query, and the filter manager query (if applicable). Otherwise, it returns the main SQL query string, the distribution query, and the filter manager query, omitting the process ID.
Note:
- The function determines the registration method (update-insert or merge) based on the global configuration.
- It delegates the actual registration logic to _register_process_view_update_insert or _register_process_view_merge,
depending on the chosen method.
_register_process_view_merge
¶
_register_process_view_merge(view_name, entity_id, feature_names, metadata={}, entity_null_substitute={}, **kwargs)
This function registers a new process view or updates an existing one in the feature store. It is versatile, accepting either a view name as a string or a DataFrame, and can handle different time parameters for data validity. The primary operations include generating a unique process ID, constructing SQL queries for inserting or updating view details, and optionally returning the process ID for further use. It leverages global configurations and specific modules for its operations.
- view_name (str | DataFrame): The name of the view as a string, or a DataFrame object. If a DataFrame is provided, its table name is extracted and used as the view name.
- entity_id (str): The identifier of the entity to which the view is associated.
- feature_names (List[str]): The names of features included in the view.
- metadata (dict, optional): A dictionary of additional metadata related to the view. Defaults to {}.
- **kwargs: Arbitrary keyword arguments. Includes options like 'with_process_id' to return the process ID, 'filtermanager' for applying a filter manager, 'primary_index', and 'partitioning' for data distribution.
- If 'with_process_id' is True, returns a tuple containing the main SQL query string, process ID, distribution query, and filter manager query (if applicable). Otherwise, returns the main SQL query string, distribution query, and filter manager query without the process ID.
Note:
- Assumes certain global variables and configurations (e.g., tdfs4ds.END_PERIOD, tdfs4ds.FEATURE_STORE_TIME) are set.
- Requires 'tdml' module for DataFrame operations and 'uuid' for generating unique identifiers.
_register_process_view_update_insert
¶
_register_process_view_update_insert(view_name, entity_id, feature_names, metadata={}, entity_null_substitute={}, **kwargs)
Registers or updates a process view in the feature store. This function supports both the creation of new views and the modification of existing ones. It handles the process based on the type of view name provided (str or DataFrame) and the specified time parameters (current or past).
The function generates a unique process identifier and constructs a SQL query to insert or update the view details in the feature store. Additionally, it handles logging of the process registration.
view_name (str or DataFrame): The name of the view (string) or a DataFrame object representing the view. If a DataFrame is provided, its table name is used as the view name. entity_id (str): The identifier of the entity associated with the view. feature_names (list of str): A list of feature names included in the view. metadata (dict, optional): Additional metadata related to the view. Defaults to an empty dictionary. kwargs: Additional keyword arguments. If 'with_process_id' is provided and set to True, the function also returns the process ID.
tuple or str: If 'with_process_id' is True, returns a tuple containing the SQL query string and the process ID. Otherwise, returns only the SQL query string. The query is for inserting or updating the view details in the feature store.
Note:
- The function assumes specific global variables and configurations (like tdfs4ds.END_PERIOD, tdfs4ds.FEATURE_STORE_TIME, etc.)
are already set in the environment.
- It requires the 'tdml' module for DataFrame operations and 'uuid' for generating unique identifiers.
register_process_tdstone
¶
Registers a 'tdstone2 view' process in the feature store with specified model details and metadata. This function is designed for registering hyper-segmented models created using the 'tdstone2' Python package. It handles both scenarios where the feature store date is current or in the past.
Parameters: model (Model Object): An instance of the 'tdstone2' model containing necessary details for the registration. metadata (dict, optional): Additional metadata related to the process. Defaults to an empty dictionary.
Returns: str: A SQL query string to insert the process details into the feature store.
Notes: - The 'model' parameter should be an object of the 'tdstone2' model class. - This function generates a unique process identifier for each registration. - It constructs SQL queries for both current valid time and past date scenarios based on 'tdfs4ds' global variables. - The function logs the process registration by printing the process ID.
Dependencies: - 'tdfs4ds' global variables and configurations must be set in the environment. - The 'uuid' and 'json' modules are used for generating unique identifiers and handling metadata, respectively. - This function requires the 'tdstone2' Python package for working with 'tdstone2' models.