Fix(Fabric): Skip Catalog Jump#5780
Open
fresioAS wants to merge 6 commits intoSQLMesh:mainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Reduces excessive catalog-switching churn in the Fabric engine adapter.
Root cause:
get_current_catalog()was inherited fromGetCurrentCatalogFromFunctionMixin, executingSELECT db_name()on every call — including the two calls made by theset_catalogdecorator (switch-in + restore) wrapping every catalog-scoped operation. For Fabric, each SQL statement runs in an independent session, so this also triggered a connectionclose()+ reopen on every single restore, even when restoring to the same catalog.Changes:
Override
get_current_catalog()to read thread-local state (_target_catalog) instead of querying the database. Eliminates allSELECT db_name()round-trips.Treat the default catalog as neutral (
None) via_normalize_catalog(). The configureddatabaseis the implicit connection default — there is no meaningful distinction between "connected todefault" and "no catalog set", so both map toNone. This prevents the decorator from seeing a mismatch and unnecessarily switching back to the default after every operation.Lazy connection management via
_connected_catalogtracking.set_current_catalog()now distinguishes between the logical catalog target (_target_catalog) and the physical catalog the open connection is using (_connected_catalog). The connection is only closed and reopened when the physical connection actually needs to change:_target_catalogis updated, but the open connection is kept alive for reuse on the next call to the same catalog.Fix
_drop_catalogto check both_connected_catalogandget_current_catalog()(with default-db fallback) before closing all connections, so dropping the default warehouse is still handled correctly.Test Plan
get_current_catalog, default catalog clearing, restore-to-neutral without connection close, same-catalog reuse (1 close for N consecutive ops), and cross-catalog switching (1 close per genuine switch).Checklist
make styleand fixed any issuesmake fast-test)git commit -s) per the DCO