Repository navigation
Conversation
The Spark and Databricks adapters register a temp view for every DataFrame insert but never drop it, so long sessions accumulate views and keep the DataFrames alive on the driver. Drop the view in the source query cleanup, as the other adapters do for their temp tables. Fixes SQLMesh#6125 Signed-off-by: JanakiRamChittineni <341781521+raams95@users.noreply.github.com>
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
As reported in #6125, every DataFrame insert in the Spark and Databricks (Spark session) adapters registers a temp view (
createOrReplaceGlobalTempView/createOrReplaceTempView) that is never dropped. In long-running sessions the views pile up and keep the DataFrames alive on the driver.The other adapters already clean up their temp tables through the
SourceQuerycleanup callback (DuckDB, BigQuery, MSSQL, ClickHouse, Snowflake). This adds the same for Spark and Databricks: the view is dropped withspark.catalog.dropGlobalTempView/spark.catalog.dropTempViewonce the statement that reads it has run. I used the catalog API rather thanDROP VIEWso the drop goes through the same Spark session that created the view. On Databricks this matters because SQL can otherwise go through the SQL connector.The temp view name is now generated once, outside the query factory, so the cleanup knows what to drop. The generated SQL is the same as before.
Fixes #6125
Test Plan
test_df_source_query_drops_global_temp_view(tests/core/engine_adapter/test_spark.py) andtest_df_source_query_drops_temp_view(tests/core/engine_adapter/test_databricks.py). Each one checks that the view is created and queried inside the source query context and dropped when it exits. Both fail onmain(drop never called) and pass with this change.pytest tests/core/engine_adapter tests/core/test_snapshot_evaluator.py --ignore=tests/core/engine_adapter/integrationpasses, excepttest_drop_table_ducklake_no_cascade, which failed once in a parallel run on my Windows machine and passes when rerun on its own (it doesn't touch the Spark/Databricks adapters).ruff check,ruff formatandmypyare clean on the changed files.Checklist
make styleand fixed any issues (ruff and ruff-format pass; mypy and the migrations hook report the same environment-only errors onmainon my Windows machine)make fast-test) (no new failures compared tomainon my Windows machine; the Windows-only failures onmainare unchanged)git commit -s) per the DCO