Repository navigation
Map PostgreSQL numeric(p,0) with p>76 to Int256 in MaterializedPostgreSQL - #107431
Merged
Merged
Conversation
…tgreSQL PostgreSQL `numeric` can have a precision higher than ClickHouse `Decimal256` supports (76 digits); a common use case is `numeric(78, 0)` to store 256-bit integers. Previously this failed with "Precision N and scale M are too big and not supported". Map such columns (precision > 76, scale 0) to `Int256`, which natively holds 256-bit integers. Because wide-integer text parsing does not detect overflow, the value is verified by round-tripping it back to text on insert, so a value that does not fit into `Int256` is rejected with a clear error instead of being silently wrapped around. This also adds `vtInt256` to `ExternalResultDescription` and handles it in `insertPostgreSQLValue`. Closes: #59224 Related: #49045 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
|
Workflow [PR], commit [77afd1e] Summary: ✅
AI ReviewSummaryThis PR maps PostgreSQL Findings
Final VerdictStatus: Minimum required action: update the source-level |
…rt arrays The previous version was unreachable for the exact case it targeted: for a typed `numeric(78, 0)`, `DataTypeFactory::instance().get(type)` was called first and threw `Wrong precision: it must be between 1 and 76` before the `scale == 0` branch could map it to `Int256`. Parse the precision and scale directly from the type string (e.g. "numeric(78,0)") so the over-precision, scale-0 case can be mapped to `Int256` without going through the Decimal factory. Also handle `numeric(p, 0)[]` arrays, which become `Array(Int256)`: add an `Int256` branch (with the same round-trip overflow check) to `preparePostgreSQLArrayInfo`, which previously threw "Type conversion to Int256 is not supported". Co-Authored-By: Claude Opus 4.8 <[email protected]>
The manual precision/scale parser added for the `numeric(p, 0)` -> `Int256` mapping constructed `DataTypeDecimal<...>` directly, which only checks `scale <= maxPrecision`. This dropped the `scale > precision` rejection that `createDecimal` (reached via `DataTypeFactory` before) used to provide, so a PostgreSQL `numeric(5, 7)` would become an invalid `Decimal32(5, 7)`. Use `createDecimal<DataTypeDecimal>` for `precision <= 76` to restore the validation and dispatch, keeping the `Int256` special case only for `precision > 76 && scale == 0`. Add a regression test (`test_numeric_int256_validation`) covering both the `scale > precision` rejection and the `Int256` overflow guard, exercised synchronously via the `postgresql` table function. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Update the PostgreSQL data-type mapping table to mention that `numeric(p, 0)` with precision greater than 76 (e.g. `numeric(78, 0)`) is inferred as `Int256`, and that out-of-range values are rejected. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 32/49 (65.31%) | Lost baseline coverage: none · Uncovered code |
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.
PostgreSQL
numericcan have a precision higher than ClickHouseDecimal256supports (76 digits). A common case isnumeric(78, 0), used to store 256-bit integers (uint256).MaterializedPostgreSQLpreviously failed to create such a table with:This PR maps
numeric(p, 0)withp > 76to ClickHouseInt256, which natively holds 256-bit integers (PostgreSQLnumericis signed, henceInt256).Wide-integer text parsing in ClickHouse intentionally does not detect overflow (
readIntText.hskips the check for big integers). To avoid silently storing a wrapped-around value, the parsed value is verified by round-tripping it back to text on insert; a value that does not fit intoInt256is rejected with a clearout of range of Int256error.Mechanically this adds a
vtInt256value type toExternalResultDescriptionand handles it ininsertPostgreSQLValue(other sources keep their existingdefault:handling, so this is a no-op for them).The integration test replicates a
numeric(78, 0)column holding the maximumInt256value, a negative value and zero, checks the resulting column isInt256with matching values, and that ongoing replication works.Closes: #59224
Related: #49045
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
MaterializedPostgreSQLnow maps PostgreSQLnumeric(p, 0)columns with precision greater than 76 (e.g.numeric(78, 0)used for 256-bit integers) to ClickHouseInt256instead of failing with "Precision too big". Values that do not fit intoInt256are rejected with a clear error.Documentation entry for user-facing changes
🤖 Generated with Claude Code