Types: Compile Float without a precision to DOUBLE - #317
Open
aminghadersohi wants to merge 2 commits into
Open
aminghadersohi wants to merge 2 commits into
aminghadersohi wants to merge 2 commits into
Conversation
CrateDB's FLOAT is the 4-byte REAL, so a generic Float column rounded Python floats to 24 bits of precision. SQLAlchemy documents a precision-less Float as 8-byte on backends that distinguish the two. Float(precision<=24), REAL and the uppercase FLOAT type still render 4-byte columns.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
sa.Double does not exist on SQLAlchemy 1.3/1.4, so importing compiler_test failed and stopped the whole test run on those versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sa.Float()without a precision compiles toFLOAT, which is CrateDB's 4-byteREAL. Python floats are 8-byte, so values written through a genericFloatcolumn are silently rounded to 24 bits of precision. Against CrateDB 5.10.16:SQLAlchemy's
Floatdocumentation (quoted invisit_FLOAT's docstring) describes a precision-lessFloatas 8-byte on backends that distinguish the two. PostgreSQL and MSSQL renderFLOATthere, which on those backends means double precision. To get a 4-byte type, the documentation says to pass a precision of 24 or lower, or to useREAL.Change
Add
visit_floatfor the genericFloattype. With no precision it rendersDOUBLE. Otherwise it defers to the existingvisit_FLOAT, so a precision of 24 or lower still rendersFLOATand higher precisions renderDOUBLE. The uppercasesa.FLOATtype is untouched and still rendersFLOAT.REALandDoubleare also untouched and renderREALandDOUBLE.This changes the DDL of existing code that uses
sa.Float(), so the changelog entry is marked BREAKING. Existing tables are not affected. pandas'to_sqlusesFloat(precision=53)forfloat64columns, so its DDL is unchanged.Tests
test_float_ddlintests/compiler_test.pycoversFloat(),Float(asdecimal=True), precisions 10, 24, 25 and 53,FLOAT,REAL, andDouble(on SQLAlchemy 2.0+, where it exists). The expected DDL increate_table_test.pychanges tofloat_col DOUBLE.poe lintis clean andintegration.pypasses. pytest gives 208 passed on SQLAlchemy 2.1.1, 193 passed on 1.4.54, and 131 passed on 1.3.24. On 1.3 there is one failure,test_schema.py::test_correct_schema, which fails the same way onmain.Float()column: onmainit was created asrealand0.1 + 2**-40read back as0.1. On this branch it isdouble precisionand the value round-trips exactly.