From 32ce6630be2a449ab149053803b8d16e9406afdb Mon Sep 17 00:00:00 2001 From: Sreekanth Vadigi Date: Wed, 17 Jun 2026 10:34:16 +0000 Subject: [PATCH] Fix supportsBatchUpdates() to honor EnableBatchedInserts DatabricksDatabaseMetaData.supportsBatchUpdates() was hard-coded to return false. Batch-aware JDBC clients (e.g. Apache Hop) call this method before batching; seeing false, they never call executeBatch() and fall back to one executeUpdate() per row, so the multi-row INSERT optimization gated by EnableBatchedInserts never runs. Return true when EnableBatchedInserts=1 so those clients use the optimized executeBatch() path. Default behavior is unchanged (flag off -> false). Mirrors the existing context-driven supportsTransactions(). Signed-off-by: Sreekanth Vadigi --- NEXT_CHANGELOG.md | 1 + .../jdbc/api/impl/DatabricksDatabaseMetaData.java | 4 +++- .../api/impl/DatabricksDatabaseMetaDataTest.java | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index a972de65e..3abd63e88 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -10,6 +10,7 @@ - Fixed `setCatalog()` and `setSchema()` producing invalid SQL (e.g. `SET CATALOG ``name``) when the catalog or schema name was passed already wrapped in backticks. Backticks are now stripped before wrapping, and `getCatalog()`/`getSchema()` return the bare identifier name. - Fixed metadata SQL generation for catalog, schema, and table identifiers containing backticks. - Fixed SEA result truncation when direct results are disabled. Large, highly-compressible results that span multiple chunks were delivered inline via the old hybrid path and truncated to the first chunk. The SQL Execution path now uses an async (`0s`) wait timeout when direct results are disabled, so results are returned via external links and fetched in full. +- Fixed `DatabricksDatabaseMetaData.supportsBatchUpdates()` always returning `false`, which caused batch-aware JDBC clients (e.g. Apache Hop) to skip `executeBatch()` and fall back to one INSERT per row. It now returns `true` when `EnableBatchedInserts=1`, so those clients use the optimized multi-row INSERT path. --- *Note: When making changes, please add your change under the appropriate section diff --git a/src/main/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaData.java b/src/main/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaData.java index a53b228c7..f86f44058 100644 --- a/src/main/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaData.java +++ b/src/main/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaData.java @@ -1278,7 +1278,9 @@ public boolean insertsAreDetected(int type) throws SQLException { public boolean supportsBatchUpdates() throws SQLException { LOGGER.debug("public boolean supportsBatchUpdates()"); throwExceptionIfConnectionIsClosed(); - return false; + // Advertise batch support only when the multi-row INSERT optimization is enabled, so + // batch-aware clients use executeBatch() instead of one executeUpdate() per row. + return session.getConnectionContext().isBatchedInsertsEnabled(); } @Override diff --git a/src/test/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaDataTest.java b/src/test/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaDataTest.java index b7c03bb85..303cb4fb4 100644 --- a/src/test/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaDataTest.java +++ b/src/test/java/com/databricks/jdbc/api/impl/DatabricksDatabaseMetaDataTest.java @@ -95,11 +95,21 @@ public void getDatabaseProductName_throwsExceptionWhenConnectionIsClosed() throw } @Test - public void supportsBatchUpdates_returnsFalse() throws Exception { + public void supportsBatchUpdates_returnsFalseByDefault() throws Exception { + // Default EnableBatchedInserts=0, so batch support is not advertised boolean supportsBatchUpdates = metaData.supportsBatchUpdates(); assertFalse(supportsBatchUpdates); } + @Test + public void supportsBatchUpdates_returnsTrueWhenBatchedInsertsEnabled() throws Exception { + String urlWithBatchedInserts = WAREHOUSE_JDBC_URL + ";EnableBatchedInserts=1"; + when(session.getConnectionContext()) + .thenReturn(DatabricksConnectionContext.parse(urlWithBatchedInserts, new Properties())); + boolean supportsBatchUpdates = metaData.supportsBatchUpdates(); + assertTrue(supportsBatchUpdates); + } + @Test public void getDatabaseMajorVersion_returnsCorrectVersion() throws Exception { int majorVersion = metaData.getDatabaseMajorVersion();