Skip to content

Bound Decimal rendering to ClickHouse precision limits#271

Merged
ruslandoga merged 1 commit intomasterfrom
ruslandoga+conductor/apply-eric-patch
May 5, 2026
Merged

Bound Decimal rendering to ClickHouse precision limits#271
ruslandoga merged 1 commit intomasterfrom
ruslandoga+conductor/apply-eric-patch

Conversation

@ruslandoga
Copy link
Copy Markdown
Collaborator

@ruslandoga ruslandoga commented May 5, 2026

Bounds Decimal SQL rendering and parameter typing to ClickHouse Decimal256 precision and scale limits.

Adds shared Decimal validation for inline literals and parameter types, rejecting non-finite or over-limit values with ArgumentError.

Updates Decimal parameter typing to emit Decimal(precision, scale) instead of always Decimal64(scale), and adds focused coverage for valid and rejected Decimal values.

Validation: the 4 new Decimal tests pass; the full connection test file still has one unrelated existing VALUES column-order assertion failure.

The adapter previously emitted Decimal64(scale) for every Decimal parameter regardless of value size and rendered the coefficient with Decimal.to_string/2 verbatim. Both the inline literal path (expr/4) and the parameter type path (param_type/1) are now guarded by a shared decimal_precision_and_scale!/1 helper that:

- rejects non-finite values (NaN, Infinity) with ArgumentError
- rejects scale > 76 with ArgumentError
- rejects coefficients with more than 76 digits with ArgumentError
- rejects computed precision > 76 with ArgumentError

param_type/1 now emits Decimal(precision, scale) sized to the actual value (up to ClickHouse's Decimal256 ceiling of precision 76) instead of always Decimal64(scale). Rendering goes through a new decimal_to_string/1 helper that, when the upstream Decimal library exposes Decimal.to_string/3 with :max_digits, caps output at 77 digits and otherwise falls back to Decimal.to_string/2.

Behavioral change for callers: Decimal parameters and inlined Decimal literals that exceed ClickHouse's Decimal limits, or that are NaN or Infinity, now raise ArgumentError at render time instead of silently producing malformed SQL. No new public option or API surface is added.
@ruslandoga ruslandoga marked this pull request as ready for review May 5, 2026 17:35
@ruslandoga ruslandoga merged commit 377a760 into master May 5, 2026
5 checks passed
@ruslandoga ruslandoga deleted the ruslandoga+conductor/apply-eric-patch branch May 5, 2026 17:36
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.

2 participants