Handling proper fallback for SQL functions in bulk copy batch insert operations #2845
+106
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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:
Testing
BatchExecutionWithBulkCopyTestto validat fallback behavior for SQL function scenariosThis fix ensures reliable batch operations for all SQL statement types while maintaining optimal performance for compatible bulk copy scenarios.