@@ -17,7 +17,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SQL.VectorTest
1717 public static class VectorFloat32TestData
1818 {
1919 public const int VectorHeaderSize = 8 ;
20- public static float [ ] testData = new float [ ] { 1.1f , 2.2f , 3.3f } ;
20+ public static float [ ] testData = new float [ ] { 1.1f , 2.2f , 3.3f , 1.01f , float . MinValue , - 0.0f } ;
2121 public static int vectorColumnLength = testData . Length ;
2222 // Incorrect size for SqlParameter.Size
2323 public static int IncorrectParamSize = 3234 ;
@@ -59,16 +59,17 @@ public sealed class NativeVectorFloat32Tests : IDisposable
5959 private static readonly string s_connectionString = ManualTesting . Tests . DataTestUtility . TCPConnectionString ;
6060 private static readonly string s_tableName = DataTestUtility . GetShortName ( "VectorTestTable" ) ;
6161 private static readonly string s_bulkCopySrcTableName = DataTestUtility . GetShortName ( "VectorBulkCopyTestTable" ) ;
62- private static readonly string s_bulkCopySrcTableDef = $@ "(Id INT PRIMARY KEY IDENTITY, VectorData vector(3) NULL)";
63- private static readonly string s_tableDefinition = $@ "(Id INT PRIMARY KEY IDENTITY, VectorData vector(3) NULL)";
62+ private static readonly int s_vectorDimensions = VectorFloat32TestData . vectorColumnLength ;
63+ private static readonly string s_bulkCopySrcTableDef = $@ "(Id INT PRIMARY KEY IDENTITY, VectorData vector({ s_vectorDimensions } ) NULL)";
64+ private static readonly string s_tableDefinition = $@ "(Id INT PRIMARY KEY IDENTITY, VectorData vector({ s_vectorDimensions } ) NULL)";
6465 private static readonly string s_selectCmdString = $ "SELECT VectorData FROM { s_tableName } ORDER BY Id DESC";
6566 private static readonly string s_insertCmdString = $ "INSERT INTO { s_tableName } (VectorData) VALUES (@VectorData)";
6667 private static readonly string s_vectorParamName = $ "@VectorData";
6768 private static readonly string s_outputVectorParamName = $ "@OutputVectorData";
6869 private static readonly string s_storedProcName = DataTestUtility . GetShortName ( "VectorsAsVarcharSp" ) ;
6970 private static readonly string s_storedProcBody = $@ "
70- { s_vectorParamName } vector(3 ), -- Input: Serialized float[] as JSON string
71- { s_outputVectorParamName } vector(3 ) OUTPUT -- Output: Echoed back from latest inserted row
71+ { s_vectorParamName } vector({ s_vectorDimensions } ), -- Input: Serialized float[] as JSON string
72+ { s_outputVectorParamName } vector({ s_vectorDimensions } ) OUTPUT -- Output: Echoed back from latest inserted row
7273 AS
7374 BEGIN
7475 SET NOCOUNT ON;
@@ -147,7 +148,7 @@ private void ValidateInsertedData(SqlConnection connection, float[] expectedData
147148 }
148149 }
149150
150- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
151+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
151152 [ MemberData ( nameof ( VectorFloat32TestData . GetVectorFloat32TestData ) , MemberType = typeof ( VectorFloat32TestData ) , DisableDiscoveryEnumeration = true ) ]
152153 public void TestSqlVectorFloat32ParameterInsertionAndReads (
153154 int pattern ,
@@ -213,7 +214,7 @@ private async Task ValidateInsertedDataAsync(SqlConnection connection, float[] e
213214 }
214215 }
215216
216- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
217+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
217218 [ MemberData ( nameof ( VectorFloat32TestData . GetVectorFloat32TestData ) , MemberType = typeof ( VectorFloat32TestData ) , DisableDiscoveryEnumeration = true ) ]
218219 public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync (
219220 int pattern ,
@@ -247,7 +248,7 @@ public async Task TestSqlVectorFloat32ParameterInsertionAndReadsAsync(
247248 await ValidateInsertedDataAsync ( conn , expectedValues , expectedLength ) ;
248249 }
249250
250- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
251+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
251252 [ MemberData ( nameof ( VectorFloat32TestData . GetVectorFloat32TestData ) , MemberType = typeof ( VectorFloat32TestData ) , DisableDiscoveryEnumeration = true ) ]
252253 public void TestStoredProcParamsForVectorFloat32 (
253254 int pattern ,
@@ -304,7 +305,7 @@ public void TestStoredProcParamsForVectorFloat32(
304305 Assert . Throws < InvalidOperationException > ( ( ) => command . ExecuteNonQuery ( ) ) ;
305306 }
306307
307- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
308+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
308309 [ MemberData ( nameof ( VectorFloat32TestData . GetVectorFloat32TestData ) , MemberType = typeof ( VectorFloat32TestData ) , DisableDiscoveryEnumeration = true ) ]
309310 public async Task TestStoredProcParamsForVectorFloat32Async (
310311 int pattern ,
@@ -361,7 +362,7 @@ public async Task TestStoredProcParamsForVectorFloat32Async(
361362 await Assert . ThrowsAsync < InvalidOperationException > ( async ( ) => await command . ExecuteNonQueryAsync ( ) ) ;
362363 }
363364
364- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
365+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
365366 [ InlineData ( 1 ) ]
366367 [ InlineData ( 2 ) ]
367368 public void TestBulkCopyFromSqlTable ( int bulkCopySourceMode )
@@ -460,7 +461,7 @@ public void TestBulkCopyFromSqlTable(int bulkCopySourceMode)
460461 Assert . Equal ( VectorFloat32TestData . testData . Length , ( ( SqlVector < float > ) verifyReader . GetSqlVector < float > ( 0 ) ) . Length ) ;
461462 }
462463
463- [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
464+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
464465 [ InlineData ( 1 ) ]
465466 [ InlineData ( 2 ) ]
466467 public async Task TestBulkCopyFromSqlTableAsync ( int bulkCopySourceMode )
@@ -560,7 +561,7 @@ public async Task TestBulkCopyFromSqlTableAsync(int bulkCopySourceMode)
560561 Assert . Equal ( VectorFloat32TestData . testData . Length , vector . Length ) ;
561562 }
562563
563- [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsAzureServer ) , nameof ( DataTestUtility . IsNotManagedInstance ) ) ]
564+ [ ConditionalFact ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsSqlVectorSupported ) ) ]
564565 public void TestInsertVectorsFloat32WithPrepare ( )
565566 {
566567 SqlConnection conn = new SqlConnection ( s_connectionString ) ;
@@ -571,15 +572,15 @@ public void TestInsertVectorsFloat32WithPrepare()
571572 command . Prepare ( ) ;
572573 for ( int i = 0 ; i < 10 ; i ++ )
573574 {
574- vectorParam . Value = new SqlVector < float > ( new float [ ] { i + 0.1f , i + 0.2f , i + 0.3f } ) ;
575+ vectorParam . Value = new SqlVector < float > ( new float [ ] { i + 0.1f , i + 0.2f , i + 0.3f , i + 0.4f , i + 0.5f , i + 0.6f } ) ;
575576 command . ExecuteNonQuery ( ) ;
576577 }
577578 SqlCommand validateCommand = new SqlCommand ( $ "SELECT VectorData FROM { s_tableName } ", conn ) ;
578579 using SqlDataReader reader = validateCommand . ExecuteReader ( ) ;
579580 int rowcnt = 0 ;
580581 while ( reader . Read ( ) )
581582 {
582- float [ ] expectedData = new float [ ] { rowcnt + 0.1f , rowcnt + 0.2f , rowcnt + 0.3f } ;
583+ float [ ] expectedData = new float [ ] { rowcnt + 0.1f , rowcnt + 0.2f , rowcnt + 0.3f , rowcnt + 0.4f , rowcnt + 0.5f , rowcnt + 0.6f } ;
583584 float [ ] dbData = reader . GetSqlVector < float > ( 0 ) . Memory . ToArray ( ) ;
584585 Assert . Equal ( expectedData , dbData ) ;
585586 rowcnt ++ ;
0 commit comments