Skip to content

tdfs4ds.server_side_batch

tdfs4ds.server_side_batch

Server-side batch: the statements of one ingestion batch in ONE round trip (0.3.8.0, opt-in).

A batch stores its staged features with one MERGE per feature (feature_merge_statements). On a remote client each statement is a round trip. With tdfs4ds.SERVER_SIDE_BATCH set, the MERGEs go to the database as ONE CALL of a generic stored procedure that runs them with dynamic SQL, in order.

SERVER_SIDE_BATCH (env TDFS4DS_SERVER_SIDE_BATCH): 'off' (default, today's statements), 'auto' / 'procedure' (the procedure; installed once by :func:install_server_side_batch, never created implicitly), 'macro' (accepted; see below).

Why a generic procedure and no per-process macro (measured on Vantage 20): the statements of a batch name the staging volatile table, whose name changes at every batch, and carry the valid time as a VALIDTIME PERIOD '(...)' literal. A macro takes parameters for values, never for identifiers or a temporal qualifier, so one macro per process would need its text rebuilt (and re-installed) at every batch: no gain. Dynamic SQL inside a procedure takes both. 'macro' therefore behaves as 'auto' with one warning that says so.

Contract (each point has a test):

  • Outcome identical. The same statements, in the same order, in the same session (the staging table is volatile and visible). A data error surfaces as the same exception class (teradatasql.OperationalError) with the database's own message, so failure_status / describe_db_error / the FAILED follow-up text read as on the client path.
  • A refusal is not a failure. Missing procedure, no right to execute it, a statement the procedure cannot run: ONE warning, the mechanism is off for the session, and the SAME batch continues on the client path (the follow-up row is the one already RUNNING; no duplicate). The statements are idempotent MERGEs, so rerunning them after a partial run stores the same rows.
  • Visible. The procedure text is in FS_SERVER_BATCH_OBJECTS (optional table, FS_V_ view), reviewed in the app (Performance > Server-side batches), checked by the server_batch sanity check.
  • The procedure returns a result set (failed_index, sqlstate, sqlcode, message): failed_index 0 = everything ran; otherwise the 1-based index of the statement that failed.

PROC_VERSION module-attribute

PROC_VERSION = 1

PROC_BASE module-attribute

PROC_BASE = 'TDFS4DS_RUN_BATCH'

TABLE module-attribute

TABLE = 'FS_SERVER_BATCH_OBJECTS'

VIEW module-attribute

VIEW = 'FS_V_SERVER_BATCH_OBJECTS'

DELIM module-attribute

DELIM = '/*;;TDFS4DS;;*/'

MAX_REQUEST_CHARS module-attribute

MAX_REQUEST_CHARS = 64000

CHUNK module-attribute

CHUNK = 8000

MODES module-attribute

MODES = ('off', 'auto', 'procedure', 'macro')

_QUOTE module-attribute

_QUOTE = chr(39)

_STATE module-attribute

_STATE = {'disabled': False, 'warned': set(), 'tables': None, 'reason': None}

_NOT_SUPPORTED module-attribute

_NOT_SUPPORTED = ('not supported within a stored procedure',)

_OUR_OBJECTS module-attribute

_OUR_OBJECTS = ('TDFS4DS_RUN_BATCH', 'SYSEXECSQL')

sql_literal

sql_literal(value)

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.

reset_state

reset_state()

mode

mode() -> str

active

active() -> bool

proc_name

proc_name(version: int = PROC_VERSION, schema=None) -> str

procedure_body

procedure_body() -> str

procedure_ddl

procedure_ddl(version: int = PROC_VERSION, schema=None, replace: bool = True) -> str

body_hash

body_hash(text: str) -> str

expected_hash

expected_hash(version: int = PROC_VERSION) -> str

build_call

build_call(statements, version: int = PROC_VERSION)

CALL <proc>('<stmt1>/*;;*/<stmt2>') or None when the text is too long for one call.

classify_call_error

classify_call_error(text: str) -> str

'refused' (the mechanism is not usable: fall back) or 'data' (the statements' own error).

Matched on phrases, never on numbers. A missing object is a refusal only when it is OUR procedure (or DBC.SysExecSQL): a missing table or column of a MERGE is the same error on the client path.

parse_result

parse_result(sets)

From the result sets of a CALL: (failed_index, sqlstate, sqlcode, message); None when none.

data_error

data_error(index, sqlstate, code, message)

The exception a client-path statement failure would raise (same class, same shape of message).

_warn_once

_warn_once(key, text)

disable

disable(reason: str)

try_run

try_run(statements) -> bool

Run statements in one CALL. True = they ran server-side; False = the client path must run them (mechanism off, refused or not applicable). A data error raises as on the client path.

_fetch

_fetch(cur)

table_ddl

table_ddl()

view_ddl

view_ddl()

registry_creation

registry_creation(existing=None) -> bool

Create the optional registry table and view when missing. Never raises.

chunks

chunks(text: str, size: int = CHUNK)

registry_rows_sql

registry_rows_sql(name, kind, version, text, process_id=None)

The statements that make text the registered body of name now (close the old rows, insert the new).

install_script

install_script(version: int = PROC_VERSION) -> list

The statements :func:install_server_side_batch runs (pure; nothing executed).

install_server_side_batch

install_server_side_batch(dry_run: bool = True, version: int = PROC_VERSION) -> dict

Install (or replace) the generic batch procedure and record its text in the registry.

dry_run=True (default) only returns the statements. Nothing else changes: the mechanism stays off until tdfs4ds.SERVER_SIDE_BATCH is set. Returns {'statements', 'applied', 'error'}.

drop_script

drop_script(version: int = PROC_VERSION) -> list

drop_server_side_batch

drop_server_side_batch(dry_run: bool = True, version: int = PROC_VERSION) -> dict

_rows

_rows(sql)

installed_objects

installed_objects() -> list

Server-side objects of the store from DBC (procedures TDFS4DS_RUN_BATCH_*, macros TDFS4DS_B_*).

registered_objects

registered_objects() -> dict

{name: {version, hash, text, process_id}} from the registry (current valid time); {} when absent.

rights_verdict

rights_verdict() -> dict

{'verdict': 'probable'|'unlikely'|'unknown', 'detail'} from the dictionary (never executes).

findings

findings(installed=None, registered=None, expected=None) -> list

Pure: sanity findings from what is installed (installed_objects) and registered (registered_objects).

check_row

check_row(probe_writes: bool = False) -> dict

The check_configuration row server_side_batch (never raises).

_probe

_probe() -> str

Create, call and drop a throwaway copy of the procedure (opt-in: the only part that writes).

process_info

process_info(process_id=None) -> dict

get_process_info entry SERVER_BATCH.

process_objects

process_objects(process_id) -> list

Objects registered for one process (none are created by the generic procedure; kept for removal).

drop_process_objects_sql

drop_process_objects_sql(process_id) -> list

Statements that drop the objects registered for process_id (per-process macros, if any).

review_model

review_model() -> dict

What the app tab shows (read-only): objects, their text, rights, drift, and the client SQL replaced.