Skip to content

Fix float inference to use DoubleParameter (64-bit) instead of FloatP…#742

Merged
jprakash-db merged 2 commits intodatabricks:mainfrom
Shubhambhusate:fix/float-to-double-parameter-inference
Mar 10, 2026
Merged

Fix float inference to use DoubleParameter (64-bit) instead of FloatP…#742
jprakash-db merged 2 commits intodatabricks:mainfrom
Shubhambhusate:fix/float-to-double-parameter-inference

Conversation

@Shubhambhusate
Copy link
Contributor

…arameter (32-bit)

What type of PR is this?

  • Bug Fix

Description

dbsql_parameter_from_primitive() in src/databricks/sql/parameters/native.py currently maps Python's float type to FloatParameter, which binds values as Databricks SQL FLOAT (32-bit single-precision). However, Python's float is a 64-bit IEEE 754 double-precision number, so this mapping silently truncates precision.
This PR changes the inference to use DoubleParameter instead, which binds values as Databricks SQL DOUBLE (64-bit) and correctly preserves the full precision of Python floats.

Before (buggy):

cursor.execute("INSERT INTO t (val) VALUES (?)", [12345.678901234])
# Stored as 12345.0 — precision lost silently

After (fixed):

cursor.execute("INSERT INTO t (val) VALUES (?)", [12345.678901234])
# Stored as 12345.678901234 — full precision preserved

How is this tested?

  • Unit tests
  • Manually

All 55 unit tests in tests/unit/test_parameters.py pass, including test_inference[DoubleParameter-Primitive.FLOAT].

Manually verified that parameterized queries with raw Python floats now preserve full 64-bit precision when inserted into DOUBLE columns.

Related Tickets & Documents

…arameter (32-bit)

Signed-off-by: Shubhambhusate <bhusates6@gmail.com>
@Shubhambhusate
Copy link
Contributor Author

Issue link: #741

@Shubhambhusate
Copy link
Contributor Author

Hi @msrathore-db Can you please review the PR

@msrathore-db
Copy link
Contributor

Hi @msrathore-db Can you please review the PR

Adding @jprakash-db for review as he has more context on the same

@Shubhambhusate
Copy link
Contributor Author

Hi @jprakash-db Can you please review this PR?

Copy link

@gopalldb gopalldb left a comment

Choose a reason for hiding this comment

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

A minor comment on test, will also let Jothi also take a look

@jprakash-db
Copy link
Contributor

Overall LGTM.
I think this is fine, even if customers define FLOAT table and insert DOUBLE from client the server auto truncates so not an issue.

@Shubhambhusate
Copy link
Contributor Author

Hi @jprakash-db

Do we have any ETA for the PR to be merged, and the fix will be available?

@jprakash-db
Copy link
Contributor

@Shubhambhusate Looks like the creds are not available in this forked branch to run the e2e. Let me run them manually and I will update the status here

@jprakash-db jprakash-db merged commit 12bfd5b into databricks:main Mar 10, 2026
33 of 36 checks passed
@jprakash-db
Copy link
Contributor

@Shubhambhusate We have merged it , thanks for the contribution

@Shubhambhusate
Copy link
Contributor Author

Hi @jprakash-db

Thanks for merging it. Could you please let me know when the fix will be available to the user?

@jprakash-db
Copy link
Contributor

@Shubhambhusate We are going to cut a release in this week tentatively, so you can expect by coming Monday

@Shubhambhusate
Copy link
Contributor Author

Thanks for the update.

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