fix(types): render valid Enum type declarations - #493
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes EnumType.ToString() so it renders valid ClickHouse enum type declarations by properly quoting/escaping labels, using invariant integer formatting, and including the closing parenthesis—preventing malformed type names from surfacing via APIs like GetDataTypeName().
Changes:
- Fix enum declaration rendering to include proper quoting/escaping and correct closing syntax.
- Add a parser→renderer→parser regression test covering escaped quotes and
=inside labels. - Document the user-visible fix in the changelog and release notes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ClickHouse.Driver/Types/EnumType.cs | Updates ToString() to emit valid, escaped, invariant ClickHouse enum declarations. |
| ClickHouse.Driver.Tests/Types/EnumTypeTests.cs | Adds a regression test ensuring rendered enum declarations are parseable and preserve tricky labels. |
| CHANGELOG.md | Notes the bug fix in the Unreleased “Bug Fixes” section. |
| RELEASENOTES.md | Notes the bug fix in the Unreleased “Bug Fixes” section. |
| public override string ToString() => | ||
| $"{Name}({string.Join(", ", Values.Select(kvp => $"{kvp.Key.Escape().QuoteSingle()} = {kvp.Value.ToString(CultureInfo.InvariantCulture)}"))})"; |
There was a problem hiding this comment.
Values is populated from the parsed declaration, and preserving that insertion order keeps the rendered type consistent with the source declaration.
The previous implementation also enumerated Values directly, so this change does not introduce a new ordering dependency. Sorting by numeric value would instead change the declared member order, so I’d prefer to keep the current behavior.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Hi, thanks, the basic concept is good, a couple of issues though:
|
b2dcb9f to
bc0f193
Compare
main added 22 new Unreleased entries since this branch was cut. Each is now its own changelog.d/ fragment, extracted verbatim by line number rather than retyped, so the assembled Unreleased section reproduces main's exactly (as a set of lines; sorting by PR number reorders entries within their sections). New fragments, one per (PR, category): #390 improvements multidim blittable inserts #472 improvements per-scalar Span<byte> reads #484 fixes byte[]/TimeOnly HTTP parameters #485 fixes JSON strings under ReadStringsAsByteArrays #490 breaking raw results return compressed bytes #490 features AcceptEncoding response compression #490 improvements lz4 by default, HttpClient, errors, deflate #492 fixes HTTP response disposal #493 fixes Enum type declarations #494 fixes raw-stream double dispose #497 fixes GetSchema("Columns") restrictions #498 fixes JSON paths starting with setting names #503 fixes quoted JSON typed paths #504 fixes quoted Tuple/Nested element names #509 fixes {name:Type} scanner vs server lexer #511 fixes {name:Type} hints after a non-hint brace #513 fixes @name placeholders, heredocs, $ in names #390's entry was appended to the *released* v1.3.0 section on main (v1.3.0 shipped 2026-06-29), so it would have documented an unreleased change under a shipped version and never appeared in 1.4.0's notes. It moves to Unreleased as a fragment; the rest of v1.3.0 is byte-identical. RELEASENOTES.md regenerated with --sync-notes. `--check` passes, the solution builds, and the packed .nupkg's releaseNotes open on v1.3.0 with no Unreleased stub and no #390 bullet.
Summary
EnumType.ToString()currently omits the closing parenthesis and renders labels without ClickHouse quoting or escaping. This produces malformed type names through APIs such asGetDataTypeName().Render enum declarations using the existing ClickHouse string escaping helpers, invariant integer formatting, and canonical spacing.
Tests
Added a parser-renderer-parser regression covering escaped quotes and labels containing
=.