Skip to content

Commit 5779d28

Browse files
committed
Update negotiation logic
1 parent 61c6f75 commit 5779d28

File tree

7 files changed

+69
-45
lines changed

7 files changed

+69
-45
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ final class TDS {
172172

173173
// Vector support
174174
static final byte TDS_FEATURE_EXT_VECTORSUPPORT = 0x0E;
175-
static final byte VECTORSUPPORT_NOT_SUPPORTED = 0x00;
176-
static final byte VECTORSUPPORT_VERSION_1 = 0x01;
177-
static final byte VECTORSUPPORT_VERSION_2 = 0x02;
175+
static final byte VECTORSUPPORT_NOT_SUPPORTED = 0x00; // vector not supported; will return json formatted string
176+
static final byte VECTORSUPPORT_VERSION_1 = 0x01; // supports float32 vector type
177+
static final byte VECTORSUPPORT_VERSION_2 = 0x02; // supports float32 and float16 vector types
178178
static final byte MAX_VECTORSUPPORT_VERSION = 0x02;
179179

180180
// JSON support

src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
658658
*
659659
* @param vectorTypeSupport
660660
* A string that indicates the vector type support during connection initialization.
661-
* Valid values are "off" (vector types are returned as strings) and "v1" (vectors of type FLOAT32 are returned as vectors).
661+
* Valid values are :
662+
* - "off" (vector types are returned as strings)
663+
* - "v1" (supports float32 vector type)
664+
* - "v2" (supports float32 and float16 vector types)
662665
* Default is "v1".
663666
*/
664667
void setVectorTypeSupport(String vectorTypeSupport);
@@ -667,7 +670,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold,
667670
* Returns the value of the vectorTypeSupport connection property.
668671
*
669672
* @return vectorTypeSupport
670-
* The current vector type support setting ("off" or "v1").
673+
* The current vector type support setting ("off"|"v1"|"v2").
671674
*/
672675
String getVectorTypeSupport();
673676

src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,10 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
10901090
*
10911091
* @param vectorTypeSupport
10921092
* A string that indicates the vector type support during connection initialization.
1093-
* Valid values are "off" (vector types are returned as strings) and "v1" (vectors of type FLOAT32 are returned as vectors).
1093+
* Valid values are :
1094+
* - "off" (vector types are returned as strings)
1095+
* - "v1" (supports float32 vector type)
1096+
* - "v2" (supports float32 and float16 vector types)
10941097
* Default is "v1".
10951098
*/
10961099
void setVectorTypeSupport(String vectorTypeSupport);
@@ -1099,7 +1102,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
10991102
* Returns the value of the vectorTypeSupport connection property.
11001103
*
11011104
* @return vectorTypeSupport
1102-
* The current vector type support setting ("off" or "v1").
1105+
* The current vector type support setting ("off"|"v1"|"v2").
11031106
*/
11041107
String getVectorTypeSupport();
11051108

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ private ActiveDirectoryAuthentication() {
760760
}
761761
}
762762

763-
private static final String VECTOR_SUPPORT_OFF = "off";
764-
private static final String VECTOR_SUPPORT_V1 = "v1";
765-
private static final String VECTOR_SUPPORT_V2 = "v2";
763+
private static final String VECTOR_SUPPORT_OFF = "off"; // vector not supported; will return json formatted string
764+
private static final String VECTOR_SUPPORT_V1 = "v1"; // supports float32 vector type
765+
private static final String VECTOR_SUPPORT_V2 = "v2"; // supports float32 and float16 vector types
766766

767767
final static int TNIR_FIRST_ATTEMPT_TIMEOUT_MS = 500; // fraction of timeout to use for fast failover connections
768768

@@ -1106,13 +1106,15 @@ public void setBulkCopyForBatchInsertAllowEncryptedValueModifications(
11061106
* A string that indicates the vector type support during connection initialization.
11071107
* Valid values are :
11081108
* - "off" (vector types are returned as strings)
1109-
* - "v1" (vectors of type FLOAT32 are returned as vectors)
1110-
* - "v2" (vectors of type FLOAT32 and FLOAT16 are returned as vectors)
1109+
* - "v1" (supports float32 vector type)
1110+
* - "v2" (supports float32 and float16 vector types)
11111111
* Default is "v1".
11121112
*/
1113-
private String vectorTypeSupport = VECTOR_SUPPORT_V1;
1113+
private String vectorTypeSupport = SQLServerDriverStringProperty.VECTOR_TYPE_SUPPORT.getDefaultValue();
11141114

1115-
/** negotiated vector version between client and server */
1115+
/**
1116+
* Negotiated vector version between client and server
1117+
*/
11161118
private byte negotiatedVectorVersion = TDS.VECTORSUPPORT_NOT_SUPPORTED;
11171119

11181120
/**
@@ -1133,8 +1135,8 @@ public String getVectorTypeSupport() {
11331135
* A string that indicates the vector type support during connection initialization.
11341136
* Valid values are :
11351137
* - "off" (vector types are returned as strings)
1136-
* - "v1" (vectors of type FLOAT32 are returned as vectors)
1137-
* - "v2" (vectors of type FLOAT32 and FLOAT16 are returned as vectors)
1138+
* - "v1" (supports float32 vector type)
1139+
* - "v2" (supports float32 and float16 vector types)
11381140
* Default is "v1".
11391141
*/
11401142
@Override
@@ -5917,15 +5919,19 @@ int writeVectorSupportFeatureRequest(boolean write,
59175919
tdsWriter.writeInt(1);
59185920

59195921
byte clientVectorSupportVersion;
5920-
if (VECTOR_SUPPORT_V2.equalsIgnoreCase(vectorTypeSupport)) {
5921-
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_2;
5922-
} else if (VECTOR_SUPPORT_V1.equalsIgnoreCase(vectorTypeSupport)) {
5923-
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_1;
5924-
} else {
5925-
// Should not reach here due to prior validation.
5926-
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_1;
5922+
switch (vectorTypeSupport) {
5923+
case VECTOR_SUPPORT_V2:
5924+
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_2;
5925+
break;
5926+
case VECTOR_SUPPORT_V1:
5927+
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_1;
5928+
break;
5929+
case VECTOR_SUPPORT_OFF:
5930+
default:
5931+
// Should not reach here due to prior validation.
5932+
clientVectorSupportVersion = TDS.VECTORSUPPORT_VERSION_1;
5933+
break;
59275934
}
5928-
59295935
tdsWriter.writeByte(clientVectorSupportVersion);
59305936
}
59315937
return len;
@@ -7200,27 +7206,32 @@ private void onFeatureExtAck(byte featureId, byte[] data) throws SQLServerExcept
72007206
* @return The negotiated vector version
72017207
*/
72027208
private byte negotiateVectorVersion(String clientVectorSupport, byte serverVersion) {
7203-
// If client has vector support disabled, return "off"
7204-
if (VECTOR_SUPPORT_OFF.equalsIgnoreCase(clientVectorSupport)) {
7205-
return TDS.VECTORSUPPORT_NOT_SUPPORTED;
7206-
}
72077209

7208-
// If server doesn't support vectors, return "off"
7210+
// If server doesn't support vectors, negotiation is off
72097211
if (serverVersion == TDS.VECTORSUPPORT_NOT_SUPPORTED) {
72107212
return TDS.VECTORSUPPORT_NOT_SUPPORTED;
72117213
}
72127214

7213-
// Determine client's maximum supported version
72147215
byte clientMaxVersion;
7215-
if (VECTOR_SUPPORT_V2.equalsIgnoreCase(clientVectorSupport)) {
7216-
clientMaxVersion = TDS.VECTORSUPPORT_VERSION_2;
7217-
} else if (VECTOR_SUPPORT_V1.equalsIgnoreCase(clientVectorSupport)) {
7218-
clientMaxVersion = TDS.VECTORSUPPORT_VERSION_1;
7219-
} else {
7220-
return TDS.VECTORSUPPORT_NOT_SUPPORTED; // Invalid client setting
7216+
7217+
switch (clientVectorSupport.toLowerCase()) {
7218+
case VECTOR_SUPPORT_OFF:
7219+
return TDS.VECTORSUPPORT_NOT_SUPPORTED;
7220+
7221+
case VECTOR_SUPPORT_V2:
7222+
clientMaxVersion = TDS.VECTORSUPPORT_VERSION_2;
7223+
break;
7224+
7225+
case VECTOR_SUPPORT_V1:
7226+
clientMaxVersion = TDS.VECTORSUPPORT_VERSION_1;
7227+
break;
7228+
7229+
default:
7230+
// Invalid client setting
7231+
return TDS.VECTORSUPPORT_NOT_SUPPORTED;
72217232
}
72227233

7223-
// Negotiate version: use minimum of client and server versions
7234+
// Negotiate using the minimum supported version
72247235
return (byte) Math.min(clientMaxVersion, serverVersion);
72257236
}
72267237

@@ -7531,6 +7542,7 @@ final boolean complete(LogonCommand logonCommand, TDSReader tdsReader) throws SQ
75317542

75327543
// request vector support
75337544
len += writeVectorSupportFeatureRequest(false, tdsWriter);
7545+
75347546
// request JSON support
75357547
len += writeJSONSupportFeatureRequest(false, tdsWriter);
75367548

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnectionPoolProxy.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,19 +893,25 @@ public void setBulkCopyForBatchInsertAllowEncryptedValueModifications(boolean bu
893893
}
894894

895895
/**
896-
* Returns the vectorTypeSupport value.
896+
* Returns the value of the vectorTypeSupport connection property.
897897
*
898-
* @return the vectorTypeSupport value.
898+
* @return vectorTypeSupport
899+
* The current vector type support setting ("off"|"v1"|"v2").
899900
*/
900901
public String getVectorTypeSupport() {
901902
return wrappedConnection.getVectorTypeSupport();
902903
}
903904

904905
/**
905-
* Sets the vectorTypeSupport value.
906+
* Sets the value of the vectorTypeSupport connection property.
906907
*
907908
* @param vectorTypeSupport
908-
* the vectorTypeSupport value to set ("off" or "v1").
909+
* A string that indicates the vector type support during connection initialization.
910+
* Valid values are :
911+
* - "off" (vector types are returned as strings)
912+
* - "v1" (supports float32 vector type)
913+
* - "v2" (supports float32 and float16 vector types)
914+
* Default is "v1".
909915
*/
910916
public void setVectorTypeSupport(String vectorTypeSupport) {
911917
wrappedConnection.setVectorTypeSupport(vectorTypeSupport);

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,8 @@ static DatetimeType valueOfString(String value) throws SQLServerException {
503503

504504
enum VectorTypeSupport {
505505
OFF("off"),
506-
V1("v1"),
507-
V2("v2");
506+
V1("v1"), //float32 support
507+
V2("v2"); //float32 and float16 support
508508

509509
private final String type;
510510

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ protected Object[][] getContents() {
341341
{"R_unsupportedStmtColEncSetting", "SQLServerStatementColumnEncryptionSetting cannot be null."},
342342
{"R_unsupportedConversionAE", "The conversion from {0} to {1} is unsupported for encrypted column."},
343343
{"R_InvalidDataForAE", "The given value of type {0} from the data source cannot be converted to type {1} of the specified target column {2}."},
344-
{"R_vectorTypeSupportPropertyDescription", "Determines the vector support feature negotiation during connection initialization. Valid values are \"off\" or \"v1\". Default is \"v1\"."},
345-
{"R_invalidVectorTypeSupport", "Invalid value for vectorTypeSupport: {0}. Valid values are \"off\" or \"v1\"."},
344+
{"R_vectorTypeSupportPropertyDescription", "Determines the vector support feature negotiation during connection initialization. Valid values are \"off\" ,\"v1\" or \"v2\". Default is \"v1\"."},
345+
{"R_invalidVectorTypeSupport", "Invalid value for vectorTypeSupport: {0}. Valid values are \"off\" ,\"v1\" or \"v2\"."},
346346
{"R_VectorDimensionCountMismatch", "Mismatch between vector dimension count and provided data."},
347347
{"R_InvalidVectorDimensionCount", "Invalid vector dimension count."},
348348
{"R_VectorDimensionTypeCannotBeNull", "Vector dimension type cannot be null."},

0 commit comments

Comments
 (0)