Skip to content

Comments

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

Open
Shubhambhusate wants to merge 1 commit intodatabricks:mainfrom
Shubhambhusate:fix/float-to-double-parameter-inference
Open

Fix float inference to use DoubleParameter (64-bit) instead of FloatP…#742
Shubhambhusate wants to merge 1 commit intodatabricks:mainfrom
Shubhambhusate:fix/float-to-double-parameter-inference

Conversation

@Shubhambhusate
Copy link

…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
Author

Issue link: #741

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.

1 participant