Repository navigation
Conversation
`get_columns()` read only `data_type` from `information_schema.columns`, so a `NUMERIC(10, 2)` column was reflected as a bare `NUMERIC`. A table created from it raised `CompileError`, and values read back with ten decimal places instead of the column's scale. Read `numeric_precision` and `numeric_scale` too, and use them for a `numeric` column when both are present. CrateDB reports the scale since 6.4.6. Older servers report the precision with a NULL scale, which means unknown rather than zero, so such columns stay a bare `NUMERIC` instead of silently becoming `NUMERIC(p)`. Other types report a fixed bit width and ignore the values. Arrays of `NUMERIC` report neither and stay unchanged. Fixes crate#313 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Follow the file's convention and assert the `CREATE TABLE` that a reflected column renders, instead of the type's attributes. The new helper `render_row_ddl` passes an `information_schema` row through `_create_column_info()`; the string-length test uses it too. A bare `NUMERIC` has no valid DDL, because `CrateDDLCompiler` refuses it, so the tests for a column without both values check the type compiler's output instead of DDL or the refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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.
Fixes #313.
Before and after
The script in the appendix reflects this table on CrateDB 6.4.6:
Before, on
main:After, with this change:
The change
get_columns()now also readsnumeric_precisionandnumeric_scalefrominformation_schema.columns. Anumericcolumn uses them only when both are present.Integer and float types ignore the reported values: their precision is a bit width fixed by the type, not a value the user declared.
Tests
NUMERIC(10, 2)in the DDL.NUMERIC(5)with a scale of zero, and it renders asNUMERIC(5, 0), as in SQLAlchemy's PostgreSQL dialect.NUMERIC.NUMERIC.INT.NUMERIC(10, 2)andNUMERIC(5, 0)and reads its value at the column's scale. On a server before 6.4.6, its columns stay a bareNUMERIC.Follow-ups
Numeric()and with standard SQL: CrateDB rejects aNUMERICcolumn without a precision (NUMERIC storage is only supported if precision and scale are specified), while PostgreSQL, for example, stores it as an unconstrained decimal. The dialect therefore refuses such DDL, and the tests for a bareNUMERICcheck the rendered type instead.NUMERICstill reflect without precision.CREATE TABLEfrom a reflected table with a primary key fails: reflection marks every column as nullable, the primary key included.Appendix
repro_313.py, the script that produced the output in "Before and after".