Skip to content

Commit 27fd1f6

Browse files
Support vector datatype with SqlVector<T> (#3443)
* Support vector datatype with SqlVector<T> * Update xml documentation for APIs and address review comments * Remove ToArray() and change ToString() to internal GetString()
1 parent fc950e8 commit 27fd1f6

24 files changed

+722
-522
lines changed

doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ No conversions are performed; therefore. the data retrieved must already be a ch
415415
<item><description>SqlMoney</description></item>
416416
<item><description>SqlSingle</description></item>
417417
<item><description>SqlString</description></item>
418-
<item><description>SqlVectorFloat32</description></item>
418+
<item><description>SqlVector</description></item>
419419
<item><description>Stream</description></item>
420420
<item><description>String</description></item>
421421
<item><description>TextReader</description></item>
@@ -490,7 +490,7 @@ No conversions are performed; therefore. the data retrieved must already be a ch
490490
<item><description>SqlMoney</description></item>
491491
<item><description>SqlSingle</description></item>
492492
<item><description>SqlString</description></item>
493-
<item><description>SqlVectorFloat32</description></item>
493+
<item><description>SqlVector</description></item>
494494
<item><description>Stream</description></item>
495495
<item><description>String</description></item>
496496
<item><description>TextReader</description></item>
@@ -964,13 +964,13 @@ The <xref:Microsoft.Data.SqlClient.SqlDataReader.GetSchemaTable%2A> method retur
964964
No conversions are performed; therefore, the data retrieved must already be a JSON string, or an exception is generated.
965965
</remarks>
966966
</GetSqlJson>
967-
<GetSqlVectorFloat32>
967+
<GetSqlVector>
968968
<param name="i"></param>
969969
<summary>
970-
Gets the value of the specified column as a <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32"/>.
970+
Gets the value of the specified column as a <see cref="T:Microsoft.Data.SqlTypes.SqlVector"/>.
971971
</summary>
972972
<returns>
973-
A <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32"/> object representing the column at the given ordinal.
973+
A <see cref="T:Microsoft.Data.SqlTypes.SqlVector"/> object representing the column at the given ordinal.
974974
</returns>
975975
<exception cref="T:System.ArgumentOutOfRangeException">
976976
The index passed was outside the range of 0 to <see cref="P:System.Data.DataTableReader.FieldCount" /> - 1
@@ -979,12 +979,12 @@ The <xref:Microsoft.Data.SqlClient.SqlDataReader.GetSchemaTable%2A> method retur
979979
An attempt was made to read or access columns in a closed <see cref="T:Microsoft.Data.SqlClient.SqlDataReader" />.
980980
</exception>
981981
<exception cref="T:System.InvalidCastException">
982-
The retrieved data is not compatible with the <see cref="T:Microsoft.Data.SqlTypes.SqlVectorFloat32" /> type.
982+
The retrieved data is not compatible with the <see cref="T:Microsoft.Data.SqlTypes.SqlVector" /> type.
983983
</exception>
984984
<remarks>
985985
No conversions are performed; therefore, the data retrieved must already be a vector value, or an exception is generated.
986986
</remarks>
987-
</GetSqlVectorFloat32>
987+
</GetSqlVector>
988988
<GetSqlMoney>
989989
<param name="i">
990990
The zero-based column ordinal.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<docs>
3+
<members name="SqlVector">
4+
<SqlVector>
5+
<summary>Represents a vector value in SQL Server.</summary>
6+
</SqlVector>
7+
<ctor1>
8+
<param name="length"></param>
9+
<summary>
10+
Constructs a null vector of the given length. SQL Server requires vector arguments to specify their length even when null.
11+
</summary>
12+
<exception cref="T:System.ArgumentOutOfRangeException">
13+
Vector length must be non-negative.
14+
</exception>
15+
</ctor1>
16+
<ctor2>
17+
<param name="memory"></param>
18+
<summary>
19+
Constructs a vector with the given values.
20+
</summary>
21+
</ctor2>
22+
<IsNull>
23+
<inheritdoc/>
24+
</IsNull>
25+
<Null>
26+
<summary>
27+
Represents a null instance without any attributes.
28+
</summary>
29+
<remarks>
30+
This property is provided for compatibility with DataTable.
31+
In most cases, prefer using <c>IsNull</c> to check if a SqlVector instance is a null vector.
32+
This is equivalent to <c>null</c> value.
33+
</remarks>
34+
</Null>
35+
<Length>
36+
<summary>
37+
Returns the number of elements in the vector.
38+
</summary>
39+
</Length>
40+
<Size>
41+
<summary>
42+
Returns the number of bytes required to represent this vector when communicating with SQL Server.
43+
</summary>
44+
</Size>
45+
<Memory>
46+
<summary>Returns the vector values as a memory region. No copies are made.</summary>
47+
</Memory>
48+
</members>
49+
</docs>

doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/Microsoft.Data.SqlClient.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Data.SqlTypes", "
172172
ProjectSection(SolutionItems) = preProject
173173
..\doc\snippets\Microsoft.Data.SqlTypes\SqlFileStream.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlFileStream.xml
174174
..\doc\snippets\Microsoft.Data.SqlTypes\SqlJson.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlJson.xml
175-
..\doc\snippets\Microsoft.Data.SqlTypes\SqlVectorFloat32.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlVectorFloat32.xml
175+
..\doc\snippets\Microsoft.Data.SqlTypes\SqlVector.xml = ..\doc\snippets\Microsoft.Data.SqlTypes\SqlVector.xml
176176
EndProjectSection
177177
EndProject
178178
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.TestUtilities", "Microsoft.Data.SqlClient\tests\tools\Microsoft.Data.SqlClient.TestUtilities\Microsoft.Data.SqlClient.TestUtilities.csproj", "{89D6D382-9B36-43C9-A912-03802FDA8E36}"

src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,24 @@ public SqlJson(System.Text.Json.JsonDocument jsonDoc) { }
122122
public override string ToString() { throw null; }
123123
}
124124

125-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/SqlVectorFloat32/*' />
126-
public sealed class SqlVectorFloat32 : System.Data.SqlTypes.INullable
127-
{
128-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor1/*' />
129-
public SqlVectorFloat32(int length) { }
130-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor2/*' />
131-
public SqlVectorFloat32(System.ReadOnlyMemory<float> values) { }
132-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/IsNull/*' />
125+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/SqlVector/*' />
126+
public sealed class SqlVector<T> : System.Data.SqlTypes.INullable
127+
where T : unmanaged
128+
{
129+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor1/*' />
130+
public SqlVector(int length) { }
131+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor2/*' />
132+
public SqlVector(System.ReadOnlyMemory<T> memory) { }
133+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/IsNull/*' />
133134
public bool IsNull => throw null;
134-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Null/*' />
135-
public static SqlVectorFloat32 Null => throw null;
136-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Length/*' />
135+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Null/*' />
136+
public static SqlVector<T> Null => throw null;
137+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Length/*' />
137138
public int Length { get { throw null; } }
138-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Size/*' />
139+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Size/*' />
139140
public int Size { get { throw null; } }
140-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Values/*' />
141-
public System.ReadOnlyMemory<float> Values { get { throw null; } }
142-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToString/*' />
143-
public override string ToString() { throw null; }
144-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToArray/*' />
145-
public float[] ToArray() { throw null; }
141+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Memory/*' />
142+
public System.ReadOnlyMemory<T> Memory { get { throw null; } }
146143
}
147144
}
148145
namespace Microsoft.Data.SqlClient
@@ -1395,8 +1392,8 @@ public override void Close() { }
13951392
public virtual object GetSqlValue(int i) { throw null; }
13961393
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlValues/*'/>
13971394
public virtual int GetSqlValues(object[] values) { throw null; }
1398-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVectorFloat32/*'/>
1399-
public virtual Microsoft.Data.SqlTypes.SqlVectorFloat32 GetSqlVectorFloat32(int i) { throw null; }
1395+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVector/*'/>
1396+
public virtual Microsoft.Data.SqlTypes.SqlVector<T> GetSqlVector<T>(int i) where T : unmanaged { throw null; }
14001397
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlXml/*'/>
14011398
public virtual System.Data.SqlTypes.SqlXml GetSqlXml(int i) { throw null; }
14021399
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSchemaTable/*'/>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,8 @@
795795
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlJson.cs">
796796
<Link>Microsoft\Data\SqlTypes\SqlJson.cs</Link>
797797
</Compile>
798-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVectorFloat32.cs">
799-
<Link>Microsoft\Data\SqlTypes\SqlVectorFloat32.cs</Link>
798+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
799+
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
800800
</Compile>
801801
<Compile Include="$(CommonSourceRoot)Resources\ResCategoryAttribute.cs">
802802
<Link>Resources\ResCategoryAttribute.cs</Link>

src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,8 @@ public override void Close() { }
13701370
public virtual object GetSqlValue(int i) { throw null; }
13711371
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlValues/*'/>
13721372
public virtual int GetSqlValues(object[] values) { throw null; }
1373-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVectorFloat32/*'/>
1374-
public virtual Microsoft.Data.SqlTypes.SqlVectorFloat32 GetSqlVectorFloat32(int i) { throw null; }
1373+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlVector/*'/>
1374+
public virtual Microsoft.Data.SqlTypes.SqlVector<T> GetSqlVector<T>(int i) where T : unmanaged { throw null; }
13751375
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSqlXml/*'/>
13761376
public virtual System.Data.SqlTypes.SqlXml GetSqlXml(int i) { throw null; }
13771377
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetSchemaTable/*'/>
@@ -2416,26 +2416,23 @@ public SqlJson(System.Text.Json.JsonDocument jsonDoc) { }
24162416
public override string ToString() { throw null; }
24172417
}
24182418

2419-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/SqlVectorFloat32/*' />
2420-
public sealed class SqlVectorFloat32 : System.Data.SqlTypes.INullable
2421-
{
2422-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor1/*' />
2423-
public SqlVectorFloat32(int length) { }
2424-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ctor2/*' />
2425-
public SqlVectorFloat32(System.ReadOnlyMemory<float> values) { }
2426-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/IsNull/*' />
2419+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/SqlVector/*' />
2420+
public sealed class SqlVector<T> : System.Data.SqlTypes.INullable
2421+
where T : unmanaged
2422+
{
2423+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor1/*' />
2424+
public SqlVector(int length) { }
2425+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/ctor2/*' />
2426+
public SqlVector(System.ReadOnlyMemory<T> memory) { }
2427+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/IsNull/*' />
24272428
public bool IsNull => throw null;
2428-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Null/*' />
2429-
public static SqlVectorFloat32 Null => throw null;
2430-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Length/*' />
2429+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Null/*' />
2430+
public static SqlVector<T> Null => throw null;
2431+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Length/*' />
24312432
public int Length { get { throw null; } }
2432-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Size/*' />
2433+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Size/*' />
24332434
public int Size { get { throw null; } }
2434-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/Values/*' />
2435-
public System.ReadOnlyMemory<float> Values { get { throw null; } }
2436-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToString/*' />
2437-
public override string ToString() { throw null; }
2438-
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVectorFloat32.xml' path='docs/members[@name="SqlVectorFloat32"]/ToArray/*' />
2439-
public float[] ToArray() { throw null; }
2435+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlVector.xml' path='docs/members[@name="SqlVector"]/Memory/*' />
2436+
public System.ReadOnlyMemory<T> Memory { get { throw null; } }
24402437
}
24412438
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@
585585
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SqlSer.cs">
586586
<Link>Microsoft\Data\SqlClient\Server\SqlSer.cs</Link>
587587
</Compile>
588-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\IsqlVector.cs">
588+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ISqlVector.cs">
589589
<Link>Microsoft\Data\SqlClient\ISqlVector.cs</Link>
590590
</Compile>
591591
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SessionHandle.Windows.cs">
@@ -909,8 +909,8 @@
909909
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlJson.cs">
910910
<Link>Microsoft\Data\SqlTypes\SqlJson.cs</Link>
911911
</Compile>
912-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVectorFloat32.cs">
913-
<Link>Microsoft\Data\SqlTypes\SqlVectorFloat32.cs</Link>
912+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlVector.cs">
913+
<Link>Microsoft\Data\SqlTypes\SqlVector.cs</Link>
914914
</Compile>
915915
<Compile Include="$(CommonSourceRoot)Resources\ResDescriptionAttribute.cs">
916916
<Link>Resources\ResDescriptionAttribute.cs</Link>
@@ -921,7 +921,10 @@
921921
<Compile Include="$(CommonSourceRoot)System\IO\StreamExtensions.netfx.cs">
922922
<Link>System\IO\StreamExtensions.netfx.cs</Link>
923923
</Compile>
924-
924+
<Compile Include="$(CommonSourceRoot)System\Runtime\CompilerServices\IsExternalInit.netfx.cs">
925+
<Link>System\Runtime\CompilerServices\IsExternalInit.netfx.cs</Link>
926+
</Compile>
927+
925928
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
926929
<Compile Include="Microsoft\Data\SqlClient\SqlConnection.cs" />
927930
<Compile Include="Microsoft\Data\SqlClient\SqlConnectionHelper.cs" />

0 commit comments

Comments
 (0)