Skip to content

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_sql by 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). 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.

_CACHE module-attribute

_CACHE = ContextVar('tdfs4ds_ddl_cache', default=None)

_READ_HEADS module-attribute

_READ_HEADS = ('SELECT', 'SEL ', 'SEL\n', 'SHOW', 'HELP', 'EXPLAIN', 'LOCKING', 'WITH', 'CURRENT VALIDTIME SEL', 'NONSEQUENCED VALIDTIME SEL', 'VALIDTIME AS OF')

_is_read

_is_read(statement) -> bool

_install_invalidation

_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

ddl_cache()

Cache object definitions for the block. Nested blocks share the outer cache.

active

active() -> bool

cached

cached(key, fn)

fn() once per key inside :func:ddl_cache; a direct call outside it.

invalidate

invalidate() -> None

Forget every cached definition (a view was just replaced).

suspended

suspended()

No cache inside the block (a run moves manager views, so definitions may change).

without_ddl_cache

without_ddl_cache(fn)

Run fn with the cache suspended (functools.wraps).

with_ddl_cache

with_ddl_cache(fn)

Run fn inside :func:ddl_cache (signature and source kept: functools.wraps).