You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -217,32 +231,32 @@ class InsertHandler implements Closeable {
217
231
preparedStatement.clearParameters()
218
232
// invoke the operation closure with setup the statement params
219
233
operation.call(preparedStatement)
220
-
// add to current batch
221
-
preparedStatement.addBatch()
222
-
// if the batch size is reached, perform the batch statement
223
-
if( ++batchCount == batchSize ) {
234
+
// when the batchSize is one, execute directly (without adding to a batch)
235
+
if( batchSize==1 ) {
224
236
try {
225
-
preparedStatement.executeBatch()
226
-
preparedStatement.clearBatch()
237
+
preparedStatement.execute()
238
+
}
239
+
finally {
240
+
tryCommit(connection)
227
241
}
228
-
catch(UnsupportedOperationException e) {
229
-
log.debug "executeBatch is not supported by this driver (likely Databricks), executing statements individually: ${e.message}"
230
-
// Fallback: execute each statement individually
242
+
}
243
+
else {
244
+
// add to current batch
245
+
preparedStatement.addBatch()
246
+
// if the batch size is not reached, just return
247
+
if( ++batchCount < batchSize ) {
248
+
return
249
+
}
250
+
// otherwise, if the batch is full perform the batch statement
251
+
try {
252
+
preparedStatement.executeBatch()
231
253
preparedStatement.clearBatch()
232
-
// We need to re-add and execute each statement individually
233
-
// This is a limitation - we lose the current batch, but at least we don't silently fail
234
-
thrownewRuntimeException("Batch execution not supported by driver. Consider setting batchSize=1 for this database type.", e)
235
254
}
236
255
finally {
237
256
// reset the current batch count
238
257
batchCount =0
239
258
// make sure to commit the current batch
240
-
try {
241
-
connection.commit()
242
-
}
243
-
catch(UnsupportedOperationException e) {
244
-
log.debug "commit is not supported by this driver (likely Databricks), continuing: ${e.message}"
245
-
}
259
+
connection.commit()
246
260
}
247
261
}
248
262
}
@@ -281,32 +295,15 @@ class InsertHandler implements Closeable {
281
295
try {
282
296
if( preparedStatement && batchCount>0 ) {
283
297
log.debug("[SQL] flushing and committing open batch")
284
-
try {
285
-
preparedStatement.executeBatch()
286
-
}
287
-
catch(UnsupportedOperationException e) {
288
-
log.warn "executeBatch is not supported by this driver (likely Databricks). Remaining ${batchCount} statements were not executed. Consider using batchSize=1 for this database type."
0 commit comments