{"record":{"id":"ae4cdf83145291b2","repo":"dbt-labs/dbt-core","slug":"should-treat-persisted-view-vs-temp-view-as-equiva","errorCode":null,"errorMessage":"should treat persisted view vs temp view as equivalent","messagePattern":"should treat persisted view vs temp view as equivalent","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/sql/diff.rs","lineNumber":4464,"sourceCode":"with dummy_cte as (select 1 as foo)\nselect\n    cast(null as string) as command_invocation_id\nfrom dummy_cte\nwhere 1 = 0\n\"#;\n\n        let expected = r#\"\ncreate or replace temporary view `sources__dbt_tmp` as\n/* Bigquery won't let us `where` without `from` so we use this workaround */\nwith dummy_cte as (select 1 as foo)\nselect\n    cast(null as string) as command_invocation_id\nfrom dummy_cte\nwhere 1 = 0\n\"#;\n\n        compare_sql(actual, expected, AdapterType::Databricks)\n            .expect(\"should treat persisted view vs temp view as equivalent\");\n\n        // Same pattern but in a MERGE statement: Fusion uses a three-part qualified name for the\n        // __dbt_tmp temp table in the USING clause, while Mantle uses just the identifier.\n        let merge_actual = r#\"\n-- back compat for old kwarg name\n\n\n\n    merge\n    into\n        `dbt`.`dbt_dbt_audit`.`seed_executions` as DBT_INTERNAL_DEST\n    using\n        `dbt`.`dbt_dbt_audit`.`seed_executions__dbt_tmp` as DBT_INTERNAL_SOURCE\n    on\n        FALSE\n    when matched\n        then update set\n            *","sourceCodeStart":4446,"sourceCodeEnd":4482,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/sql/diff.rs#L4446-L4482","documentation":"Test panic from .expect at crates/dbt-adapter/src/sql/diff.rs:4464: compare_sql(actual, expected, AdapterType::Databricks) returned Err because a persisted view reference and its __dbt_tmp temp-view equivalent were not canonicalized to the same shape. The differ must treat dbt's temp-relation naming/qualification variants (__dbt_tmp) as equivalent so Mantle-generated and recorded Fusion SQL match for Databricks DDL and MERGE statements.","triggerScenarios":"cargo test -p dbt-adapter with test at diff.rs:4464: a Databricks query selecting from dummy_cte with a persisted-view vs temp-view (__dbt_tmp) qualified-name difference, and compare_sql(actual, expected, AdapterType::Databricks) yields Err, panicking \"should treat persisted view vs temp view as equivalent\".","commonSituations":"dbt creates a __dbt_tmp view before swapping in the persisted relation; replayed recorded SQL references the final name while newly generated SQL references __dbt_tmp (or vice versa); adapter changes to relation-name rendering for Databricks (catalog/schema qualification) break the equivalence normalization.","solutions":["Read the Err detail to see the exact relation names that failed to unify","Extend the Databricks canonicalizer to strip/normalize __dbt_tmp suffixes and unify two-part vs three-part relation names","Check whether relation-name normalization is adapter-gated and missing for AdapterType::Databricks","Also cover the MERGE USING variant (diff.rs:4512) since it shares the same normalization path"],"exampleFix":"// before\ncompare_sql(actual, expected, AdapterType::Databricks)\n    .expect(\"should treat persisted view vs temp view as equivalent\");\n// after (library-side: normalize temp relation names before compare)\nlet norm = |s: &str| unify_temp_relations(canonicalize(s, AdapterType::Databricks));\nassert_eq!(norm(actual), norm(expected));","handlingStrategy":"validation","validationCode":"// normalize temp relation names before diffing Databricks SQL\nfn normalize_temp_rels(sql: &str) -> String {\n    Regex::new(r\"([\\w`]+\\.)+[\\w`]*__dbt_tmp\\b\").unwrap()\n        .replace_all(sql, \"__dbt_tmp\").to_string()\n}\nassert_eq!(normalize_temp_rels(actual), normalize_temp_rels(expected));","typeGuard":null,"tryCatchPattern":"compare_sql(&normalize_temp_rels(actual), &normalize_temp_rels(expected), AdapterType::Databricks)\n    .unwrap_or_else(|e| eprintln!(\"temp-view drift: {e}\"));","preventionTips":["Normalize __dbt_tmp naming and relation qualification depth per adapter before compare","Keep relation rendering consistent between DDL and MERGE paths","Add persisted-vs-temp-view equivalence fixtures for every adapter","When the temp relation swap is intentional, compare against the temp name in tests"],"tags":["rust","sql-diff","test-panic","databricks","temp-view","dbt-tmp"],"backgroundTag":"sql-diff-mismatch","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}