Repository navigation
CORE-1501: fix: store dbt_run_results.execution_time as an 8-byte double - #1074
EladBarkay wants to merge 3 commits into
Conversation
dbt reports execution_time as a Python float (8-byte double), but the column was declared via dbt.type_float(), which is a 4-byte float on DuckDB, Spark/Databricks, ClickHouse and Dremio. Values were silently rounded to ~7 significant digits. Add edr_type_double(), which returns an 8-byte type on those adapters and falls back to edr_type_float() elsewhere (already 8 bytes there, so no schema change), and use it for execution_time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
|
👋 @EladBarkay |
| adapters, but on these it is a 4-byte float that silently rounds Python | ||
| floats (dbt's own run timings among them) to ~7 significant digits. #} | ||
| {% macro edr_type_double() %} | ||
| {{ return(adapter.dispatch("edr_type_double", "elementary")()) }} |
There was a problem hiding this comment.
is there a dbt.type_double or dbt_utils.type_float?
There was a problem hiding this comment.
No: dbt core only has string/timestamp/float/numeric/bigint/int/boolean, and dbt_utils ≥1.0 dropped its type macros (older versions only had type_float). So we need our own edr_type_double().
| {% macro duckdb__edr_type_double() %} {% do return("double") %} {% endmacro %} | ||
|
|
||
| {% macro spark__edr_type_double() %} {% do return("double") %} {% endmacro %} | ||
|
|
||
| {% macro fabricspark__edr_type_double() %} | ||
| {{ return(elementary.spark__edr_type_double()) }} | ||
| {% endmacro %} | ||
|
|
||
| {% macro dremio__edr_type_double() %} {% do return("double") %} {% endmacro %} | ||
|
|
||
| {% macro clickhouse__edr_type_double() %} {% do return("Float64") %} {% endmacro %} | ||
|
|
||
|
|
There was a problem hiding this comment.
- what happened on all of this WHs if that column already existed?
- the original issue happened on alibaba's MaxCompute WH. should it be mentioned here? what will happened there? (it looks like it will just fall back to the default impl, which is pointing to edr_type_float
There was a problem hiding this comment.
Existing tables keep FLOAT: dbt_run_results uses append_new_columns, which ignores type changes on all of these adapters, so uploads keep working as they do today until an elementary_full_refresh. Verified on DuckDB by changing the column back to FLOAT and running an upgrade + upload.
MaxCompute: good catch. type_float() is plain float (4 bytes) there, so the fallback wouldn't help. Added maxcompute__edr_type_double() → double in 4e1ff55 (untested, since MaxCompute isn't a supported adapter).
MaxCompute's FLOAT is 4 bytes and it rejects inserting a DOUBLE literal into it, which is the failure that prompted #1062. type_float() resolves to plain "float" there, so the default edr_type_double() fallback would not have fixed it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Context: we hit exactly this on MaxCompute and opened #1062 (cast numeric literals in 1. The
So on MaxCompute the 8-byte type isn't a precision nicety — it's the difference between the artifact upload running at all and not. 2. The "existing tables keep working exactly as they do today" paragraph doesn't transfer to MaxCompute — there "today" is a failure, and it stays a failure until the table is rebuilt. Because the insert still hands the engine a DOUBLE and
So for a MaxCompute user the release note is not "sub-millisecond rounding of run timings until a rebuild", it is "uploads keep failing until a rebuild" ( 3. Cross-package note: Nothing we need from you — if a new commit lands here we're happy to re-run the two tables above against it and post the readings. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Problem
dbt reports
run_result.execution_timeas a Python float (an 8-byte double).dbt_run_results.execution_timeis declared withdbt.type_float(), which is a 4-byte float on some adapters:type_float()float(4 bytes)Float32On the 4-byte adapters, values are silently rounded to ~7 significant digits (e.g.
1234.5678901234→1234.56787109375). Engines that refuse implicit narrowing (e.g. MaxCompute) reject the insert entirely.This is an alternative to #1062 / #1066. Those PRs cast numeric literals in
insert_rowsto the destination type. That makes strict engines accept the insert, but a cast to a 4-byteFLOATstill rounds, and it changes how every numeric value in everyinsert_rowscall is rendered. Fixing the column type removes both the precision loss and the narrowing.Change
edr_type_double()macro:doubleon DuckDB, Spark (and Databricks through dispatch), fabricspark, Dremio and MaxCompute, andFloat64on ClickHouse;edr_type_float()on every other adapter, which is already 8 bytes there, so no schema change on those adapters.empty_columnsupports a new"double"column kind.dbt_run_results.execution_timeis declared as"double".MaxCompute isn't a supported adapter, but it's where this was first reported (#1062): its
FLOATis 4 bytes and it rejects the double literal instead of rounding it. Sincetype_float()returns plainfloatthere, the default fallback wouldn't fix it, so it gets its own one-line override. It's untested.Existing tables
dbt_run_resultsis incremental withon_schema_change="append_new_columns", and itsfull_refreshis tied toelementary_full_refresh. Underappend_new_columns, dbt ignores column type changes. That's true for the shared dbt logic and for the ClickHouse, Spark, Databricks, Dremio and MaxCompute incremental implementations. So existing tables keep theirFLOATcolumn, and uploads keep working exactly as they do today, until the table is rebuilt withelementary_full_refresh: true. New installs get the double column right away.Checked on DuckDB: I changed an existing
dbt_run_resultscolumn back toFLOAT, ran the normal incremental build plus a run that uploads results, and the column stayedFLOATwith rows inserted without errors. Since the impact is sub-millisecond rounding of run timings, I think that's acceptable. It's worth a release note.Tests
New integration test
test_run_results_execution_time_precision. It rebuildsdbt_run_results, insertsexecution_time = 1234.5678901234throughelementary.insert_rows(the same path the upload uses), and checks the stored value is exact (within 1e-9).Locally on DuckDB:
float, it fails with1234.56787109375 != 1234.5678901234;test_dbt_artifactssuite passes (50 passed, 4 skipped).The other 4-byte adapters (Spark/Databricks, ClickHouse, Dremio) are left to CI.
🤖 Generated with Claude Code