Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulk Copy with SQL Variant type fails due to null sourceResultSet #2442

Open
hchenatsafe opened this issue Jun 6, 2024 · 7 comments
Open
Labels
Backlog The topic in question has been recognized and added to development backlog Enhancement An enhancement to the driver. Lower priority than bugs.

Comments

@hchenatsafe
Copy link

Driver version

12.4.1.jre8

SQL Server version

Microsoft SQL Server 2014 (SP3-GDR) (KB5029184) - 12.0.6179.1 (X64)
Jul 27 2023 21:44:30
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.3 (Build 9600: ) (Hypervisor)

Client Operating System

Ubuntu 22.04

JAVA/JVM version

openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Ubuntu-122.04.1, mixed mode, sharing)

Table schema

Provide the table schema to repro the issue.

Problem description

Our application supports inserting using bulk copy, and we call writeToServer(ISQLServerBulkData sourceData) to do so. We are trying to add support for sql_variant type (-156), but we run into a NullPointerException when we pass a sourceData object containing that type.

It appears that writeSqlVariant() relies on a sourceResultSet that is set to null in writeToServer(ISQLServerBulkData sourceData)

Expected behavior

Bulk source data is written successfully.

Actual behavior

See the following trace

Error message/stack trace

java.lang.NullPointerException: Cannot invoke "com.microsoft.sqlserver.jdbc.SQLServerResultSet.getVariantInternalType(int)" because "sourceResultSet" is null
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeSqlVariant(SQLServerBulkCopy.java:2614)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeColumnToTdsWriter(SQLServerBulkCopy.java:2580)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeColumn(SQLServerBulkCopy.java:3094)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeBatchData(SQLServerBulkCopy.java:3652)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.doInsertBulk(SQLServerBulkCopy.java:1582)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.access$300(SQLServerBulkCopy.java:67)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy$1InsertBulk.doExecute(SQLServerBulkCopy.java:673)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7675)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4137)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.sendBulkLoadBCP(SQLServerBulkCopy.java:707)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:1670)
at com.microsoft.sqlserver.jdbc.SQLServerBulkCopy.writeToServer(SQLServerBulkCopy.java:630)

@lilgreenbird
Copy link
Contributor

hi @hchenatsafe

We do have tests for bulkcopy using the SQL Variant type, what are you doing different? Could you please provide us with a repro of the issue?

@lilgreenbird lilgreenbird added the Question Used when a question is asked, as opposed to an issue being raised label Jun 7, 2024
@hchenatsafe
Copy link
Author

Hi @lilgreenbird, thanks for following up!

Your tests seem to be using writeToServer(ResultSet sourceData), which wouldn't run into this issue since sourceResultSet would be set here.

Our application passes a source data object that implements ISQLServerBulkData, so we are using writeToServer(ISQLServerBulkData sourceData) where sourceResultSet seems to be set to null, and we run into this error when writeSqlVariant() is called

@lilgreenbird
Copy link
Contributor

@hchenatsafe

Could you please include your repro code here along with the schema and connection string used

@hchenatsafe
Copy link
Author

It seems it would be a challenge to untangle our source to provide a clean repro. We'll leave this issue up to your consideration. Thanks for your assistance!

@lilgreenbird
Copy link
Contributor

thanks @hchenatsafe I can see in the code path that this would be an issue. Looks like this had been an issue since day 1, I will add this as an enhancement and add a note in the doc that this isn't supported right now. Thanks for reporting the issue to us!

@lilgreenbird lilgreenbird added Enhancement An enhancement to the driver. Lower priority than bugs. and removed Question Used when a question is asked, as opposed to an issue being raised labels Jun 10, 2024
@Jeffery-Wasty Jeffery-Wasty added the Documentation Pull requests that update documentation label Jun 11, 2024
@lilgreenbird lilgreenbird added the Backlog The topic in question has been recognized and added to development backlog label Jun 19, 2024
@typhoon2k
Copy link

Facing the same issue. It's a blocker for implementing data transfer pipelines into tables having SQL Variant columns.

@Jeffery-Wasty
Copy link
Contributor

Jeffery-Wasty commented Jul 30, 2024

Docs will be updated for 12.8 (07/31/24).

@Jeffery-Wasty Jeffery-Wasty removed the Documentation Pull requests that update documentation label Jul 30, 2024
@github-project-automation github-project-automation bot moved this to Backlog in MSSQL JDBC Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog The topic in question has been recognized and added to development backlog Enhancement An enhancement to the driver. Lower priority than bugs.
Projects
Status: Backlog
Development

No branches or pull requests

4 participants