Skip to content

CORE-1501: fix: store dbt_run_results.execution_time as an 8-byte double - #1074

Draft
EladBarkay wants to merge 3 commits into
masterfrom
fix/run-results-execution-time-double
Draft

EladBarkay wants to merge 3 commits into
masterfrom
fix/run-results-execution-time-double

Conversation

@EladBarkay

@EladBarkay EladBarkay commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

dbt reports run_result.execution_time as a Python float (an 8-byte double). dbt_run_results.execution_time is declared with dbt.type_float(), which is a 4-byte float on some adapters:

Adapter type_float()
DuckDB, Spark/Databricks, Dremio float (4 bytes)
ClickHouse Float32
Postgres/Redshift, Snowflake, BigQuery, Trino/Athena, SQL Server/Fabric, Vertica already 8 bytes

On 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_rows to the destination type. That makes strict engines accept the insert, but a cast to a 4-byte FLOAT still rounds, and it changes how every numeric value in every insert_rows call is rendered. Fixing the column type removes both the precision loss and the narrowing.

Change

  • New edr_type_double() macro:
    • returns double on DuckDB, Spark (and Databricks through dispatch), fabricspark, Dremio and MaxCompute, and Float64 on ClickHouse;
    • falls back to edr_type_float() on every other adapter, which is already 8 bytes there, so no schema change on those adapters.
  • empty_column supports a new "double" column kind.
  • dbt_run_results.execution_time is declared as "double".

MaxCompute isn't a supported adapter, but it's where this was first reported (#1062): its FLOAT is 4 bytes and it rejects the double literal instead of rounding it. Since type_float() returns plain float there, the default fallback wouldn't fix it, so it gets its own one-line override. It's untested.

Existing tables

dbt_run_results is incremental with on_schema_change="append_new_columns", and its full_refresh is tied to elementary_full_refresh. Under append_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 their FLOAT column, and uploads keep working exactly as they do today, until the table is rebuilt with elementary_full_refresh: true. New installs get the double column right away.

Checked on DuckDB: I changed an existing dbt_run_results column back to FLOAT, ran the normal incremental build plus a run that uploads results, and the column stayed FLOAT with 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 rebuilds dbt_run_results, inserts execution_time = 1234.5678901234 through elementary.insert_rows (the same path the upload uses), and checks the stored value is exact (within 1e-9).

Locally on DuckDB:

  • the new test passes;
  • with the column temporarily switched back to float, it fails with 1234.56787109375 != 1234.5678901234;
  • the full test_dbt_artifacts suite passes (50 passed, 4 skipped).

The other 4-byte adapters (Spark/Databricks, ClickHouse, Dremio) are left to CI.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

👋 @EladBarkay
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@linear

linear Bot commented Oct 4, 2026

Copy link
Copy Markdown

CORE-1501

@EladBarkay EladBarkay changed the title fix: store dbt_run_results.execution_time as an 8-byte double CORE-1501: fix: store dbt_run_results.execution_time as an 8-byte double Oct 4, 2026
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")()) }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a dbt.type_double or dbt_utils.type_float?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Comment on lines +134 to +146
{% 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 %}


Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@TonyStack2026

Copy link
Copy Markdown

Context: we hit exactly this on MaxCompute and opened #1062 (cast numeric literals in insert_rows) — closed in favour of this approach, which we agree is the better one: fixing the column type removes both the silent rounding and the narrowing, instead of changing how every numeric renders on every adapter. Two readings from our side, on the part the body marks as untested.

1. The maxcompute__edr_type_double() override is the only form the engine accepts. Against a real MaxCompute project with odps.sql.type.system.odps2=true, inserting 0.1234567890123456789 into a one-row table:

destination column result
double accepted, reads back 0.12345678901234568 (all 17 digits kept)
float rejected before execution: ODPS-0130071 … column __value_col1 in source has incompatible type DOUBLE with destination column execution_time, which has type FLOAT. Implicit conversion is not applied because of potential data loss …

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 append_new_columns ignores the type change, we measured:

existing float column result
bare double literal ODPS-0130071 (same error as above)
cast(<literal> as double) still ODPS-0130071 — a cast to the wider type cannot fix narrowing into the column
cast(<literal> as float) accepted, stores 0.12345679104328156 (float32 rounding, i.e. the thing this PR exists to remove)

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" (elementary_full_refresh: true, or drop/recreate dbt_run_results). If you'd rather not name a specific engine in the note, something like "on warehouses that refuse implicit narrowing this is a hard failure for pre-existing tables until they are rebuilt" covers it without singling anyone out.

3. Cross-package note: dbt-project-evaluator hit the same shape in stg_nodes (a FLOAT column fed by graph-derived values) and it was fixed there by casting the generated insert values to the types the models already declare — merged as dbt-labs/dbt-project-evaluator#602 (merge commit c796a89). So today the two packages diverge: that one works on a type-strict warehouse, this one waits on #1074.

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.

@jonlevine7

jonlevine7 commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants