Skip to content

Conversation

@muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Nov 19, 2025

Description

GitHub issue : PreparedStatement.executeBatch() fails for VARBINARY function parameters with bulk copy enabled #2825

This PR addresses a critical bug where PreparedStatement.executeBatch() fails when SQL functions are used as parameters in INSERT statements with bulk copy enabled (useBulkCopyForBatchInsert=true). The driver now properly detects incompatible SQL constructs and automatically falls back to standard batch execution.

Problem

When bulk copy for batch insert is enabled, the driver attempts to process all batch operations through the Bulk Copy API, including those containing SQL functions like len(?), encryptbykey(), or other expressions wrapping parameters. However, as documented in the Bulk Copy API limitations, wildcards (?) are the only supported parameters for this functionality.

This incompatibility resulted in various failures:

  • "Parsing user's Batch Insert SQL Query failed: Number of provided columns X does not match the table definition Y"
  • Invalid data type conversion errors
  • "Unable to retrieve data from the source"
  • Complete batch operation failures without proper fallback mechanism

Fix

Enhanced the fallback detection logic to identify when SQL functions or unsupported expressions are present in parameterized INSERT statements during bulk copy batch operations. When such cases are detected:

  • Bulk copy processing is bypassed
  • The driver automatically switches to standard PreparedStatement batch execution
  • Operations complete successfully without data loss or user intervention

Testing

  • Added comprehensive test in BatchExecutionWithBulkCopyTest to validat fallback behavior for SQL function scenarios
  • Confirmed no regression for standard bulk copy operations
  • Verified proper logging and error messaging during fallback detection

This fix ensures reliable batch operations for all SQL statement types while maintaining optimal performance for compatible bulk copy scenarios.

@muskan124947 muskan124947 self-assigned this Nov 19, 2025
@muskan124947 muskan124947 added this to the 13.3.1 milestone Nov 19, 2025
@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.38%. Comparing base (caef383) to head (a2104e8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2845      +/-   ##
============================================
+ Coverage     56.36%   56.38%   +0.02%     
+ Complexity     4523     4521       -2     
============================================
  Files           151      151              
  Lines         34442    34442              
  Branches       5738     5738              
============================================
+ Hits          19412    19420       +8     
+ Misses        12408    12400       -8     
  Partials       2622     2622              

☔ 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
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@muskan124947 muskan124947 merged commit 8f3ddc4 into main Nov 26, 2025
19 checks passed
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.

5 participants