Skip to content

Add support for ValueTuple#291

Open
alex-clickhouse wants to merge 3 commits intomainfrom
valuetuple-support
Open

Add support for ValueTuple#291
alex-clickhouse wants to merge 3 commits intomainfrom
valuetuple-support

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

Summary

Adds support for ValueTuples on the write path, treating them in the same way as plain Tuples.

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 90.47619% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ClickHouse.Driver/Types/TypeConverter.cs 90.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 on lines +398 to +408
if (type.IsGenericType && type.GetGenericTypeDefinition().FullName!.StartsWith("System.ValueTuple", StringComparison.InvariantCulture))
{
// ValueTuple implements ITuple which already flattens the >7 element "rest" nesting,
// but the generic type arguments still contain the nested ValueTuple<TRest> structure.
var tuple = (ITuple)value;
var genericArgs = FlattenValueTupleTypes(type);
var items = new ClickHouseType[tuple.Length];
for (var i = 0; i < tuple.Length; i++)
{
items[i] = tuple[i] is { } itemValue ? ToClickHouseType(itemValue) : ToClickHouseType(genericArgs[i]);
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

FlattenValueTupleTypes(type) is assumed to produce the same number of element types as ((ITuple)value).Length, but this isn’t guaranteed for malformed ValueTuple<T1..T7, TRest> constructions (where TRest is not another ValueTuple). In that case the loop can end up indexing past genericArgs (or mapping an incorrect arity) and throw an IndexOutOfRangeException/confusing error. Consider validating genericArgs.Length == tuple.Length (and/or that the 8th generic arg is itself a ValueTuple) and throwing a clear ArgumentException when the ValueTuple shape is invalid.

Copilot uses AI. Check for mistakes.
Comment on lines +152 to +153
// Use ITuple[] so the array element type is known to be tuple-compatible
var tuples = new ITuple[] { (1, "one"), (2, "two") };
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This test uses an ITuple[] array, which only works here because ToClickHouseType(object) peeks the first element. If the array is empty (a common edge case for inserts), inference will fall back to the element type ITuple and fail with "Unknown type". Using a concrete ValueTuple array type (e.g., (int, string)[] / ValueTuple<int,string>[]) would keep inference working for both empty and non-empty arrays and better matches the scenario being tested.

Suggested change
// Use ITuple[] so the array element type is known to be tuple-compatible
var tuples = new ITuple[] { (1, "one"), (2, "two") };
// Use a concrete ValueTuple array type so tuple inference works for empty and non-empty arrays
var tuples = new (int, string)[] { (1, "one"), (2, "two") };

Copilot uses AI. Check for mistakes.
@Codex
Copy link
Copy Markdown
Contributor

Codex AI commented Apr 14, 2026

@codex[agent] review

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

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.

3 participants