Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2025

Conversation

muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Jun 4, 2025

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

@muskan124947 muskan124947 self-assigned this Jun 4, 2025
Copy link

codecov bot commented Jun 4, 2025

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 muskan124947 added the Under Review Used for pull requests under review label Jun 11, 2025
@muskan124947 muskan124947 merged commit c513efa into main Jun 18, 2025
18 of 19 checks passed
@muskan124947 muskan124947 removed the Under Review Used for pull requests under review label Jun 23, 2025
@machavan machavan added this to the 13.1.0 milestone Jun 25, 2025
@David-Engel David-Engel changed the title Extended bulk copy API support for temporal and money datatypes Extended bulk copy for batch insert support for temporal and money datatypes Jun 27, 2025
@muskan124947 muskan124947 deleted the users/muskgupta/icm#628030717 branch June 30, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants