Skip to content

Parameter type resolution extensibility#275

Merged
alex-clickhouse merged 6 commits intomainfrom
parameter-type-extensibility
Apr 13, 2026
Merged

Parameter type resolution extensibility#275
alex-clickhouse merged 6 commits intomainfrom
parameter-type-extensibility

Conversation

@alex-clickhouse
Copy link
Copy Markdown
Collaborator

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

Summary

Currently, when using @-style parameters as opposed to ClickHouse-style {param:type} (eg SELECT * FROM foo WHERE bar = @param), the driver infers the ClickHouse type based on the .NET type. DateTime maps to DateTime etc. Overriding this requires specifying the type on each parameter, which can be tedious.

Here we add a new extensibility point via the IParameterTypeResolver interface, a new property on the ClickHouseClientSettings. This allows users to customize the parameter type resolution depending on type and/or value. A simple implementation that covers basic use cases, DictionaryParameterTypeResolver is also included.

This PR also streamlines parameter type resolution in ParameterTypeResolution. Previously the logic was scattered across multiple classes; now it's centralized and the priority between different type resolution sources is clear (explicit type > SQL hint > resolver > default inference). Public API listings were updated accordingly, and an advanced example was added to demonstrate resolver usage.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

…pping

Introduces a plugin system that allows users to control the default
ClickHouse type inference for @-style parameterized queries. Previously,
the only way to override type inference (e.g., DateTime → DateTime64(3))
was to set ClickHouseType on every individual parameter.

Key changes:
- IParameterTypeResolver interface + DictionaryParameterTypeResolver
- Central ParameterTypeResolution class replacing scattered resolution logic
- Type resolved exactly once per parameter per request for consistency
- ParameterTypeResolver property on ClickHouseClientSettings
Copilot AI review requested due to automatic review settings April 2, 2026 10:03
@alex-clickhouse alex-clickhouse requested a review from mzitnik as a code owner April 2, 2026 10:03
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

❌ Patch coverage is 94.11765% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../ADO/Parameters/DictionaryParameterTypeResolver.cs 66.66% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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 an extensibility point for resolving ClickHouse parameter types for @-style parameters, allowing consumers to override the default CLR→ClickHouse type inference via a new IParameterTypeResolver on ClickHouseClientSettings. This centralizes parameter type resolution into a single flow so SQL placeholder generation and HTTP parameter formatting remain consistent.

Changes:

  • Introduces IParameterTypeResolver (+ DictionaryParameterTypeResolver) and wires it into ClickHouseClientSettings and query execution.
  • Centralizes type precedence in ParameterTypeInference (explicit type > SQL hint > resolver > default inference) and updates placeholder replacement / HTTP formatting to use the same resolved type names.
  • Adds docs/examples and new unit/integration tests validating resolver behavior across HTTP transport modes and ADO.NET.

Reviewed changes

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

Show a summary per file
File Description
ClickHouse.Driver/ADO/Parameters/IParameterTypeResolver.cs New public resolver interface for custom type resolution.
ClickHouse.Driver/ADO/Parameters/DictionaryParameterTypeResolver.cs Simple built-in resolver implementation.
ClickHouse.Driver/ADO/Parameters/ParameterTypeInference.cs Centralized type resolution precedence logic.
ClickHouse.Driver/ADO/ClickHouseClientSettings.cs Adds ParameterTypeResolver setting and copies/compares it.
ClickHouse.Driver/ClickHouseClient.cs Resolves parameter types once per request and reuses for placeholders + HTTP formatting.
ClickHouse.Driver/ADO/Parameters/ClickHouseParameterCollection.cs Replaces @name placeholders using pre-resolved type names.
ClickHouse.Driver/Formats/HttpParameterFormatter.cs Formatting now requires an already-resolved ClickHouse type name.
ClickHouse.Driver/ADO/Parameters/ClickHouseDbParameter.cs QueryForm now uses centralized inference (without resolver/hints).
ClickHouse.Driver.Tests/* Adds/updates tests for resolver precedence and transport consistency.
examples/*, CHANGELOG.md, RELEASENOTES.md Documentation and runnable example for the new resolver feature.

Comment thread ClickHouse.Driver/ADO/Parameters/DictionaryParameterTypeResolver.cs Outdated
Comment thread ClickHouse.Driver/ADO/Parameters/ClickHouseParameterCollection.cs
Comment thread ClickHouse.Driver/ClickHouseClient.cs
Comment thread ClickHouse.Driver.Tests/SQL/ParameterTypeInferenceIntegrationTests.cs Outdated
@alex-clickhouse
Copy link
Copy Markdown
Collaborator Author

Not really happy with the ParameterTypeInference name, any better ideas would be appreciated.

@alex-clickhouse
Copy link
Copy Markdown
Collaborator Author

@codex[agent] review

Co-authored-by: alex-clickhouse <237136924+alex-clickhouse@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ alex-clickhouse
❌ Codex
You have signed the CLA already but the status is still pending? Let us recheck it.

@Codex
Copy link
Copy Markdown
Contributor

Codex AI commented Apr 2, 2026

Not really happy with the ParameterTypeInference name, any better ideas would be appreciated.

Renamed the helper to ParameterTypeResolution throughout code/docs to reflect the resolved-type pipeline role. (b074041)

@codex[agent] review

Completed review below; no blocking issues found. (a904dfc)

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b66b5f97f7

ℹ️ 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".

Comment thread ClickHouse.Driver/ClickHouseClient.cs
Co-authored-by: alex-clickhouse <237136924+alex-clickhouse@users.noreply.github.com>
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

Just dropped one questions regarding testing

/// </summary>
[TestFixture(false)]
[TestFixture(true)]
public class ParameterTypeResolutionIntegrationTests
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

General question: Does it make sense to add some unsupported type to the tests

Copy link
Copy Markdown
Collaborator Author

@alex-clickhouse alex-clickhouse Apr 13, 2026

Choose a reason for hiding this comment

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

By unsupported you mean a .NET type that doesn't map to any ClickHouse type, or a mapping that would not actually work? I'd say probably not?

@alex-clickhouse alex-clickhouse merged commit 6f8b411 into main Apr 13, 2026
16 checks passed
@alex-clickhouse alex-clickhouse deleted the parameter-type-extensibility branch April 13, 2026 13:02
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.

5 participants