Skip to content

Conversation

@muskan124947
Copy link
Contributor

@muskan124947 muskan124947 commented Dec 3, 2025

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

@muskan124947 muskan124947 self-assigned this Dec 3, 2025
@codecov
Copy link

codecov bot commented Dec 3, 2025

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.

@muskan124947 muskan124947 added this to the 13.3.1 milestone Dec 4, 2025
machavan
machavan previously approved these changes Dec 4, 2025
Updated comment to clarify the validation of inserted rows.
@muskan124947 muskan124947 requested a review from Ananya2 December 8, 2025 04:04
@muskan124947 muskan124947 merged commit d6861e5 into main Dec 8, 2025
17 of 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.

4 participants