Fix to ignore computed columns during BulkCopy#1562
Fix to ignore computed columns during BulkCopy#1562lilgreenbird merged 3 commits intomicrosoft:mainfrom
Conversation
76b9ed8 to
7282212
Compare
|
Thanks for the contribution @alagrede, the team will test this and get back to you with the results. |
|
hi @alagrede Apologies it took so long to get back to you on this, this had fallen through the cracks.. We had discussed this within our team we are ok to add this to the driver could you please resolve the conflicts in your branch? Also, we would rather not add server version checks in the driver, I think it should be fine to just check for is_computed since if it was not supported that column would not be returned. Thank you for your contribution. |
7282212 to
0a69e78
Compare
|
Hi @lilgreenbird |
c2e3b3f
0a69e78 to
c2e3b3f
Compare
|
This fix cause NPE with computed column (if that computed column is NOT last column as per column-id), see the exception: java.lang.NullPointerException: Cannot read field "columnName" because the return value of "java.util.Map.get(Object)" is null |
|
Hi @atul-delphix, Can you open a new issue describing the above problem? Thanks. |
|
@Jeffery-Wasty created new issue #2606 |
Hello,
I'm facing a problem with the bulk API for batch insert with computed columns.
I'm using an SQL table with computed columns like
My insert query uses for bulk:
insert into myTable (id, json) values (?, ?)The current behavior of the driver is to reject the query with:
java.sql.BatchUpdateException: The column "vcol1" cannot be modified because it is either a computed column or is the result of a UNION operator.After investigating and testing this fix on my project, there is no specific reason to reject the batch insert. The current Bulk code simply reads and compares all the columns found in the table.
I updated the current code to ignore irrelevant computed columns when inserting in bulk and it works like a charm.
Currently, the relevant documentation does not mention any limitation on the computed columns (so the documentation is still true):
https://docs.microsoft.com/en-us/sql/connect/jdbc/use-bulk-copy-api-batch-insert-operation?view=sql-server-ver15
I also added a new unit test to verify and demonstrate this use case:
BatchExecutionWithBulkCopyTest#testComputedColsEDIT: Code updated to be compatible with versions prior than SQL Server 2016
Sincerely