From b861a677c8c5f6404d588fc8507a6cb60476ba69 Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Tue, 12 Aug 2025 19:23:30 +0530 Subject: [PATCH 1/7] Enable vector tests and validate ref assembly for vector APIs --- .../src/Microsoft/Data/SqlTypes/SqlVector.cs | 2 +- .../ManualTests/DataCommon/DataTestUtility.cs | 2 +- .../VectorTest/NativeVectorFloat32Tests.cs | 43 +++++++++++++++++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs index ea7bab78bf..cf04ff8636 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlTypes/SqlVector.cs @@ -58,7 +58,7 @@ private SqlVector(int length) /// public static SqlVector CreateNull(int length) => new(length); - /// + /// public SqlVector(ReadOnlyMemory memory) { (_elementType, _elementSize) = GetTypeFieldsOrThrow(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index b3f90cd34e..511d16d069 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -96,7 +96,7 @@ public static class DataTestUtility public static readonly bool IsJsonSupported = false; // VECTOR column type - public static readonly bool IsVectorSupported = false; + public static readonly bool IsVectorSupported = !IsNotAzureServer(); // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index d2d8c52716..1d01ea9e4d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -148,7 +148,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, object value, @@ -214,7 +214,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, object value, @@ -248,7 +248,7 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestStoredProcParamsForVectorFloat32( int pattern, object value, @@ -305,7 +305,7 @@ public void TestStoredProcParamsForVectorFloat32( } [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] - [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData))] + [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, object value, @@ -586,5 +586,40 @@ public void TestInsertVectorsFloat32WithPrepare() } Assert.Equal(10, rowcnt); } + + + // We need this testcase to validate ref assembly for vector APIs + // Unit tests are covered under SqlVectorTest.cs + [Fact] + public void VectorAPITest() + { + // Validate that SqlVector is a valid type and has valid SqlDbType + Assert.True(typeof(SqlVector).IsValueType, "SqlVector should be a value type."); + Assert.Equal(36, (int)SqlDbTypeExtensions.Vector); + + // Validate ctor1 with float[] : public SqlVector(System.ReadOnlyMemory memory) { } + var vector = new SqlVector(VectorFloat32TestData.testData); + Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + Assert.Equal(3, vector.Length); + + // Validate ctor2 with ReadOnlyMemory : public SqlVector(ReadOnlyMemory memory) { } + vector = new SqlVector(new ReadOnlyMemory(VectorFloat32TestData.testData)); + Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + Assert.Equal(3, vector.Length); + + //Validate IsNull property + Assert.False(vector.IsNull, "IsNull should be false for non-null vector."); + + // Validate Null property returns null + Assert.Null(SqlVector.Null); + + //Validate length property + Assert.Equal(3, vector.Length); + + // Validate CreateNull method + vector = SqlVector.CreateNull(5); + Assert.True(vector.IsNull); + Assert.Equal(5, vector.Length); + } } } From 6807ab4883de20ed51822526d8da8f42ca3ab40c Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Tue, 12 Aug 2025 23:20:49 +0530 Subject: [PATCH 2/7] Enable JSON tests against Azure SqlDb --- .../ManualTests/DataCommon/DataTestUtility.cs | 6 ++- ....Data.SqlClient.ManualTesting.Tests.csproj | 11 ++-- .../VectorTest/NativeVectorFloat32Tests.cs | 51 +++---------------- .../SQL/VectorTest/VectorAPIValidationTest.cs | 47 +++++++++++++++++ 4 files changed, 65 insertions(+), 50 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 511d16d069..b58e61f72c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -92,9 +92,11 @@ public static class DataTestUtility //SQL Server EngineEdition private static string s_sqlServerEngineEdition; + // Currently, only Azure SQL supports vectors and JSON. + // Our CI images with specific SQL Server versions lag + // behind with vector and JSON support. // JSON Column type - public static readonly bool IsJsonSupported = false; - + public static readonly bool IsJsonSupported = !IsNotAzureServer(); // VECTOR column type public static readonly bool IsVectorSupported = !IsNotAzureServer(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj index 7bd503c5b9..0da63efa61 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj @@ -185,6 +185,9 @@ + + + @@ -213,6 +216,9 @@ + + + @@ -294,11 +300,6 @@ - - - - - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index 1d01ea9e4d..50e12928fe 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -20,7 +20,7 @@ public static class VectorFloat32TestData public static float[] testData = new float[] { 1.1f, 2.2f, 3.3f }; public static int vectorColumnLength = testData.Length; // Incorrect size for SqlParameter.Size - public static int IncorrectParamSize = 3234; + public static int IncorrectParamSize = 3234; public static IEnumerable GetVectorFloat32TestData() { // Pattern 1-4 with SqlVector(values: testData) @@ -43,11 +43,11 @@ public static IEnumerable GetVectorFloat32TestData() // Pattern 1-4 with SqlVector.Null yield return new object[] { 1, SqlVector.Null, Array.Empty(), vectorColumnLength }; - + // Following scenario is not supported in SqlClient. // This can only be fixed with a behavior change that SqlParameter.Value is internally set to DBNull.Value if it is set to null. //yield return new object[] { 2, SqlVector.Null, Array.Empty(), vectorColumnLength }; - + yield return new object[] { 3, SqlVector.Null, Array.Empty(), vectorColumnLength }; yield return new object[] { 4, SqlVector.Null, Array.Empty(), vectorColumnLength }; } @@ -128,7 +128,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader.GetSqlValue(0), expectedData, expectedLength); if (!reader.IsDBNull(0)) - { + { ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader.GetValue(0), expectedData, expectedLength); ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader[0], expectedData, expectedLength); ValidateSqlVectorFloat32Object(reader.IsDBNull(0), (SqlVector)reader["VectorData"], expectedData, expectedLength); @@ -374,8 +374,8 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) DataTable table = null; switch (bulkCopySourceMode) { - - case 1: + + case 1: // Use SqlServer table as source var insertCmd = new SqlCommand($"insert into {s_bulkCopySrcTableName} values (@VectorData)", sourceConnection); var vectorParam = new SqlParameter(s_vectorParamName, new SqlVector(VectorFloat32TestData.testData)); @@ -400,8 +400,8 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) throw new ArgumentOutOfRangeException(nameof(bulkCopySourceMode), $"Unsupported bulk copy source mode: {bulkCopySourceMode}"); } - - + + //Bulkcopy from sql server table to destination table using SqlCommand sourceDataCommand = new SqlCommand($"SELECT Id, VectorData FROM {s_bulkCopySrcTableName}", sourceConnection); using SqlDataReader reader = sourceDataCommand.ExecuteReader(); @@ -586,40 +586,5 @@ public void TestInsertVectorsFloat32WithPrepare() } Assert.Equal(10, rowcnt); } - - - // We need this testcase to validate ref assembly for vector APIs - // Unit tests are covered under SqlVectorTest.cs - [Fact] - public void VectorAPITest() - { - // Validate that SqlVector is a valid type and has valid SqlDbType - Assert.True(typeof(SqlVector).IsValueType, "SqlVector should be a value type."); - Assert.Equal(36, (int)SqlDbTypeExtensions.Vector); - - // Validate ctor1 with float[] : public SqlVector(System.ReadOnlyMemory memory) { } - var vector = new SqlVector(VectorFloat32TestData.testData); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); - Assert.Equal(3, vector.Length); - - // Validate ctor2 with ReadOnlyMemory : public SqlVector(ReadOnlyMemory memory) { } - vector = new SqlVector(new ReadOnlyMemory(VectorFloat32TestData.testData)); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); - Assert.Equal(3, vector.Length); - - //Validate IsNull property - Assert.False(vector.IsNull, "IsNull should be false for non-null vector."); - - // Validate Null property returns null - Assert.Null(SqlVector.Null); - - //Validate length property - Assert.Equal(3, vector.Length); - - // Validate CreateNull method - vector = SqlVector.CreateNull(5); - Assert.True(vector.IsNull); - Assert.Equal(5, vector.Length); - } } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs new file mode 100644 index 0000000000..99cf59de6b --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using Microsoft.Data.SqlTypes; +using Xunit; + +namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.VectorTest +{ + public sealed class VectorAPIValidationTest + { + // We need this testcase to validate ref assembly for vector APIs + // Unit tests are covered under SqlVectorTest.cs + [Fact] + public void VectorAPITest() + { + // Validate that SqlVector is a valid type and has valid SqlDbType + Assert.True(typeof(SqlVector).IsValueType, "SqlVector should be a value type."); + Assert.Equal(36, (int)SqlDbTypeExtensions.Vector); + + // Validate ctor1 with float[] : public SqlVector(System.ReadOnlyMemory memory) { } + var vector = new SqlVector(VectorFloat32TestData.testData); + Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + Assert.Equal(3, vector.Length); + + // Validate ctor2 with ReadOnlyMemory : public SqlVector(ReadOnlyMemory memory) { } + vector = new SqlVector(new ReadOnlyMemory(VectorFloat32TestData.testData)); + Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + Assert.Equal(3, vector.Length); + + //Validate IsNull property + Assert.False(vector.IsNull, "IsNull should be false for non-null vector."); + + // Validate Null property returns null + Assert.Null(SqlVector.Null); + + //Validate length property + Assert.Equal(3, vector.Length); + + // Validate CreateNull method + vector = SqlVector.CreateNull(5); + Assert.True(vector.IsNull); + Assert.Equal(5, vector.Length); + } + } +} From dd5829a22b34d530bef56b12c57423e897728886 Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Thu, 28 Aug 2025 20:37:50 +0530 Subject: [PATCH 3/7] Test execution with AADConnStr --- .../tests/ManualTests/DataCommon/DataTestUtility.cs | 2 +- .../SQL/VectorTest/NativeVectorFloat32Tests.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 88ebc4a9bf..6a815b711d 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -98,7 +98,7 @@ public static class DataTestUtility // JSON Column type public static readonly bool IsJsonSupported = !IsNotAzureServer(); // VECTOR column type - public static readonly bool IsVectorSupported = !IsNotAzureServer(); + public static readonly bool IsVectorSupported = true; // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index 50e12928fe..2bdc7a9c1c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -147,7 +147,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, @@ -213,7 +213,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, @@ -304,7 +304,7 @@ public void TestStoredProcParamsForVectorFloat32( Assert.Throws(() => command.ExecuteNonQuery()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, @@ -361,7 +361,7 @@ public async Task TestStoredProcParamsForVectorFloat32Async( await Assert.ThrowsAsync(async () => await command.ExecuteNonQueryAsync()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] [InlineData(1)] [InlineData(2)] public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) @@ -460,7 +460,7 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, ((SqlVector)verifyReader.GetSqlVector(0)).Length); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] [InlineData(1)] [InlineData(2)] public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) @@ -560,7 +560,7 @@ public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, vector.Length); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] public void TestInsertVectorsFloat32WithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); From c266487f7a7b90f1615c63641d20b22ac903cf44 Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Thu, 28 Aug 2025 21:25:07 +0530 Subject: [PATCH 4/7] Enable test only for azure sqldb instance --- .../ManualTests/DataCommon/DataTestUtility.cs | 2 +- .../SQL/VectorTest/NativeVectorFloat32Tests.cs | 14 +++++++------- .../VectorTypeBackwardCompatibilityTests.cs | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 6a815b711d..6a7fc62c22 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -98,7 +98,7 @@ public static class DataTestUtility // JSON Column type public static readonly bool IsJsonSupported = !IsNotAzureServer(); // VECTOR column type - public static readonly bool IsVectorSupported = true; + public static readonly bool IsVectorSupported = Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index 2bdc7a9c1c..de94657885 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -147,7 +147,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, @@ -213,7 +213,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, @@ -247,7 +247,7 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( await ValidateInsertedDataAsync(conn, expectedValues, expectedLength); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestStoredProcParamsForVectorFloat32( int pattern, @@ -304,7 +304,7 @@ public void TestStoredProcParamsForVectorFloat32( Assert.Throws(() => command.ExecuteNonQuery()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, @@ -361,7 +361,7 @@ public async Task TestStoredProcParamsForVectorFloat32Async( await Assert.ThrowsAsync(async () => await command.ExecuteNonQueryAsync()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [InlineData(1)] [InlineData(2)] public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) @@ -460,7 +460,7 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, ((SqlVector)verifyReader.GetSqlVector(0)).Length); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] [InlineData(1)] [InlineData(2)] public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) @@ -560,7 +560,7 @@ public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, vector.Length); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.IsAccessTokenSetup), nameof(DataTestUtility.IsAADPasswordConnStrSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestInsertVectorsFloat32WithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs index 5fb9cf7625..ca2e00b940 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs @@ -81,7 +81,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestVectorDataInsertionAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -173,7 +173,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public async Task TestVectorParameterInitializationAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -245,7 +245,7 @@ public async Task TestVectorParameterInitializationAsync() await ValidateInsertedDataAsync(conn, null); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestVectorDataReadsAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -302,7 +302,7 @@ public void TestVectorDataReadsAsVarchar() Assert.Throws(() => reader.GetFieldValue(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public async Task TestVectorDataReadsAsVarcharAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -359,7 +359,7 @@ public async Task TestVectorDataReadsAsVarcharAsync() await Assert.ThrowsAsync(async () => await reader2.GetFieldValueAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestStoredProcParamsForVectorAsVarchar() { // Test data @@ -405,7 +405,7 @@ public void TestStoredProcParamsForVectorAsVarchar() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public async Task TestStoredProcParamsForVectorAsVarcharAsync() { // Test data @@ -456,7 +456,7 @@ public async Task TestStoredProcParamsForVectorAsVarcharAsync() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestSqlBulkCopyForVectorAsVarchar() { //Setup source with test data and create destination table for bulkcopy. @@ -521,7 +521,7 @@ public void TestSqlBulkCopyForVectorAsVarchar() Assert.True(verifyReader.IsDBNull(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public async Task TestSqlBulkCopyForVectorAsVarcharAsync() { //Setup source with test data and create destination table for bulkcopy. @@ -586,7 +586,7 @@ public async Task TestSqlBulkCopyForVectorAsVarcharAsync() Assert.True(await verifyReader.IsDBNullAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] public void TestInsertVectorsAsVarcharWithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); From 265f9c951b9e9d5ebd54453076ed38d5473f2196 Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Fri, 29 Aug 2025 09:59:03 +0530 Subject: [PATCH 5/7] Turn testflag into function --- .../ManualTests/DataCommon/DataTestUtility.cs | 9 ++++++--- .../SQL/VectorTest/NativeVectorFloat32Tests.cs | 14 +++++++------- .../VectorTypeBackwardCompatibilityTests.cs | 18 +++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 6a7fc62c22..fbc34a959e 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -97,9 +97,7 @@ public static class DataTestUtility // behind with vector and JSON support. // JSON Column type public static readonly bool IsJsonSupported = !IsNotAzureServer(); - // VECTOR column type - public static readonly bool IsVectorSupported = Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); - + // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname public static bool IsAzureSynapse @@ -458,6 +456,11 @@ public static bool IsNotAzureServer() return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); } + public static bool IsAzureServer() + { + return AreConnStringsSetup() && Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource); + } + public static bool IsNotNamedInstance() { return !AreConnStringsSetup() || !new SqlConnectionStringBuilder(TCPConnectionString).DataSource.Contains(@"\"); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs index de94657885..119190f8c5 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/NativeVectorFloat32Tests.cs @@ -147,7 +147,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestSqlVectorFloat32ParameterInsertionAndReads( int pattern, @@ -213,7 +213,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( int pattern, @@ -247,7 +247,7 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync( await ValidateInsertedDataAsync(conn, expectedValues, expectedLength); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public void TestStoredProcParamsForVectorFloat32( int pattern, @@ -304,7 +304,7 @@ public void TestStoredProcParamsForVectorFloat32( Assert.Throws(() => command.ExecuteNonQuery()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData(nameof(VectorFloat32TestData.GetVectorFloat32TestData), MemberType = typeof(VectorFloat32TestData), DisableDiscoveryEnumeration = true)] public async Task TestStoredProcParamsForVectorFloat32Async( int pattern, @@ -361,7 +361,7 @@ public async Task TestStoredProcParamsForVectorFloat32Async( await Assert.ThrowsAsync(async () => await command.ExecuteNonQueryAsync()); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [InlineData(1)] [InlineData(2)] public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) @@ -460,7 +460,7 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, ((SqlVector)verifyReader.GetSqlVector(0)).Length); } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [InlineData(1)] [InlineData(2)] public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) @@ -560,7 +560,7 @@ public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode) Assert.Equal(VectorFloat32TestData.testData.Length, vector.Length); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestInsertVectorsFloat32WithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs index ca2e00b940..402a2777f8 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorTypeBackwardCompatibilityTests.cs @@ -81,7 +81,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestVectorDataInsertionAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -173,7 +173,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestVectorParameterInitializationAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -245,7 +245,7 @@ public async Task TestVectorParameterInitializationAsync() await ValidateInsertedDataAsync(conn, null); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestVectorDataReadsAsVarchar() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -302,7 +302,7 @@ public void TestVectorDataReadsAsVarchar() Assert.Throws(() => reader.GetFieldValue(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestVectorDataReadsAsVarcharAsync() { float[] data = { 1.1f, 2.2f, 3.3f }; @@ -359,7 +359,7 @@ public async Task TestVectorDataReadsAsVarcharAsync() await Assert.ThrowsAsync(async () => await reader2.GetFieldValueAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestStoredProcParamsForVectorAsVarchar() { // Test data @@ -405,7 +405,7 @@ public void TestStoredProcParamsForVectorAsVarchar() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestStoredProcParamsForVectorAsVarcharAsync() { // Test data @@ -456,7 +456,7 @@ public async Task TestStoredProcParamsForVectorAsVarcharAsync() Assert.True(outputParam.Value == DBNull.Value); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestSqlBulkCopyForVectorAsVarchar() { //Setup source with test data and create destination table for bulkcopy. @@ -521,7 +521,7 @@ public void TestSqlBulkCopyForVectorAsVarchar() Assert.True(verifyReader.IsDBNull(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestSqlBulkCopyForVectorAsVarcharAsync() { //Setup source with test data and create destination table for bulkcopy. @@ -586,7 +586,7 @@ public async Task TestSqlBulkCopyForVectorAsVarcharAsync() Assert.True(await verifyReader.IsDBNullAsync(0)); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsVectorSupported), nameof(DataTestUtility.AreConnStringsSetup))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestInsertVectorsAsVarcharWithPrepare() { SqlConnection conn = new SqlConnection(s_connectionString); From 5f5b7db8881ad5339f34ccb52005c66980cda1ca Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Fri, 29 Aug 2025 16:24:13 +0530 Subject: [PATCH 6/7] Enable JSON tests and split vector API test into multiple testcases --- .../ManualTests/DataCommon/DataTestUtility.cs | 7 -- .../SQL/JsonTest/JsonBulkCopyTest.cs | 30 ++++----- .../SQL/JsonTest/JsonStreamTest.cs | 12 ++-- .../ManualTests/SQL/JsonTest/JsonTest.cs | 16 ++--- .../SQL/VectorTest/VectorAPIValidationTest.cs | 67 ++++++++++++++++--- 5 files changed, 85 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index fbc34a959e..9cf3d3a6a0 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -92,12 +92,6 @@ public static class DataTestUtility //SQL Server EngineEdition private static string s_sqlServerEngineEdition; - // Currently, only Azure SQL supports vectors and JSON. - // Our CI images with specific SQL Server versions lag - // behind with vector and JSON support. - // JSON Column type - public static readonly bool IsJsonSupported = !IsNotAzureServer(); - // Azure Synapse EngineEditionId == 6 // More could be read at https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql?view=sql-server-ver16#propertyname public static bool IsAzureSynapse @@ -179,7 +173,6 @@ static DataTestUtility() ManagedIdentitySupported = c.ManagedIdentitySupported; IsManagedInstance = c.IsManagedInstance; AliasName = c.AliasName; - IsJsonSupported = c.IsJsonSupported; #if NETFRAMEWORK System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs index c92ba237b4..45a2c59a35 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs @@ -14,11 +14,11 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.JsonTest public class JsonBulkCopyTest { private readonly ITestOutputHelper _output; - private static readonly string _generatedJsonFile = DataTestUtility.GenerateRandomCharacters("randomRecords"); - private static readonly string _outputFile = DataTestUtility.GenerateRandomCharacters("serverResults"); - private static readonly string _sourceTableName = DataTestUtility.GenerateObjectName(); - private static readonly string _destinationTableName = DataTestUtility.GenerateObjectName(); - + private static readonly string _generatedJsonFile = DataTestUtility.GetUniqueName("randomRecords"); + private static readonly string _outputFile = DataTestUtility.GetUniqueName("serverResults"); + private static readonly string _sourceTableName = DataTestUtility.GetUniqueName("jsonBulkCopySrcTable", true); + private static readonly string _destinationTableName = DataTestUtility.GetUniqueName("jsonBulkCopyDestTable", true); + public JsonBulkCopyTest(ITestOutputHelper output) { _output = output; @@ -26,10 +26,10 @@ public JsonBulkCopyTest(ITestOutputHelper output) public static IEnumerable JsonBulkCopyTestData() { - yield return new object[] { CommandBehavior.Default, false, 300, 100 }; - yield return new object[] { CommandBehavior.Default, true, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, false, 300, 100 }; - yield return new object[] { CommandBehavior.SequentialAccess, true, 300, 100 }; + yield return new object[] { CommandBehavior.Default, false, 30, 10 }; + yield return new object[] { CommandBehavior.Default, true, 30, 10 }; + yield return new object[] { CommandBehavior.SequentialAccess, false, 30, 10 }; + yield return new object[] { CommandBehavior.SequentialAccess, true, 30, 10 }; } private void PopulateData(int noOfRecords, int rows) @@ -87,7 +87,7 @@ private void PrintJsonDataToFileAndCompare(SqlConnection connection) try { DeleteFile(_outputFile); - using (SqlCommand command = new SqlCommand("SELECT [data] FROM [" + _destinationTableName + "]", connection)) + using (SqlCommand command = new SqlCommand("SELECT [data] FROM " + _destinationTableName, connection)) { using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) { @@ -125,7 +125,7 @@ private async Task PrintJsonDataToFileAndCompareAsync(SqlConnection connection) try { DeleteFile(_outputFile); - using (SqlCommand command = new SqlCommand("SELECT [data] FROM [" + _destinationTableName + "]", connection)) + using (SqlCommand command = new SqlCommand("SELECT [data] FROM " + _destinationTableName, connection)) { using (SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess)) { @@ -159,7 +159,7 @@ private async Task PrintJsonDataToFileAndCompareAsync(SqlConnection connection) private void StreamJsonFileToServer(SqlConnection connection) { - using (SqlCommand cmd = new SqlCommand("INSERT INTO [" + _sourceTableName + "] (data) VALUES (@jsondata)", connection)) + using (SqlCommand cmd = new SqlCommand("INSERT INTO " + _sourceTableName + " (data) VALUES (@jsondata)", connection)) { using (StreamReader jsonFile = File.OpenText(_generatedJsonFile)) { @@ -171,7 +171,7 @@ private void StreamJsonFileToServer(SqlConnection connection) private async Task StreamJsonFileToServerAsync(SqlConnection connection) { - using (SqlCommand cmd = new SqlCommand("INSERT INTO [" + _sourceTableName + "] (data) VALUES (@jsondata)", connection)) + using (SqlCommand cmd = new SqlCommand("INSERT INTO " + _sourceTableName + " (data) VALUES (@jsondata)", connection)) { using (StreamReader jsonFile = File.OpenText(_generatedJsonFile)) { @@ -265,7 +265,7 @@ private async Task BulkCopyDataAsync(CommandBehavior cb, bool enableStraming, in } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData( nameof(JsonBulkCopyTestData) #if NETFRAMEWORK @@ -289,7 +289,7 @@ public void TestJsonBulkCopy(CommandBehavior cb, bool enableStraming, int jsonAr } } - [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] [MemberData( nameof(JsonBulkCopyTestData) #if NETFRAMEWORK diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs index a82fee1665..efcef3e674 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonStreamTest.cs @@ -22,8 +22,8 @@ public class JsonRecord public class JsonStreamTest { private readonly ITestOutputHelper _output; - private static readonly string _jsonFile = "randomRecords.json"; - private static readonly string _outputFile = "serverRecords.json"; + private static readonly string _jsonFile = DataTestUtility.GetUniqueName("randomRecords") + ".json"; + private static readonly string _outputFile = DataTestUtility.GetUniqueName("serverRecords") + ".json"; public JsonStreamTest(ITestOutputHelper output) { @@ -157,10 +157,10 @@ private void DeleteFile(string filename) } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonStreaming() { - GenerateJsonFile(10000, _jsonFile); + GenerateJsonFile(1000, _jsonFile); using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) { connection.Open(); @@ -173,10 +173,10 @@ public void TestJsonStreaming() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonStreamingAsync() { - GenerateJsonFile(10000, _jsonFile); + GenerateJsonFile(1000, _jsonFile); using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString)) { await connection.OpenAsync(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs index ccf0c00919..9b3c37da4f 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonTest.cs @@ -73,7 +73,7 @@ private void ValidateNullJson(SqlDataReader reader) } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonWrite() { string tableName = DataTestUtility.GenerateObjectName(); @@ -137,7 +137,7 @@ public void TestJsonWrite() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonWriteAsync() { string tableName = DataTestUtility.GenerateObjectName(); @@ -201,7 +201,7 @@ public async Task TestJsonWriteAsync() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonRead() { string tableName = DataTestUtility.GenerateObjectName(); @@ -260,7 +260,7 @@ public void TestJsonRead() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public async Task TestJsonReadAsync() { string tableName = DataTestUtility.GenerateObjectName(); @@ -319,7 +319,7 @@ public async Task TestJsonReadAsync() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestNullJson() { string tableName = DataTestUtility.GenerateObjectName(); @@ -350,7 +350,7 @@ public void TestNullJson() DataTestUtility.DropTable(connection, tableName); } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonAPIs() { string tableName = DataTestUtility.GenerateObjectName(); @@ -398,7 +398,7 @@ public void TestJsonAPIs() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonWithMARS() { string table1Name = DataTestUtility.GenerateObjectName(); @@ -454,7 +454,7 @@ public void TestJsonWithMARS() } } - [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsJsonSupported))] + [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsAzureServer))] public void TestJsonSPParams() { string tableName = DataTestUtility.GenerateObjectName(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs index 99cf59de6b..a805cb4dc9 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/VectorTest/VectorAPIValidationTest.cs @@ -10,38 +10,83 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.VectorTest { public sealed class VectorAPIValidationTest { - // We need this testcase to validate ref assembly for vector APIs + // We need these testcases to validate ref assembly for vector APIs // Unit tests are covered under SqlVectorTest.cs [Fact] - public void VectorAPITest() + public void ValidateVectorSqlDbType() { // Validate that SqlVector is a valid type and has valid SqlDbType Assert.True(typeof(SqlVector).IsValueType, "SqlVector should be a value type."); Assert.Equal(36, (int)SqlDbTypeExtensions.Vector); + } + [Fact] + public void TestSqlVectorCreationAPIWithFloatArr() + { // Validate ctor1 with float[] : public SqlVector(System.ReadOnlyMemory memory) { } - var vector = new SqlVector(VectorFloat32TestData.testData); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); + Assert.Equal(testData, vector.Memory.ToArray()); Assert.Equal(3, vector.Length); + } + [Fact] + public void TestSqlVectorCreationAPIWithROM() + { // Validate ctor2 with ReadOnlyMemory : public SqlVector(ReadOnlyMemory memory) { } - vector = new SqlVector(new ReadOnlyMemory(VectorFloat32TestData.testData)); - Assert.Equal(VectorFloat32TestData.testData, vector.Memory.ToArray()); + var testData = new ReadOnlyMemory(new float[] { 1.1f, 2.2f, 3.3f }); + var vector = new SqlVector(testData); + Assert.Equal(testData.ToArray(), vector.Memory.ToArray()); Assert.Equal(3, vector.Length); + } + [Fact] + public void TestSqlVectorCreationAPICreateNull() + { + // Validate CreateNull method + var vector = SqlVector.CreateNull(5); + Assert.True(vector.IsNull); + Assert.Equal(5, vector.Length); + } + + [Fact] + public void TestIsNullProperty() + { //Validate IsNull property + var testData = new ReadOnlyMemory(new float[] { 1.1f, 2.2f, 3.3f }); + var vector = new SqlVector(testData); Assert.False(vector.IsNull, "IsNull should be false for non-null vector."); + vector = SqlVector.CreateNull(3); + Assert.True(vector.IsNull, "IsNull should be true for null vector."); + } + [Fact] + public void TestNullProperty() + { // Validate Null property returns null Assert.Null(SqlVector.Null); + } - //Validate length property + [Fact] + public void TestLengthProperty() + { + // Validate Length property is correctly populated for null and non-null vectors + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); Assert.Equal(3, vector.Length); + vector = SqlVector.CreateNull(3); + Assert.Equal(3, vector.Length); + } - // Validate CreateNull method - vector = SqlVector.CreateNull(5); - Assert.True(vector.IsNull); - Assert.Equal(5, vector.Length); + [Fact] + public void TestMemoryProperty() + { + // Validate Memory property is correctly populated for non-null and null vectors + var testData = new float[] { 1.1f, 2.2f, 3.3f }; + var vector = new SqlVector(testData); + Assert.Equal(testData, vector.Memory.ToArray()); + vector = SqlVector.CreateNull(3); + Assert.True( vector.Memory.IsEmpty, "Null vector of given size point to empty ROM"); } } } From 6dbb4dbc9b8af932a1b331523c03e49ddb7e9526 Mon Sep 17 00:00:00 2001 From: Apoorv Deshmukh Date: Fri, 29 Aug 2025 22:22:35 +0530 Subject: [PATCH 7/7] Remove IsJsonSupported flag from config files --- .../tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs | 2 +- .../Microsoft.Data.SqlClient.TestUtilities/config.default.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs index 1b712ceaf5..bf47188b34 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs @@ -42,7 +42,7 @@ public class Config public string KerberosDomainUser = null; public bool IsManagedInstance = false; public string AliasName = null; - public bool IsJsonSupported = false; + public static Config Load(string configPath = @"config.json") { try diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json index a5f6cd996e..5ef2e9c99e 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json @@ -35,6 +35,5 @@ "ManagedIdentitySupported": true, "UserManagedIdentityClientId": "", "PowerShellPath": "", - "AliasName": "", - "IsJsonSupported": false + "AliasName": "" }