-
Notifications
You must be signed in to change notification settings - Fork 0
How to enable Bulk Copy API for batch insert operations
Using Bulk Copy API for batch insert operations is supported starting from JDBC driver preview release 6.5.4. This feature allows the users to utilize Bulk Copy API underneath when executing batch insert operations against Azure Data Warehouses, and improves the performance significantly. This feature aims to achieve the performance improvement while inserting the same data as it would have with regular batch insert operation. This page shows various use cases with batch insert using Bulk Copy API, as well as its limitations.
There are two prerequisites to enable Bulk Copy API for batch insert.
- The server must be Azure Data Warehouse.
- The query must be an insert query (the query may contain comments, but the query must start with the INSERT keyword for this feature to come into effect).
There are two ways to enable Bulk Copy API for batch insert.
Adding useBulkCopyForBatchInsert=true; to the connection string enables this feature.
connection = DriverManager.getConnection("jdbc:sqlserver://localhost;userName=user;password=password;database=test;useBulkCopyForBatchInsert=true;");
Calling SQLServerConnection.setUseBulkCopyForBatchInsert(true) enables this feature.
SQLServerConnection.getUseBulkCopyForBatchInsert() retrieves the current value for **useBulkCopyForBatchInsert **connection property.
There are currently these limitations that apply to this feature.
- The insert query cannot contain INSERT-SELECT queries (e.g. INSERT INTO TABLE SELECT * FROM TABLE2).
- The insert query cannot contain multiple VALUE expressions (e.g. INSERT INTO TABLE VALUES (1, 2) (3, 4))
- The insert query cannot be followed by the OPTION clause, or be joined with other queries that are not part of the INSERT query.
If the query fails due to non-SQL server related errors, the driver will log the error message and fallback to the original logic for batch insert.