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
fix: Improve error handling and logging for unsupported database operations
- Enhanced the InsertHandler to provide fallbacks for unsupported operations like setObject and executeBatch, specifically for drivers such as Databricks.
- Added detailed logging to inform users when operations are skipped or when fallbacks are attempted, improving debuggability.
- Ensured that exceptions are thrown with clear messages when both primary and fallback methods fail, preventing silent failures.
#30 (comment)
Co-authored-by: Paolo Di Tommaso <[email protected]>
Signed-off-by: Edmund Miller <[email protected]>
Copy file name to clipboardExpand all lines: plugins/nf-sqldb/src/main/nextflow/sql/InsertHandler.groovy
+28-19Lines changed: 28 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -169,10 +169,14 @@ class InsertHandler implements Closeable {
169
169
stm.setObject(i+1, value)
170
170
}
171
171
catch(UnsupportedOperationException e) {
172
-
log.debug "setObject is not supported by this driver (likely Databricks), skipping value: ${e.message}"
173
-
}
174
-
catch(Exception e) {
175
-
log.debug "Database does not support setObject, skipping value: ${e.message}"
172
+
log.debug "setObject is not supported by this driver (likely Databricks), trying setString fallback: ${e.message}"
173
+
// Fallback to setString for basic types
174
+
try {
175
+
stm.setString(i+1, value?.toString())
176
+
}
177
+
catch(Exception fallbackError) {
178
+
thrownewRuntimeException("Failed to set parameter ${i+1} with value '${value}': both setObject and setString failed", fallbackError)
179
+
}
176
180
}
177
181
}
178
182
// report a debug line
@@ -189,10 +193,14 @@ class InsertHandler implements Closeable {
189
193
stm.setObject(i+1, value)
190
194
}
191
195
catch(UnsupportedOperationException e) {
192
-
log.debug "setObject is not supported by this driver (likely Databricks), skipping value: ${e.message}"
193
-
}
194
-
catch(Exception e) {
195
-
log.debug "Database does not support setObject, skipping value: ${e.message}"
196
+
log.debug "setObject is not supported by this driver (likely Databricks), trying setString fallback: ${e.message}"
197
+
// Fallback to setString for basic types
198
+
try {
199
+
stm.setString(i+1, value?.toString())
200
+
}
201
+
catch(Exception fallbackError) {
202
+
thrownewRuntimeException("Failed to set parameter ${i+1} with value '${value}': both setObject and setString failed", fallbackError)
203
+
}
196
204
}
197
205
}
198
206
// report a debug line
@@ -217,6 +225,14 @@ class InsertHandler implements Closeable {
217
225
preparedStatement.executeBatch()
218
226
preparedStatement.clearBatch()
219
227
}
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
231
+
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
+
}
220
236
finally {
221
237
// reset the current batch count
222
238
batchCount =0
@@ -227,9 +243,6 @@ class InsertHandler implements Closeable {
227
243
catch(UnsupportedOperationException e) {
228
244
log.debug "commit is not supported by this driver (likely Databricks), continuing: ${e.message}"
229
245
}
230
-
catch(Exception e) {
231
-
log.debug "Database does not support commit, continuing with default behavior: ${e.message}"
232
-
}
233
246
}
234
247
}
235
248
}
@@ -272,26 +285,22 @@ class InsertHandler implements Closeable {
272
285
preparedStatement.executeBatch()
273
286
}
274
287
catch(UnsupportedOperationException e) {
275
-
log.debug "executeBatch is not supported by this driver (likely Databricks), continuing: ${e.message}"
276
-
}
277
-
catch(Exception e) {
278
-
log.debug "Database does not support executeBatch, continuing with default behavior: ${e.message}"
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."
289
+
// Clear the batch to prevent inconsistent state
290
+
preparedStatement.clearBatch()
279
291
}
280
292
try {
281
293
preparedStatement.close()
282
294
}
283
295
catch(Exception e) {
284
-
log.debug "Database does not support preparedStatement.close(), continuing: ${e.message}"
0 commit comments