Skip to content

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.v needs SELECT on P.v only if P itself holds SELECT ... WITH GRANT OPTION on what v reads in another database (Error 3523 / 5315 otherwise). That is the Databases group.
  • run() / roll_out() write the store's tables (the MERGE into FS_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_DATABASES module-attribute

GROUP_DATABASES = 'databases'

GROUP_MIGRATING module-attribute

GROUP_MIGRATING = 'migrating'

GROUP_RUN module-attribute

GROUP_RUN = 'run'

GROUP_READERS module-attribute

GROUP_READERS = 'readers'

GROUPS module-attribute

GROUPS = (GROUP_DATABASES, GROUP_MIGRATING, GROUP_RUN, GROUP_READERS)

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'}

READERS_PLACEHOLDER module-attribute

READERS_PLACEHOLDER = '<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_STORE_RIGHTS = ('SELECT', 'INSERT', 'UPDATE', 'CREATE TABLE', 'DROP TABLE', 'STATISTICS')

RUN_CLOSING_RIGHTS module-attribute

RUN_CLOSING_RIGHTS = ('DELETE',)

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'

RUN_VIEW_RIGHTS module-attribute

RUN_VIEW_RIGHTS = ('DROP VIEW',)

MIGRATING_TABLE_RIGHTS module-attribute

MIGRATING_TABLE_RIGHTS = ('CREATE TABLE', 'DROP TABLE', 'SELECT', 'INSERT', 'UPDATE', 'DELETE')

MIGRATING_VIEW_RIGHTS module-attribute

MIGRATING_VIEW_RIGHTS = ('CREATE VIEW', 'DROP VIEW', 'SELECT')

MIGRATING_SOURCE_RIGHTS module-attribute

MIGRATING_SOURCE_RIGHTS = ('SELECT', 'SHOW')

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

logger_safe(level, message, *args, **kwargs)

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

norm_name(name: Optional[str]) -> str

Uppercase, de-quoted, stripped — the canonical comparison form.

split_qualified

split_qualified(name: Optional[str]) -> Tuple[str, str]

Split 'db.obj' / '"db"."obj"' / 'obj' into (db, obj) (raw, de-quoted but original case preserved). db is '' when unqualified.

qualified

qualified(database, object_name, force=False)

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

quote_ident(name, force=False)

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

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.

_target

_target(db: str, obj: Optional[str] = None) -> str

_grantee

_grantee(name: str) -> str

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]

_users

_users(value) -> List[str]

effective_location

effective_location(o: Dict[str, Any]) -> Tuple[str, str]

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

_manager_locations(plan) -> Dict[Tuple[str, str], Tuple[str, str]]

{(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.

_resolver

_resolver(plan)

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.

summarize

summarize(grants: List[Dict[str, Any]]) -> Dict[str, Dict[str, int]]

_rows

_rows(sql: str)

_in

_in(values) -> str

read_rights

read_rights(grantees: Iterable[str], databases: Iterable[str] = ()) -> Dict[str, Any]

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

_owns(grantee: str, db: str, owners: Dict[str, str]) -> bool

True when grantee is db or one of its owners: those hold every right on it.

grant_status

grant_status(g: Dict[str, Any], snap: Dict[str, Any]) -> str

granted / missing / unknown for one grant against a :func:read_rights snapshot. A right that cannot be read is unknown, never missing.

refresh_status

refresh_status(access: Dict[str, Any]) -> Dict[str, Any]

Fill the status of every grant of access from the rights the session can read (fail-open: unknown). Returns access.

_split_name

_split_name(name: str, default_db: str) -> Tuple[str, str]

dataset_access

dataset_access(dataset: str, readers=None) -> Dict[str, Any]

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

process_run_access(process_ids=None, user: Optional[str] = None) -> Dict[str, Any]

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.

_current_user

_current_user() -> Optional[str]

access_script

access_script(access: Dict[str, Any], groups: Optional[Iterable[str]] = None) -> str

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}.