tdfs4ds.genai.operators.byom¶
tdfs4ds.genai.operators.byom
¶
BYOM scoring operators (ONNXPredict, PMMLPredict, H2OPredict, ...): see operator_context.
A BYOM call scores every row of an input with a model STORED IN A TABLE of the database
(ON <input> AS InputTable ... ON <model table> AS ModelTable DIMENSION USING ...).
The model table holds the model itself (a BLOB, never read here) and often metadata
(model id, training date, comment, metrics) which tells what the model is and which one
is in use. detect parses the call, collect reads that metadata, render writes
the fixed text block.
FUNCTIONS
module-attribute
¶
FUNCTIONS = ('ONNXPredict', 'PMMLPredict', 'H2OPredict', 'DataRobotPredict', 'DataikuPredict', 'MLeapPredict', 'ONNXEmbeddings', 'ONNXSeq2Seq', 'ONNXClassification')
_FUNC_RE
module-attribute
¶
_FUNC_RE = compile('(?<![\\w$#@])((?:' + _NAME + '\\s*\\.\\s*)?)(' + join(FUNCTIONS) + ')\\s*\\(', I)
_FROM_RE
module-attribute
¶
_mask
¶
sql with comments blanked and string / quoted-identifier contents neutralised.
Same length as the input, so positions found on the mask slice the original.
Quoted identifiers keep word characters (x) so name patterns still match them.
_top_level
¶
Yield (pos, char) of every character of masked[start:end] at paren depth 0.
_split_top_level
¶
_split_top_level(masked: str, start: int, end: int, keywords: Tuple[str, ...]) -> List[Tuple[str, int, int]]
Cut masked[start:end] at depth-0 keywords (whole words): [(keyword, from, to)].
_parse_using
¶
Name(v1, v2) Name2(v) -> {Name: [v1, v2], ...} (order kept).
_parse_source
¶
One ON clause body <object | (subquery)> AS <alias> [PARTITION BY ... | DIMENSION ...].
detect
¶
One dict per BYOM call: function, qualifier, input / model source, USING parameters.
_run
¶
(column names, rows) of sql through the active teradataml context.
_table_kind
¶
TableKind from DBC.TablesV ('T', 'O', 'V', ...), None when unknown (no right, no row).
_view_text
¶
(view text, None) for a view, (None, None) for a table, (None, refusal) when SHOW VIEW was refused.
_resolve_table
¶
Follow views (SHOW VIEW, one FROM object) down to the table. -> (db, table, chain).
_read_table
¶
_read_table(db: str, obj: str, where: Optional[str] = None) -> Tuple[List[str], List[dict], List[str]]
Non-LOB columns and at most MAX_ROWS rows of a table. -> (columns, rows, notes).
where: a simple selection (see simple_selection) read first, so the model the
SQL picks is in the list even when the table holds more than MAX_ROWS models.
collect
¶
Add the model table's metadata to each item. Fail-open: a problem becomes a note.
simple_selection
¶
{column: {values}} when where is only col = 'v' / col IN ('a','b') joined by AND, else {}.