Skip to content

Add support for ValueTuple#291

Merged
alex-clickhouse merged 10 commits intomainfrom
valuetuple-support
Apr 17, 2026
Merged

Add support for ValueTuple#291
alex-clickhouse merged 10 commits intomainfrom
valuetuple-support

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

@alex-clickhouse alex-clickhouse commented Apr 14, 2026

Summary

  • Add support for C# ValueTuple types (unlike the old Tuple, ValueTuple is not a reference type but a value type) as parameter values and in InsertBinaryAsync, mapping them to ClickHouse Tuple(T1, T2, ...) columns
  • The existing TupleType.Write() already handled both via the ITuple interface, so the changes are in type inference (TypeConverter)
  • For ValueTuples with >7 elements (e.g., (1,2,3,4,5,6,7,"eight"), the C# compiler produces a nested ValueTuple, where the 8th generic type (<T1, T2, ..., T7, TRest>) is another ValueTuple that has the rest of the elements. We handle this scenario by flattening the structure.
  • Implements the TRest handling for System.Tuple as well, this was broken before.
  • Works with both named (Tuple(a Int32, b Int32)) and unnamed (Tuple(Int32, Int32)) ClickHouse tuples
  • Added ITuple element-by-element comparison to TestUtilities.AssertEqual so Tuple-vs-ValueTuple comparisons work in tests

Known limitation

When a ValueTuple has exactly 7 scalar elements followed by a tuple element (e.g., Tuple(Int32, ..., Int32, Tuple(String, String))), the driver cannot distinguish this from a 9-element flat tuple. Both produce the same .NET type due to C# compiler TRest nesting. The driver treats the 8th generic argument as TRest (flattens it). The workaround is a doubly-nested tuple for the 8th element. Will also add a note for this in the docs.

Copilot AI review requested due to automatic review settings April 14, 2026 08:44
@alex-clickhouse
Copy link
Copy Markdown
Collaborator Author

@codex[agent] review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ClickHouse.Driver/Types/TypeConverter.cs 89.47% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds write-path support for System.ValueTuple by treating ValueTuples the same as tuples during ClickHouse type inference and parameter/binary insert handling, including flattening of compiler-generated TRest nesting for tuples with >7 elements.

Changes:

  • Extend TypeConverter to recognize System.ValueTuple (type-based and value-based inference) and flatten TRest nesting for >7 elements.
  • Add/extend tests covering ValueTuple type mapping, binary inserts, and SQL parameterized queries.
  • Document the new feature in release notes and changelog.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
RELEASENOTES.md Document ValueTuple write-path support for v1.3.0.
CHANGELOG.md Add v1.3.0 entry describing ValueTuple write-path support.
ClickHouse.Driver/Types/TypeConverter.cs Add ValueTuple detection and TRest-flattening for accurate ClickHouse Tuple(...) inference.
ClickHouse.Driver.Tests/Types/TypeMappingTests.cs Add type mapping and value-based inference test cases for ValueTuple, including >7 elements.
ClickHouse.Driver.Tests/Types/TupleTypeTests.cs Add binary insert round-trip tests for ValueTuple scenarios (nested, nullable, arrays, >7 elements).
ClickHouse.Driver.Tests/SQL/SqlParameterizedSelectTests.cs Add SQL parameterization tests passing ValueTuple parameters (including nested).

Comment thread ClickHouse.Driver/Types/TypeConverter.cs Outdated
Comment thread ClickHouse.Driver.Tests/Types/TupleTypeTests.cs Outdated
@Codex
Copy link
Copy Markdown
Contributor

Codex AI commented Apr 14, 2026

@codex[agent] review

Reviewed 3399bcf; feedback posted in the review summary below.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread CHANGELOG.md Outdated
Comment thread ClickHouse.Driver/Types/TypeConverter.cs Outdated
Comment thread ClickHouse.Driver/Types/TypeConverter.cs Outdated
Comment thread RELEASENOTES.md Outdated
Copy link
Copy Markdown
Contributor

@mzitnik mzitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alex-clickhouse alex-clickhouse merged commit f4c19b0 into main Apr 17, 2026
16 checks passed
@alex-clickhouse alex-clickhouse deleted the valuetuple-support branch April 17, 2026 07:51
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.

4 participants