Skip to content

Extended bulk copy for batch insert support for temporal and money datatypes - #2670

Merged
Muskan Gupta (muskan124947) merged 4 commits into
mainfrom
users/muskgupta/icm#628030717
Jun 18, 2025
Merged

Muskan Gupta (muskan124947) merged 4 commits into
mainfrom
users/muskgupta/icm#628030717

Conversation

@muskan124947

@muskan124947 Muskan Gupta (muskan124947) commented Jun 4, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR addresses a customer reported issue.
The Bulk Copy API did not previously support batch inserts using useBulkCopyForBatchInsert=true for certain SQL Server data types such as DATETIME, DATE, MONEY, etc. As a result, these types were inserted row by row, degrading performance when handling large datasets.

According to official Microsoft documentation (see here), the following data types are not supported by the Bulk Copy API: MONEY, SMALLMONEY, DATE, DATETIME, DATETIMEOFFSET, SMALLDATETIME, TIME, GEOMETRY, and GEOGRAPHY.

Resolution details:
This PR extends support in the Bulk Copy API for the aforementioned data types. The updated behavior is as follows:

  • When the flag 'useBulkCopyForBatchInsert=true' is enabled, data will sent as varchar. This behavior is controlled by the connection property sendTemporalDataTypesAsStringForBulkCopy, which is set to true by default.
  • When the connection property(sendTemporalDataTypesAsStringForBulkCopy) is explicitly set to FALSE, then DATE, DATETIME, DATIMETIME2 DATETIMEOFFSET, SMALLDATETIME, and TIME datatypes will be sent in their native SQL Server format instead of as strings.
  • Additionally, even without setting this connection string to FALSE, MONEY and SMALLMONEY datatypes will be sent as MONEY / SMALLMONEY datatypes.

Note: This extended handling is not supported in Synapse Analytics (formerly SQL DW). In that environment, bulk copy operations for these data types will continue to fall back to row-wise inserts.

Testing

Test scenarios have been added to validate the behavior of the Bulk Copy API for the affected data types under the following configurations:

  1. useBulkCopyForBatchInsert=true (sendTemporalDataTypesAsStringForBulkCopy=true by default)
  2. useBulkCopyForBatchInsert=true and sendTemporalDataTypesAsStringForBulkCopy=false
@codecov

codecov Bot commented Jun 4, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 51.94%. Comparing base (f0706ea) to head (6ea9638).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2670      +/-   ##
============================================
+ Coverage     51.62%   51.94%   +0.32%     
- Complexity     4008     4064      +56     
============================================
  Files           147      147              
  Lines         33800    33800              
  Branches       5650     5650              
============================================
+ Hits          17448    17557     +109     
+ Misses        13888    13815      -73     
+ Partials       2464     2428      -36     

☔ View full report in Codecov by Sentry.
📢 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.
@muskan124947 Muskan Gupta (muskan124947) added the Under Review Used for pull requests under review label Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants