tdfs4ds.dataset.dataset¶
tdfs4ds.dataset.dataset
¶
_OUTER_VALIDTIME_RE
module-attribute
¶
_AS_OF_VALIDTIME_RE
module-attribute
¶
_AS_OF_VALIDTIME_RE = compile("\\bVALIDTIME\\s+AS\\s+OF\\s+(?:TIMESTAMP|DATE)\\s*'[^']*'", IGNORECASE)
_AS_OF_TM_VALIDTIME_RE
module-attribute
¶
_AS_OF_TM_VALIDTIME_RE = compile('\\bVALIDTIME\\s+AS\\s+OF\\s*\\(\\s*SELECT\\s+BUSINESS_DATE\\s+FROM\\s+[^)]+\\)', IGNORECASE)
Dataset
¶
valid_time
instance-attribute
¶
__init__
¶
Parameters¶
entity, features : optional
The AUTHORITATIVE entity/feature split, supplied by build_dataset
(which knows it at build time). When BOTH are provided they are used
verbatim and the fragile DDL-regex re-derivation
(_retrieve_entities_and_features) is skipped. When omitted (e.g.
an ad-hoc Dataset(view_name=...) for inspection) the regex path is
used as before — preserving backward compatibility.
entity is {col: sql_type}; features is
{NAME: {id, version, type, database, view}}.
valid_time : str, optional
The governing temporal qualifier, supplied by build_dataset which
chose it. When omitted it is read back from the view's DDL.
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).
get_feature_types_sql_format
¶
Retrieve the SQL data types of specified columns from a Teradata dataframe.
This function executes a query to fetch the SQL data types of the given columns and returns them in a dictionary format.
Parameters: tddf (tdml.DataFrame): A Teradata dataframe. columns (list): List of column names to retrieve their data types.
Returns: dict: A dictionary where keys are column names and values are their corresponding SQL data types.
Example:
tdml.load_example_data("GLM", ["admissions_train"]) df = tdml.DataFrame("admissions_train") get_feature_types_sql_format(df, columns=df.columns) {'id': 'INTEGER', 'masters': 'VARCHAR(5)', 'gpa': 'FLOAT', 'stats': 'VARCHAR(30)', 'programming': 'VARCHAR(30)', 'admitted': 'INTEGER'}
df.to_sql(table_name='test_admission_train', types={'stats': tdml.VARCHAR(length=40, charset='UNICODE')}, if_exists='replace') df = tdml.DataFrame("test_admission_train") get_feature_types_sql_format(df, columns=df.columns) {'id': 'INTEGER', 'masters': 'VARCHAR(5)', 'gpa': 'FLOAT', 'stats': 'VARCHAR(40) CHARACTER SET UNICODE', 'programming': 'VARCHAR(30)', 'admitted': 'INTEGER'}
_extract_validtime
¶
The temporal qualifier that governs a snapshot dataset view, from its DDL.
Read by SCANNING for the qualifier, never by indexing a line. This used to be
ddl.split('\n')[4].strip() — the 5th line of the SHOW VIEW text — which
recorded whatever happened to sit there. Since the generated DDL begins with a
newline, that index lands on the SELECT, so the dataset catalog's
DATASET_VALIDTIME column held a fragment of the select list (observed live:
SELECT A1.CUSTOMERID). Nothing in the package reads the column back, which
is why it went unnoticed.
The outer qualifier wins because it governs the whole view; the sub-query
AS OF is consulted only in the time-travel shape, where the outer one is
deliberately empty. Returns '' when neither is present, rather than
guessing — an empty valid time is honest, a wrong one is not.