Skip to content

Commit 807deb8

Browse files
ajcvickersclaude
andcommitted
Fix set-operation primitive collection tests on SQL Server 2019/2022
The new tests asserted SQL Server 2025 baselines (JSON_CONTAINS, and a SqlException for UNION/DISTINCT over the json type) unconditionally. On earlier versions the column is nvarchar(max), so the OPENJSON translation is used and UNION/DISTINCT succeed. Branch on IsJsonTypeSupported. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent a281882 commit 807deb8

1 file changed

Lines changed: 166 additions & 16 deletions

File tree

‎test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs‎

Lines changed: 166 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2790,8 +2790,10 @@ public override async Task Concat_of_column_collections_then_Contains()
27902790
{
27912791
await base.Concat_of_column_collections_then_Contains();
27922792

2793-
AssertSql(
2794-
"""
2793+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
2794+
{
2795+
AssertSql(
2796+
"""
27952797
SELECT [u].[Ints]
27962798
FROM (
27972799
SELECT [p].[Ints]
@@ -2802,22 +2804,66 @@ FROM [PrimitiveCollectionsEntity] AS [p0]
28022804
) AS [u]
28032805
WHERE JSON_CONTAINS([u].[Ints], 10) = 1
28042806
""");
2807+
}
2808+
else
2809+
{
2810+
AssertSql(
2811+
"""
2812+
SELECT [u].[Ints]
2813+
FROM (
2814+
SELECT [p].[Ints]
2815+
FROM [PrimitiveCollectionsEntity] AS [p]
2816+
UNION ALL
2817+
SELECT [p0].[Ints]
2818+
FROM [PrimitiveCollectionsEntity] AS [p0]
2819+
) AS [u]
2820+
WHERE 10 IN (
2821+
SELECT [i].[value]
2822+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
2823+
)
2824+
""");
2825+
}
28052826
}
28062827

28072828
public override async Task Union_of_column_collections_then_Contains()
28082829
{
2809-
// The json data type isn't comparable, so it can't be used with UNION or DISTINCT (UNION ALL is fine)
2810-
await Assert.ThrowsAsync<SqlException>(() => base.Union_of_column_collections_then_Contains());
2830+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
2831+
{
2832+
// The json data type isn't comparable, so it can't be used with UNION or DISTINCT (UNION ALL is fine)
2833+
await Assert.ThrowsAsync<SqlException>(() => base.Union_of_column_collections_then_Contains());
28112834

2812-
AssertSql();
2835+
AssertSql();
2836+
}
2837+
else
2838+
{
2839+
await base.Union_of_column_collections_then_Contains();
2840+
2841+
AssertSql(
2842+
"""
2843+
SELECT [u].[Ints]
2844+
FROM (
2845+
SELECT [p].[Ints]
2846+
FROM [PrimitiveCollectionsEntity] AS [p]
2847+
UNION
2848+
SELECT [p0].[Ints]
2849+
FROM [PrimitiveCollectionsEntity] AS [p0]
2850+
) AS [u]
2851+
WHERE 10 IN (
2852+
SELECT [i].[value]
2853+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
2854+
)
2855+
""");
2856+
}
28132857
}
28142858

28152859
public override async Task Concat_of_anonymous_types_with_column_collection_then_Contains()
28162860
{
28172861
await base.Concat_of_anonymous_types_with_column_collection_then_Contains();
28182862

2819-
AssertSql(
2820-
"""
2863+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
2864+
{
2865+
AssertSql(
2866+
"""
28212867
SELECT [u].[Id], [u].[Ints]
28222868
FROM (
28232869
SELECT [p].[Id], [p].[Ints]
@@ -2828,6 +2874,25 @@ FROM [PrimitiveCollectionsEntity] AS [p0]
28282874
) AS [u]
28292875
WHERE JSON_CONTAINS([u].[Ints], 10) = 1
28302876
""");
2877+
}
2878+
else
2879+
{
2880+
AssertSql(
2881+
"""
2882+
SELECT [u].[Id], [u].[Ints]
2883+
FROM (
2884+
SELECT [p].[Id], [p].[Ints]
2885+
FROM [PrimitiveCollectionsEntity] AS [p]
2886+
UNION ALL
2887+
SELECT [p0].[Id], [p0].[Ints]
2888+
FROM [PrimitiveCollectionsEntity] AS [p0]
2889+
) AS [u]
2890+
WHERE 10 IN (
2891+
SELECT [i].[value]
2892+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
2893+
)
2894+
""");
2895+
}
28312896
}
28322897

28332898
public override async Task Concat_of_column_collections_then_Where_Count()
@@ -2855,8 +2920,10 @@ public override async Task Concat_of_string_column_collections_then_Contains()
28552920
{
28562921
await base.Concat_of_string_column_collections_then_Contains();
28572922

2858-
AssertSql(
2859-
"""
2923+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
2924+
{
2925+
AssertSql(
2926+
"""
28602927
SELECT [u].[Strings]
28612928
FROM (
28622929
SELECT [p].[Strings]
@@ -2867,14 +2934,35 @@ FROM [PrimitiveCollectionsEntity] AS [p0]
28672934
) AS [u]
28682935
WHERE JSON_CONTAINS([u].[Strings], N'10') = 1
28692936
""");
2937+
}
2938+
else
2939+
{
2940+
AssertSql(
2941+
"""
2942+
SELECT [u].[Strings]
2943+
FROM (
2944+
SELECT [p].[Strings]
2945+
FROM [PrimitiveCollectionsEntity] AS [p]
2946+
UNION ALL
2947+
SELECT [p0].[Strings]
2948+
FROM [PrimitiveCollectionsEntity] AS [p0]
2949+
) AS [u]
2950+
WHERE N'10' IN (
2951+
SELECT [s].[value]
2952+
FROM OPENJSON([u].[Strings]) WITH ([value] nvarchar(max) '$') AS [s]
2953+
)
2954+
""");
2955+
}
28702956
}
28712957

28722958
public override async Task Concat_of_column_collections_then_Contains_parameter()
28732959
{
28742960
await base.Concat_of_column_collections_then_Contains_parameter();
28752961

2876-
AssertSql(
2877-
"""
2962+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
2963+
{
2964+
AssertSql(
2965+
"""
28782966
@value='10'
28792967
28802968
SELECT [u].[Ints]
@@ -2887,14 +2975,37 @@ FROM [PrimitiveCollectionsEntity] AS [p0]
28872975
) AS [u]
28882976
WHERE JSON_CONTAINS([u].[Ints], @value) = 1
28892977
""");
2978+
}
2979+
else
2980+
{
2981+
AssertSql(
2982+
"""
2983+
@value='10'
2984+
2985+
SELECT [u].[Ints]
2986+
FROM (
2987+
SELECT [p].[Ints]
2988+
FROM [PrimitiveCollectionsEntity] AS [p]
2989+
UNION ALL
2990+
SELECT [p0].[Ints]
2991+
FROM [PrimitiveCollectionsEntity] AS [p0]
2992+
) AS [u]
2993+
WHERE @value IN (
2994+
SELECT [i].[value]
2995+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
2996+
)
2997+
""");
2998+
}
28902999
}
28913000

28923001
public override async Task Concat_of_column_collections_then_Contains_then_Select_Count()
28933002
{
28943003
await base.Concat_of_column_collections_then_Contains_then_Select_Count();
28953004

2896-
AssertSql(
2897-
"""
3005+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
3006+
{
3007+
AssertSql(
3008+
"""
28983009
SELECT (
28993010
SELECT COUNT(*)
29003011
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
@@ -2908,14 +3019,53 @@ FROM [PrimitiveCollectionsEntity] AS [p0]
29083019
) AS [u]
29093020
WHERE JSON_CONTAINS([u].[Ints], 10) = 1
29103021
""");
3022+
}
3023+
else
3024+
{
3025+
AssertSql(
3026+
"""
3027+
SELECT (
3028+
SELECT COUNT(*)
3029+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i0]
3030+
WHERE [i0].[value] > 1)
3031+
FROM (
3032+
SELECT [p].[Ints]
3033+
FROM [PrimitiveCollectionsEntity] AS [p]
3034+
UNION ALL
3035+
SELECT [p0].[Ints]
3036+
FROM [PrimitiveCollectionsEntity] AS [p0]
3037+
) AS [u]
3038+
WHERE 10 IN (
3039+
SELECT [i].[value]
3040+
FROM OPENJSON([u].[Ints]) WITH ([value] int '$') AS [i]
3041+
)
3042+
""");
3043+
}
29113044
}
29123045

29133046
public override async Task Distinct_of_column_collection_then_Contains()
29143047
{
2915-
// The json data type isn't comparable, so it can't be used with UNION or DISTINCT (UNION ALL is fine)
2916-
await Assert.ThrowsAsync<SqlException>(() => base.Distinct_of_column_collection_then_Contains());
3048+
if (SqlServerTestEnvironment.IsJsonTypeSupported)
3049+
{
3050+
// The json data type isn't comparable, so it can't be used with UNION or DISTINCT (UNION ALL is fine)
3051+
await Assert.ThrowsAsync<SqlException>(() => base.Distinct_of_column_collection_then_Contains());
29173052

2918-
AssertSql();
3053+
AssertSql();
3054+
}
3055+
else
3056+
{
3057+
await base.Distinct_of_column_collection_then_Contains();
3058+
3059+
AssertSql(
3060+
"""
3061+
SELECT DISTINCT [p].[Ints]
3062+
FROM [PrimitiveCollectionsEntity] AS [p]
3063+
WHERE 10 IN (
3064+
SELECT [i].[value]
3065+
FROM OPENJSON([p].[Ints]) WITH ([value] int '$') AS [i]
3066+
)
3067+
""");
3068+
}
29193069
}
29203070

29213071
public override async Task Parameter_collection_Concat_column_collection()

0 commit comments

Comments
 (0)