Skip to content

Update vector tests for server-side implicit FLOAT16/FLOAT32 conversion - #3005

Merged
Mahendra Chavan (machavan) merged 4 commits into
mainfrom
users/muskgupta/vector_implicit_conversion
Aug 6, 2026
Merged

Mahendra Chavan (machavan) merged 4 commits into
mainfrom
users/muskgupta/vector_implicit_conversion

Conversation

@muskan124947

@muskan124947 Muskan Gupta (muskan124947) commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

SQL Server now supports implicit and explicit conversion between FLOAT16 and FLOAT32 vector subtypes. This PR updates existing tests that expected SQLException for 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) and vector(N, float32) without requiring intermediate varchar conversion. This improves usability and performance for vector operations across different precision levels.

Previously, cross-type operations like INSERT INTO f32_table SELECT * FROM f16_table or CAST(f16_col AS VECTOR(3, float32)) would fail with:

"Conversion of vector from data type float16 to float32 is not allowed."

With the server update, these operations now succeed with implicit conversion.

Changes

Updated existing tests (expect success instead of failure)

  • VectorFloat16Test.java: Cross-type INSERT...SELECT and setObject tests now verify data arrives correctly instead of catching SQLException.
  • VectorFloat16BulkCopyTest.java: Bulk copy cross-type tests (testBulkCopyFloat16ToFloat32Table, testBulkCopyFloat32ToFloat16Table, testMixedBulkCopyColumnMappingSwapped) now verify successful transfer with implicit conversion.
  • VectorTest.java: Updated expected error message for exceeding max vector dimensions.

New test coverage

Test Scenario
testExplicitCastFloat16ToFloat32 CAST(v AS VECTOR(3, float32)) with data assertion
testExplicitCastFloat32ToFloat16 CAST(v AS VECTOR(3, float16)) with data assertion
testConvertFloat16ToFloat32 CONVERT(VECTOR(3, float32), v) with data assertion
testConvertFloat32ToFloat16 CONVERT(VECTOR(3, float16), v) with data assertion
testAlterColumnFloat16ToFloat32 ALTER TABLE ... ALTER COLUMN v VECTOR(3, float32) with data assertion
testAlterColumnFloat32ToFloat16 ALTER TABLE ... ALTER COLUMN v VECTOR(3, float16) with data assertion
testCrossTypeUpdateFloat32ColWithFloat16Value UPDATE a FLOAT32 column with a FLOAT16 Vector object, assert values
testCrossTypeUpdateFloat16ColWithFloat32Value UPDATE a FLOAT16 column with a FLOAT32 Vector object, assert values
testStoredProcedureCrossTypeParameterPassing SP declares @vec VECTOR(3), caller passes FLOAT16, assert values
testUdfCrossTypeParameterPassing UDF declares @vec VECTOR(3, float16), called with FLOAT32 source, assert values
testTvfCrossTypeReturn Inline TVF returns CAST(v AS VECTOR(3, float32)) from FLOAT16 source, assert values
testCrossTypeRoundTripPrecision F32→F16→F32 round-trip preserves values within FLOAT16 precision
testFloat16PrecisionLossWithNonRepresentableValues F32→F16 with 0.1/0.3/0.7 verifies lossy rounding contract
testCrossTypeDimensionMismatchFails VECTOR(3, float16)→VECTOR(4, float32) rejects dimension mismatch
testNullVectorCrossTypeInsertSelect NULL vector via cross-type INSERT...SELECT remains NULL
testNullVectorCrossTypeSetObject setObject(null) into FLOAT16 column stores NULL correctly
testGetObjectCrossReadFloat16AsFloat32RoundTrip Read FLOAT16 → setObject into FLOAT32 col → verify values end-to-end
testBulkCopyCrossTypeCSVFloat16ToFloat32 CSV declared as FLOAT16 imported into FLOAT32, per-row value assertion
testBulkCopyCrossTypeCSVFloat32ToFloat16 CSV declared as FLOAT32 imported into FLOAT16, per-row value assertion

New test resource

  • BulkCopyCSVTestInputCrossTypeVector.csv — 3-row CSV with VECTOR(3) data for cross-type bulk copy tests.

Server capability covered

Capability Tests
Implicit conversion in assignments (INSERT...SELECT) testInsertFloat32FromFloat16Table, testInsertFloat16FromFloat32Table
Implicit conversion in parameter passing (setObject) testSetObjectFloat32VectorIntoFloat16Column, testSetObjectFloat16VectorIntoFloat32Column
Explicit CAST testExplicitCastFloat16ToFloat32, testExplicitCastFloat32ToFloat16
Explicit CONVERT testConvertFloat16ToFloat32, testConvertFloat32ToFloat16
DDL (ALTER COLUMN) testAlterColumnFloat16ToFloat32, testAlterColumnFloat32ToFloat16
SP cross-type parameter passing testStoredProcedureCrossTypeParameterPassing
UDF cross-type parameter passing testUdfCrossTypeParameterPassing
TVF cross-type return testTvfCrossTypeReturn
UPDATE with cross-type value testCrossTypeUpdateFloat32ColWithFloat16Value, testCrossTypeUpdateFloat16ColWithFloat32Value
Round-trip precision fidelity testCrossTypeRoundTripPrecision
Precision-loss (lossy F32→F16) testFloat16PrecisionLossWithNonRepresentableValues
Dimension mismatch still rejected testCrossTypeDimensionMismatchFails
NULL vector cross-type handling testNullVectorCrossTypeInsertSelect, testNullVectorCrossTypeSetObject
JDBC-layer cross-read round-trip testGetObjectCrossReadFloat16AsFloat32RoundTrip
Bulk copy cross-type (table-to-table) testBulkCopyFloat16ToFloat32Table, testBulkCopyFloat32ToFloat16Table, testMixedBulkCopyColumnMappingSwapped
Bulk copy cross-type (CSV) testBulkCopyCrossTypeCSVFloat16ToFloat32, testBulkCopyCrossTypeCSVFloat32ToFloat16

Testing

All tests are tagged with @Tag(Constants.vectorFloat16Test) and require a server with vector version 2 support. Tests are excluded from default CI runs via excludedGroups in pom.xml.

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

codecov Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.50%. Comparing base (1c2302b) to head (b9e3106).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@muskan124947
Muskan Gupta (muskan124947) force-pushed the users/muskgupta/vector_implicit_conversion branch from bba6003 to af94cf6 Compare August 5, 2026 07:46
…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)
@muskan124947
Muskan Gupta (muskan124947) force-pushed the users/muskgupta/vector_implicit_conversion branch from af94cf6 to b9e3106 Compare August 5, 2026 07:47
@machavan
Mahendra Chavan (machavan) merged commit b462119 into main Aug 6, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Closed/Merged PRs in MSSQL JDBC Aug 6, 2026
@muskan124947 Muskan Gupta (muskan124947) added this to the 13.6.0 milestone Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed/Merged PRs

Development

Successfully merging this pull request may close these issues.

5 participants