tdfs4ds.migration.access¶
tdfs4ds.migration.access
¶
Who needs which rights for a migration (0.3.6.13): the user that runs the processes in the target store, the databases that hold the migrated views, and whoever reads the datasets.
Everything here produces TEXT: the package never executes a GRANT (a source guard
test enforces it). A DBA applies the statements; :func:check_access then confirms,
read-only and as the target user, that the views compile.
Teradata's rules behind the lists¶
- A view is resolved with the rights of the database that holds it. A user who
reads
P.vneedsSELECTonP.vonly ifPitself holdsSELECT ... WITH GRANT OPTIONon whatvreads in another database (Error 3523 / 5315 otherwise). That is the Databases group. run()/roll_out()write the store's tables (the MERGE intoFS_T_*, the follow-up row), collect statistics, and replace the manager views.
Measured on a live system (efs-dev, Vantage 20; test users created FROM the
migrating user, which hold no implicit right on the objects of another database):
see the RIGHTS_MEASURED table below. A right that no measured step needed is not
in the lists; a right that could not be tested says not measured.
GROUP_TITLES
module-attribute
¶
GROUP_TITLES = {GROUP_DATABASES: 'Databases (views read across databases)', GROUP_MIGRATING: 'Migrating user', GROUP_RUN: 'Run user', GROUP_READERS: 'Dataset readers'}
RIGHT_CODES
module-attribute
¶
RIGHT_CODES = {'SELECT': 'R', 'INSERT': 'I', 'UPDATE': 'U', 'DELETE': 'D', 'CREATE TABLE': 'CT', 'DROP TABLE': 'DT', 'CREATE VIEW': 'CV', 'DROP VIEW': 'DV', 'STATISTICS': 'ST', 'SHOW': 'SH', 'EXECUTE': 'E'}
RUN_STORE_RIGHTS
module-attribute
¶
RUN_CLOSING_WHY
module-attribute
¶
RUN_CLOSING_WHY = 'only for processes with close_absent_entities or valid_time_column, which delete rows; leave it out if none has them'
MIGRATING_TABLE_RIGHTS
module-attribute
¶
MIGRATING_VIEW_RIGHTS
module-attribute
¶
RIGHTS_MEASURED
module-attribute
¶
RIGHTS_MEASURED: Dict[str, str] = {'databases: SELECT WGO, view database -> process-view database': 'needed: run/roll_out Error 3523', 'databases: SELECT WGO, table database -> view database': 'needed: connect fails (5315), DS_TM 5315', 'databases: SELECT WGO, table database -> dataset database': 'needed: both datasets fail (5315)', 'databases: SELECT WGO, view database -> dataset database': 'needed for a TimeManager dataset (5315 on the manager view)', 'run: SELECT on the table database': 'needed: FS_PROCESS_SETTINGS unreadable (5315)', 'run: INSERT on the table database': 'needed: run/roll_out 3523', 'run: UPDATE on the table database': 'needed: run/roll_out 5315', 'run: CREATE TABLE on the table database': 'needed: run fails 3524 (teradataml staging table)', 'run: DROP TABLE on the table database': 'needed at the first run of a process (3523 on the staging table); not at later runs', 'run: DELETE on the table database': 'not needed by a plain run/roll_out; a temporal or NONSEQUENCED DELETE is refused without it (3523), the statements of close_absent_entities and valid_time_column', 'run: STATISTICS on the table database': 'needed: COLLECT STATS is refused (3523, DROP TABLE does not give it); the run still completes, with a warning, and the statistics are not refreshed', 'run: SELECT on the view database': 'needed: connect fails', 'run: CREATE VIEW on the view database': 'not needed (run, first run, roll_out)', "run: DROP VIEW on the manager view's database": 'needed: roll_out 3523 (update() replaces the view)', 'run: SELECT on the process view': 'needed: run 3523; check_access names it', 'readers: SELECT on the dataset': 'needed: 3523', 'migrating user': 'not measured'}
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.
norm_name
¶
Uppercase, de-quoted, stripped — the canonical comparison form.
split_qualified
¶
Split 'db.obj' / '"db"."obj"' / 'obj' into (db, obj) (raw,
de-quoted but original case preserved). db is '' when unqualified.
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).
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.
sql_literal
¶
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.
grant_statement
¶
grant_statement(rights: Iterable[str], db: str, obj: Optional[str], grantee: str, grant_option: bool = False) -> str
GRANT <rights> ON <db[.obj]> TO <grantee> [WITH GRANT OPTION]; (text only).
_grant
¶
_grant(group, rights, db, obj, grantee, why, grant_option=False, placeholder=False) -> Dict[str, Any]
effective_location
¶
Where an object of the plan is read from once migrated: its target, or the
source itself for a table read in place (data_choice='reference').
_manager_locations
¶
{(SRC_DB, SRC_VIEW): (target db, view)} of the plan's managers: unified
onto the canonical one, or recreated in the store's table database.
plan_access
¶
plan_access(plan: Dict[str, Any], run_user: Optional[str] = None, readers=None, session_user: Optional[str] = None, migrating_user: Optional[str] = None) -> Dict[str, Any]
The plan['access'] section: the GRANTs of the four groups. Pure (statuses
are filled by :func:refresh_status).
run_user None = the session user; readers None = a marked placeholder
and readers_runnable False; the migrating user is the session user.
read_rights
¶
The rights of grantees (users, roles or databases) as the session can read
them: {ok, rows, role_rows, roles, owners, error}. rows are
(grantee, database, object, code, grant_option) upper-cased, object is
ALL for a database-level right. Roles are followed one level. Never raises.
_owns
¶
True when grantee is db or one of its owners: those hold every right on it.
grant_status
¶
granted / missing / unknown for one grant against a :func:read_rights
snapshot. A right that cannot be read is unknown, never missing.
refresh_status
¶
Fill the status of every grant of access from the rights the session can
read (fail-open: unknown). Returns access.
dataset_access
¶
The GRANTs a user needs to read dataset ('db.name' or a name in the view
database), for any dataset, migrated or not: SELECT for the readers, and what
the dataset's database must hold to resolve the view (the store's tables, its
TimeManager view). Text only; statuses from what the session can read.
process_run_access
¶
The GRANTs a user needs to run processes of the current store (process_ids
None = all): the tables and catalog views, the process views, the manager views,
and the rights the process views' databases need on what they read (from the
persisted lineage). Text only; statuses from what the session can read.
access_script
¶
The GRANTs of access (a plan['access'], :func:dataset_access or
:func:process_run_access result, or a plan carrying one) as SQL text, one
section per group. Placeholders are left for the DBA to fill. Not executed.
write_access_script
¶
write_access_script(plan: Dict[str, Any], out_path: Optional[str] = None, groups: Optional[Iterable[str]] = None) -> str
Write :func:access_script to out_path (default tdfs4ds_grants_<ts>.sql
under tdfs4ds.SCHEDULING_SCRIPT_DIR or the working directory); return the path.
check_access
¶
check_access(plan: Optional[Dict[str, Any]] = None, datasets: Optional[Iterable[str]] = None) -> Dict[str, Any]
Run as the target user, after the GRANTs were applied: EXPLAIN on each
view (the plan's process, intermediate and dataset views at their target, or
the current store's process views plus datasets). Refusals carry the GRANT
that lifts them (:func:tdfs4ds.utils.query_management.grant_hint). Read-only,
never raises: {ok, user, checked, refused, broken, unanswered}.