Skip to content

1 - Avoid full table mapping in renderer replace_table(s) calls #6017

Description

@cmgoffena13

File: sqlmesh/core/renderer.py
Functions: _resolve_table , _resolve_tables
Lines: 326 - 418

Issue with _resolve_table:

_resolve_table resolves one table but passes the full physical + view mapping into exp.replace_tables, which re-parses every mapping key.

The full mapping today is passed to the exp.replace_tables and is:

{
    **self._to_table_mapping((snapshots or {}).values(), deployability_index),
    **(table_mapping or {}),
}

Look up this table’s entry (table_mapping overrides physical) and pass a one-entry dict into exp.replace_tables.

Keying must match how replace_tables normalizes names (quoting/case), or we miss. Either normalize this one name the same way before lookup, or pass the one pair through and let replace_tables normalize that single key.

Issue with _resolve_tables:

We pass in expression and create the table_mapping. Problem is, we don't check if the expression contains a table node, which is what's required for any of the downstream code to be useful.

So basically:

        if not snapshots and not table_mapping and not expand:
            return expression

       if not expression.find(exp.Table):      <----- NEW
           return expression

        expression = expression.copy()

This skips the execution entirely for expressions that only contain virtual or session properties.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions