Implement joins, unions, subqueries and extend tests#10
Merged
alex-clickhouse merged 3 commits intomainfrom Apr 17, 2026
Merged
Implement joins, unions, subqueries and extend tests#10alex-clickhouse merged 3 commits intomainfrom
alex-clickhouse merged 3 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR extends the ClickHouse EF Core provider to support more relational query patterns (joins, set operations, and correlated subqueries), aligns type mapping to EF Core’s ValuesExpression/nullability processing expectations, and updates/expands test coverage (including Northwind conformance suites) to reflect full Northwind data and ClickHouse-specific behaviors.
Changes:
- Add/override SQL generation for set operations,
COUNT()typing, NULL ordering, scalar subquery null behavior, and VALUES-source rewriting. - Adjust type mappings and mapping resolution for
intand array/collection parameters used in inline VALUES expansion. - Update and expand functional/integration tests, including new Northwind join/set-ops suites and updated expected results.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.ClickHouse.Tests/JoinAndSetOperationTests.cs | Adds integration tests for joins, correlated subqueries, and set operations against a seeded ClickHouse schema. |
| test/EFCore.ClickHouse.FunctionalTests/TestUtilities/ClickHouseTestStore.cs | Forces test contexts to use the connection-string path and appends set_join_use_nulls=1 to ensure correct LEFT JOIN null semantics. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindWhereQueryClickHouseTest.cs | Updates assertions to match full Northwind dataset results. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindSetOperationsQueryClickHouseTest.cs | Introduces ClickHouse-specific set-operations conformance suite overrides/skips for known server limitations. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindJoinQueryClickHouseTest.cs | Introduces ClickHouse-specific join conformance suite overrides for unsupported APPLY patterns and known translation limitations. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindFunctionsQueryClickHouseTest.cs | Updates expected results for string function tests to match full dataset. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindCompiledQueryClickHouseTest.cs | Updates compiled query expectations to match full dataset. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindAsTrackingQueryClickHouseTest.cs | Updates tracking test expectations to match full dataset size. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindAsNoTrackingQueryClickHouseTest.cs | Updates no-tracking test expectations to match full dataset size. |
| test/EFCore.ClickHouse.FunctionalTests/Query/NorthwindAggregateOperatorsQueryClickHouseTest.cs | Updates aggregate expectations (count/sum) to match full dataset values. |
| src/EFCore.ClickHouse/Storage/Internal/Mapping/ClickHouseInt32TypeMapping.cs | Adds an IntTypeMapping-derived mapping to satisfy EF Core hard-cast paths and safe materialization for int. |
| src/EFCore.ClickHouse/Storage/Internal/Mapping/ClickHouseArrayTypeMapping.cs | Wires element type mapping into CoreTypeMappingParameters and conditionally hides it for composite elements to satisfy EF model validation. |
| src/EFCore.ClickHouse/Storage/Internal/ClickHouseTypeMappingSource.cs | Prioritizes array mapping when EF provides ElementTypeMapping and broadens collection CLR type handling for inline VALUES scenarios. |
| src/EFCore.ClickHouse/Storage/Internal/ClickHouseRelationalConnection.cs | Ensures default session settings are applied even when constructing a connection directly from a connection string. |
| src/EFCore.ClickHouse/Storage/Internal/ClickHouseDataSourceManager.cs | Normalizes connection strings via EnsureDefaultSettings before pooling/caching data sources; introduces shared settings injection helper. |
| src/EFCore.ClickHouse/Query/Internal/ClickHouseQuerySqlGenerator.cs | Adds ClickHouse-specific SQL generation for set ops, COUNT casting, NULL ordering, scalar subquery behavior, and VALUES rewriting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
null(not column defaults) via injectedset_join_use_nulls=1IN,EXISTS/Any,All, scalar subqueries in projectionsConcat,Union,Intersect,ExceptJoin(localIds, ...),Contains(localList))SQL generator overrides (
ClickHouseQuerySqlGenerator)Each addresses a documented dialect quirk:
GenerateSetOperation— emit explicitALL/DISTINCT(bareUNIONis rejected)VisitSqlFunction—CAST(COUNT(...) AS Int32/Int64)so set operations type-matchVisitOrdering—NULLS FIRST/LASTfor nullable expressions only (avoids reorderingNaNin non-nullable floats)VisitNonNullableScalarSubquery— wrap withifNull(..., 0)(ClickHouse returns NULL for no-match aggregates)GenerateValues— rewriteVALUES (...)asSELECT ... UNION ALL SELECT ...(ClickHouse rejectsVALUESas a subquery source)Type mapping changes
The
ValuesExpressionpath requires three coordinated changes:ClickHouseInt32TypeMapping(new) — inherits from EF Core'sIntTypeMappingto satisfy a hard cast inSqlNullabilityProcessor. Other integers continue to use the shared mapping.ClickHouseArrayTypeMapping— wiresElementTypeMappingintoCoreTypeMappingParameters, hidden for composite elements (nested arrays, tuples, variants) to avoid the model validator's "primitive collection of a primitive collection" rejection.ClickHouseTypeMappingSource— prioritizesFindArrayMappingwhen EF suppliesElementTypeMapping+ a recognized collection CLR type (T[],List<T>,IEnumerable<T>, etc.).Tests
NorthwindJoinQueryClickHouseTest,NorthwindSetOperationsQueryClickHouseTest(skips documented inline)Northwind.ClickHouse.sql: 42 columns →Nullable(String), ~712 empty strings → NULL so LEFT JOIN assertions see real NULLs