fix(dbt-cost-estimate): count IDENTIFIER() as a possible file read on Databricks

HK
1h ago
+190-12

Issue for this PR

Follows up a review comment on #1768 (IDENTIFIER() slipping a file read past the Databricks file-read check).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

scanSql blanks quoted text, so a source named inside IDENTIFIER('...') never reached the read_files / cloud_files / <format>.\path`checks, andEXPLAIN COSTwas sent while Databricks read the files to plan it. Now a lone string literal insideIDENTIFIER(...)is read as code and run through the same patterns (any qualification, case and spacing). Any other argument (a:param, a variable, concatenation, adjacent literals, backslash escapes) is treated as a possible file read, so no estimate is given and the run is never blocked. A benign IDENTIFIER('cat.sch.tbl')` is still estimated. BigQuery and Snowflake are unchanged.

How did you verify your code works?

bun test test/altimate/dbt-cost-estimate.test.ts (219 pass) and bun typecheck are green. New regression tests cover the three inputs from the review plus case, whitespace, comment, qualification and non-literal variants, and an end-to-end check that the EXPLAIN is not sent; the failing ones fail on origin/main.

Cost side effects

None

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

🤖 Generated with Claude Code


Summary by cubic

Fixes the Databricks file-read check in dbt-cost-estimate so a source named inside IDENTIFIER(...) can't slip past it and trigger EXPLAIN COST while Databricks reads the files to plan it. A lone string literal inside IDENTIFIER(...) is read as code and checked like any direct file source; only a plain dotted ASCII name of up to three parts passes as a table. Anything else (:param, variable, concatenation, adjacent literals, escapes, double-quoted names, ${...} substitution), a literal starting with a file format (json.raw), or a name containing a read_files/cloud_files part counts as a possible read, so no estimate is given. Qualified, nested, commented, keyword-folded, and dot-suffixed calls are read conservatively and also count as reads, while benign table references like IDENTIFIER('cat.sch.tbl') still get an estimate. Scanning stays linear in SQL size, and BigQuery and Snowflake are unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Databricks queries using IDENTIFIER(...) are more reliably recognized as potential file reads, including when identifiers are dynamic, nested, or assembled from expressions. These reads are skipped during cost estimation.
    • Ordinary table identifiers remain distinguishable from file reads and eligible for estimation where applicable.
    • Snowflake queries continue to use their existing scanning behavior.