Skip to content

Fix to address bulk copy batch insert operation on persisted computed column - #2855

Merged
Muskan Gupta (muskan124947) merged 10 commits into
mainfrom
users/muskgupta/gitHubIssue_persisted_bulkCopy
Dec 8, 2025
Merged

Fix to address bulk copy batch insert operation on persisted computed column#2855
Muskan Gupta (muskan124947) merged 10 commits into
mainfrom
users/muskgupta/gitHubIssue_persisted_bulkCopy

Conversation

@muskan124947

@muskan124947 Muskan Gupta (muskan124947) commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

Description

Bulk insert operations using useBulkCopyForBatchInsert failed when the target table contained computed persisted columns. The driver incorrectly validated the destination column ordinal against the total physical column count instead of the actual set of valid destination metadata columns, causing valid mappings to be rejected.

This PR updates the bulk copy column mapping validation logic to use destColumnMetadata.containsKey(...) rather than relying solely on destColumnCount. This ensures computed columns—which are not writable targets—no longer cause false failures during bulk copy.

GitHub Issue : Persisted Computed Columns Break useBulkCopyForBatchInsert

Problem

Bulk copy operations failed when the target table included a computed persisted column. The driver validated the destination column ordinal using the physical column count (destColumnCount), causing valid mappings to be incorrectly rejected. This resulted in the error:

"Column X is invalid. Please check your column mappings."

Fix

Replaced the ordinal comparison with proper validation:

else if (0 > cm.destinationColumnOrdinal 
        || !destColumnMetadata.containsKey(cm.destinationColumnOrdinal)) {

This ensures:

  • Computed persisted columns are excluded from writable targets
  • Valid column mappings are no longer rejected due to mismatched physical counts
  • Bulk copy works correctly with tables containing computed columns

Testing

  • Added test case for bulk copy on a table containing a computed persisted column : This verifies column mappings resolve correctly, computed columns are ignored during validation and no exceptions are thrown
  • Existing bulk copy tests continue to pass and mappings for non-computed columns remain unaffected

@codecov

codecov Bot commented Dec 3, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 56.42%. Comparing base (74d1072) to head (27200fd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2855      +/-   ##
============================================
- Coverage     56.46%   56.42%   -0.05%     
+ Complexity     4576     4564      -12     
============================================
  Files           151      151              
  Lines         34560    34560              
  Branches       5768     5768              
============================================
- Hits          19516    19500      -16     
- Misses        12429    12430       +1     
- Partials       2615     2630      +15     

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

Updated comment to clarify the validation of inserted rows.
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