tdfs4ds.utils.read_cache¶
tdfs4ds.utils.read_cache
¶
A cache of object definitions (SHOW VIEW / SHOW TABLE) for one call (0.3.7.20).
upload_features builds the lineage of the view it registers several times (TimeManager
detection, the check, the soft clone, the lineage record, the process-SQL capture), and each
build reads every object's definition again: four SHOW statements per object, measured.
Inside :func:ddl_cache a definition is read once.
Scope and safety:
- The cache lives in a context variable, so other threads (the admin app) never see it.
- Errors are cached too: a SHOW VIEW on a table fails every time, so the second attempt is answered from the cache as well.
- Any statement that is not a read, sent through
teradataml.execute_sqlby the context holding the cache, clears it (a CREATE / REPLACE / DROP may change a definition already read; seen live: a soft clone created after a failed SHOW VIEW of its name). Since 0.3.7.25 a data write (INSERT / UPDATE / DELETE / MERGE, with or without a temporal qualifier, every statement of the request) clears only the cached rows (("rows", ...)keys): it cannot change an object's definition, and oneupload_featureswrites a dozen catalog rows between its lineage builds (measured: 8.7 s of repeated SHOW). tdfs4ds also clears it explicitly after the soft clone and the optimizer's rewrite (:func:invalidate). A view changed by another session during the call is not seen until the call ends.
_READ_HEADS
module-attribute
¶
_READ_HEADS = ('SELECT', 'SEL ', 'SEL\n', 'SHOW', 'HELP', 'EXPLAIN', 'LOCKING', 'WITH', 'CURRENT VALIDTIME SEL', 'NONSEQUENCED VALIDTIME SEL', 'VALIDTIME AS OF', 'DYNAMIC EXPLAIN')
_DML_HEADS
module-attribute
¶
_QUALIFIER
module-attribute
¶
_QUALIFIER = re.compile("^(?:(?:CURRENT|NONSEQUENCED|SEQUENCED)\\s+VALIDTIME|VALIDTIME\\s+PERIOD\\s*'[^']*'|VALIDTIME\\s+AS\\s+OF\\s+(?:TIMESTAMP\\s*)?'[^']*')\\s+", re.IGNORECASE)
_OBJECT_DDL
module-attribute
¶
_OBJECT_DDL = re.compile('^(?:CREATE|REPLACE|DROP)\\b[^;]*?\\b(?:VIEW|TABLE)\\s+([^\\s(,;]+)', re.IGNORECASE)
_is_session_setting
¶
A statement that changes the session only (SET QUERY_BAND around an EXPLAIN, 0.3.7.35):
it cannot change a definition or a row, so it does not forget anything. The distribution check
sets the band before each dynamic EXPLAIN, and each one used to empty the cache of a report.
_is_data_write
¶
True when every statement of the request is a data write (no definition can change).
_ddl_objects
¶
The objects a request creates, replaces or drops (CREATE / REPLACE / DROP VIEW|TABLE, mixed
with data writes), or None when one statement is anything else (then everything is
forgotten). 0.3.7.25: a REPLACE VIEW forgets that view's definition only, so the lineage
rebuilt after it reads the changed view again and the others from the cache.
_forget_objects
¶
Drop every cached row (an object created or dropped changes what DBC and the registries answer) and the cached definitions of an object with one of names' bare names (any database: forgetting too much is safe, forgetting too little is not).
_install_invalidation
¶
Clear the cache of the calling context on any statement that is not a read sent through
teradataml.execute_sql (a CREATE / REPLACE / DROP may change a definition already read:
seen live, a soft clone created after a failed SHOW VIEW of its name). Installed once;
a context without a cache (another thread) passes straight through.
ddl_cache
¶
Cache object definitions for the block. Nested blocks share the outer cache.
show_key
¶
The cache key of a SHOW statement: Teradata object names are not case sensitive, and the
same object was read under three spellings in one report (demo_user.v, DEMO_USER.V;,
quoted), once each (0.3.7.35).
cached
¶
fn() once per key inside :func:ddl_cache; a direct call outside it. A ("show", sql)
key is read as :func:show_key reads it (case, quotes and a closing ; do not make another key).
cached_rows
¶
run(sql).fetchall() once per statement inside :func:ddl_cache (a ("rows", sql)
key: any data write, CREATE or DROP forgets it); a direct read outside it. run defaults to
teradataml.execute_sql looked up at call time (tests replace it).
suspended
¶
No cache inside the block (a run moves manager views, so definitions may change).
with_ddl_cache
¶
Run fn inside :func:ddl_cache (signature and source kept: functools.wraps).