Repository navigation
Update vector tests for server-side implicit FLOAT16/FLOAT32 conversion - #3005
Conversation
SQL Server now allows implicit conversion between FLOAT16 and FLOAT32 vector subtypes. Update cross-type conversion tests to expect success instead of SQLException. Also accept updated server error message for exceeding max vector dimensions.
… SP/UDF/TVF parameter passing, round-trip precision, and cross-type CSV bulk copy
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3005 +/- ##
============================================
+ Coverage 60.26% 60.50% +0.23%
- Complexity 5168 5250 +82
============================================
Files 153 153
Lines 36646 36646
Branches 6727 6727
============================================
+ Hits 22086 22173 +87
+ Misses 10752 10735 -17
+ Partials 3808 3738 -70 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Not ready to approve
Several updated/new tests don’t fully validate converted vector contents (and two CSV tests ORDER BY a VECTOR column, which may fail on servers that don’t support ordering on VECTOR).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR updates the JDBC driver’s vector datatype test suite to align with a SQL Server capability change: implicit/explicit conversions between vector(..., float16) and vector(..., float32) now succeed where they previously failed, and new scenarios (CAST/CONVERT, DDL, DML, and bulk copy) are covered.
Changes:
- Updates existing FLOAT16/FLOAT32 cross-type tests to expect successful execution (rather than
SQLException) and validate results. - Adds new FLOAT16/FLOAT32 conversion tests covering CAST/CONVERT, ALTER COLUMN, UPDATE, and routine (SP/UDF/TVF) scenarios.
- Adds a new CSV resource used for cross-type bulk copy CSV test cases.
File summaries
| File | Description |
|---|---|
| src/test/resources/BulkCopyCSVTestInputCrossTypeVector.csv | Adds CSV input data for cross-type VECTOR bulk copy CSV tests. |
| src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorTest.java | Broadens the accepted error message for “exceeds max vector dimension” test expectations. |
| src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java | Converts cross-type tests from “expected failure” to “expected success” and adds many new conversion scenarios. |
| src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/bulkcopy/VectorFloat16BulkCopyTest.java | Updates cross-type bulk copy tests to succeed and adds CSV cross-type bulk copy coverage. |
Review details
Suppressed comments (9)
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/bulkcopy/VectorFloat16BulkCopyTest.java:1173
- Ordering by a VECTOR column can fail on servers that don't support ordering/comparison for VECTOR types, and it isn't needed for validating row count here. Dropping the ORDER BY makes the test more robust.
try (ResultSet rs = stmt.executeQuery("SELECT v FROM " + dstTable + " ORDER BY v")) {
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:363
- This test asserts the converted vector's type and dimension count, but doesn't verify the element values after the FLOAT32→FLOAT16 cross-type INSERT...SELECT. Adding a data assertion would better validate the conversion behavior (with FLOAT16 tolerance).
assertTrue(rs.next(), "No result found in FLOAT16 table after cross-type insert.");
Vector result = rs.getObject("f16_col", Vector.class);
assertNotNull(result, "Retrieved FLOAT16 vector is null.");
assertEquals(VectorDimensionType.FLOAT16, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:412
- After inserting a FLOAT32 Vector via setObject into a FLOAT16 column, the test only checks type and dimension count. It should also validate that the stored values match the source vector within FLOAT16 tolerance.
assertTrue(rs.next(), "No result found in FLOAT16 table after cross-type insert.");
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result, "Retrieved FLOAT16 vector is null.");
assertEquals(VectorDimensionType.FLOAT16, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:461
- After inserting a FLOAT16 Vector via setObject into a FLOAT32 column, the test only checks type and dimension count. It should also validate that the stored values match the source vector (FLOAT16→FLOAT32 should be exact).
assertTrue(rs.next(), "No result found in FLOAT32 table after cross-type insert.");
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result, "Retrieved FLOAT32 vector is null.");
assertEquals(VectorDimensionType.FLOAT32, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:606
- The Javadoc says the ALTER COLUMN conversion "preserves data", but the test currently only verifies type and dimension count. Add a value assertion to ensure the converted vector elements are preserved.
try (ResultSet rs = stmt.executeQuery("SELECT v FROM " + table + " WHERE id = 1")) {
assertTrue(rs.next());
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result);
assertEquals(VectorDimensionType.FLOAT32, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:635
- The Javadoc says the ALTER COLUMN conversion preserves data within FLOAT16 precision, but the test currently only verifies type and dimension count. Add a value assertion to validate the actual conversion result.
try (ResultSet rs = stmt.executeQuery("SELECT v FROM " + table + " WHERE id = 1")) {
assertTrue(rs.next());
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result);
assertEquals(VectorDimensionType.FLOAT16, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/VectorFloat16Test.java:2344
- This test says it verifies the data was converted and stored correctly, but it currently only checks vector types and dimension counts. Add assertions on the stored element values to actually validate the cross-type conversion.
Vector f32 = rs.getObject("v_float32", Vector.class);
Vector f16 = rs.getObject("v_float16", Vector.class);
assertNotNull(f32, "FLOAT32 result is null.");
assertNotNull(f16, "FLOAT16 result is null.");
assertEquals(VectorDimensionType.FLOAT32, f32.getVectorDimensionType());
assertEquals(VectorDimensionType.FLOAT16, f16.getVectorDimensionType());
assertEquals(3, f32.getDimensionCount());
assertEquals(3, f16.getDimensionCount());
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/bulkcopy/VectorFloat16BulkCopyTest.java:1048
- This cross-type bulk copy test checks only the destination vector type and dimension count. Adding a value assertion would better validate that the implicit FLOAT16→FLOAT32 conversion preserved the expected element values.
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result, "Retrieved FLOAT32 vector is null.");
assertEquals(VectorDimensionType.FLOAT32, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
}
src/test/java/com/microsoft/sqlserver/jdbc/datatypes/vector/bulkcopy/VectorFloat16BulkCopyTest.java:1092
- This cross-type bulk copy test checks only the destination vector type and dimension count. Adding a value assertion would better validate that the implicit FLOAT32→FLOAT16 conversion produced the expected values (within FLOAT16 tolerance).
Vector result = rs.getObject("v", Vector.class);
assertNotNull(result, "Retrieved FLOAT16 vector is null.");
assertEquals(VectorDimensionType.FLOAT16, result.getVectorDimensionType());
assertEquals(3, result.getDimensionCount());
}
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
bba6003 to
af94cf6
Compare
…conversion - Add assertVectorDataEquals to CAST, CONVERT, UPDATE, SP, UDF, TVF tests - Add testFloat16PrecisionLossWithNonRepresentableValues (lossy F32->F16) - Add testCrossTypeDimensionMismatchFails (negative test) - Add testNullVectorCrossTypeInsertSelect and testNullVectorCrossTypeSetObject - Add testGetObjectCrossReadFloat16AsFloat32RoundTrip (JDBC-layer cross-read) - Add per-row value assertions to CSV bulk copy cross-type tests - Fix cleanup in SP/UDF/TVF tests (use TestUtils helpers for apostrophe safety) - Remove ORDER BY v from CSV tests (vectors cannot be sorted)
af94cf6 to
b9e3106
Compare
Summary
SQL Server now supports implicit and explicit conversion between FLOAT16 and FLOAT32 vector subtypes. This PR updates existing tests that expected
SQLExceptionfor cross-type operations to instead expect success, and adds comprehensive new test coverage for all conversion scenarios.Motivation
The server-side change enables direct conversion between
vector(N, float16)andvector(N, float32)without requiring intermediatevarcharconversion. This improves usability and performance for vector operations across different precision levels.Previously, cross-type operations like
INSERT INTO f32_table SELECT * FROM f16_tableorCAST(f16_col AS VECTOR(3, float32))would fail with:With the server update, these operations now succeed with implicit conversion.
Changes
Updated existing tests (expect success instead of failure)
SQLException.testBulkCopyFloat16ToFloat32Table,testBulkCopyFloat32ToFloat16Table,testMixedBulkCopyColumnMappingSwapped) now verify successful transfer with implicit conversion.New test coverage
testExplicitCastFloat16ToFloat32CAST(v AS VECTOR(3, float32))with data assertiontestExplicitCastFloat32ToFloat16CAST(v AS VECTOR(3, float16))with data assertiontestConvertFloat16ToFloat32CONVERT(VECTOR(3, float32), v)with data assertiontestConvertFloat32ToFloat16CONVERT(VECTOR(3, float16), v)with data assertiontestAlterColumnFloat16ToFloat32ALTER TABLE ... ALTER COLUMN v VECTOR(3, float32)with data assertiontestAlterColumnFloat32ToFloat16ALTER TABLE ... ALTER COLUMN v VECTOR(3, float16)with data assertiontestCrossTypeUpdateFloat32ColWithFloat16ValuetestCrossTypeUpdateFloat16ColWithFloat32ValuetestStoredProcedureCrossTypeParameterPassing@vec VECTOR(3), caller passes FLOAT16, assert valuestestUdfCrossTypeParameterPassing@vec VECTOR(3, float16), called with FLOAT32 source, assert valuestestTvfCrossTypeReturnCAST(v AS VECTOR(3, float32))from FLOAT16 source, assert valuestestCrossTypeRoundTripPrecisiontestFloat16PrecisionLossWithNonRepresentableValuestestCrossTypeDimensionMismatchFailstestNullVectorCrossTypeInsertSelecttestNullVectorCrossTypeSetObjecttestGetObjectCrossReadFloat16AsFloat32RoundTriptestBulkCopyCrossTypeCSVFloat16ToFloat32testBulkCopyCrossTypeCSVFloat32ToFloat16New test resource
BulkCopyCSVTestInputCrossTypeVector.csv— 3-row CSV with VECTOR(3) data for cross-type bulk copy tests.Server capability covered
testInsertFloat32FromFloat16Table,testInsertFloat16FromFloat32TabletestSetObjectFloat32VectorIntoFloat16Column,testSetObjectFloat16VectorIntoFloat32ColumntestExplicitCastFloat16ToFloat32,testExplicitCastFloat32ToFloat16testConvertFloat16ToFloat32,testConvertFloat32ToFloat16testAlterColumnFloat16ToFloat32,testAlterColumnFloat32ToFloat16testStoredProcedureCrossTypeParameterPassingtestUdfCrossTypeParameterPassingtestTvfCrossTypeReturntestCrossTypeUpdateFloat32ColWithFloat16Value,testCrossTypeUpdateFloat16ColWithFloat32ValuetestCrossTypeRoundTripPrecisiontestFloat16PrecisionLossWithNonRepresentableValuestestCrossTypeDimensionMismatchFailstestNullVectorCrossTypeInsertSelect,testNullVectorCrossTypeSetObjecttestGetObjectCrossReadFloat16AsFloat32RoundTriptestBulkCopyFloat16ToFloat32Table,testBulkCopyFloat32ToFloat16Table,testMixedBulkCopyColumnMappingSwappedtestBulkCopyCrossTypeCSVFloat16ToFloat32,testBulkCopyCrossTypeCSVFloat32ToFloat16Testing
All tests are tagged with
@Tag(Constants.vectorFloat16Test)and require a server with vector version 2 support. Tests are excluded from default CI runs viaexcludedGroupsinpom.xml.