Skip to content

Commit 5b9f54f

Browse files
authored
Added connection param of ignore transactions that allows users to mu… (#1026)
## Description <!-- Provide a brief summary of the changes made and the issue they aim to address.--> Allows user to mute the exceptions for transaction related methods. Earlier the driver was throwing an exception for transaction related methods. Now the users can use the parameter to ignore these exceptions for transaction methods. ## Testing <!-- Describe how the changes have been tested--> Unit tests added. ## Additional Notes to the Reviewer <!-- Share any additional context or insights that may help the reviewer understand the changes better. This could include challenges faced, limitations, or compromises made during the development process. Also, mention any areas of the code that you would like the reviewer to focus on specifically. --> [PECOBLR-931](https://databricks.atlassian.net/browse/PECOBLR-931) [PECOBLR-931]: https://databricks.atlassian.net/browse/PECOBLR-931?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Fixes #1005
1 parent 573d656 commit 5b9f54f

6 files changed

Lines changed: 90 additions & 16 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Updated
88
- Telemetry data is now captured more efficiently and consistently due to enhancements in the log and connection close flush logic.
99
- Updated Databricks SDK version to v0.65.0 (This is to fix OAuthClient to properly encode complex query parameters.)
10+
- Added IgnoreTransactions connection parameter to silently ignore transaction method calls.
1011

1112
### Fixed
1213
- Fixed state leaking issue in thrift client.

src/main/java/com/databricks/jdbc/api/impl/DatabricksConnection.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,11 @@ public String nativeSQL(String sql) throws SQLException {
120120
@Override
121121
public void setAutoCommit(boolean autoCommit) throws SQLException {
122122
if (!autoCommit) {
123-
throw new DatabricksSQLFeatureNotSupportedException(
124-
"In Databricks OSS JDBC, every SQL statement is committed immediately upon execution."
125-
+ " Setting autoCommit=false is not supported.");
123+
if (!connectionContext.getIgnoreTransactions()) {
124+
throw new DatabricksSQLFeatureNotSupportedException(
125+
"In Databricks OSS JDBC, every SQL statement is committed immediately upon execution."
126+
+ " Setting autoCommit=false is not supported.");
127+
}
126128
}
127129
}
128130

@@ -136,15 +138,19 @@ public boolean getAutoCommit() throws SQLException {
136138
@Override
137139
public void commit() throws SQLException {
138140
LOGGER.debug("public void commit()");
139-
throw new DatabricksSQLFeatureNotImplementedException(
140-
"Not implemented in DatabricksConnection - commit()");
141+
if (!connectionContext.getIgnoreTransactions()) {
142+
throw new DatabricksSQLFeatureNotImplementedException(
143+
"Not implemented in DatabricksConnection - commit()");
144+
}
141145
}
142146

143147
@Override
144148
public void rollback() throws SQLException {
145149
LOGGER.debug("public void rollback()");
146-
throw new DatabricksSQLFeatureNotImplementedException(
147-
"Not implemented in DatabricksConnection - rollback()");
150+
if (!connectionContext.getIgnoreTransactions()) {
151+
throw new DatabricksSQLFeatureNotImplementedException(
152+
"Not implemented in DatabricksConnection - rollback()");
153+
}
148154
}
149155

150156
@Override
@@ -299,28 +305,39 @@ public int getHoldability() throws SQLException {
299305
@Override
300306
public Savepoint setSavepoint() throws SQLException {
301307
LOGGER.debug("public Savepoint setSavepoint()");
302-
throw new DatabricksSQLFeatureNotImplementedException(
303-
"Not implemented in DatabricksConnection - setSavepoint()");
308+
if (!connectionContext.getIgnoreTransactions()) {
309+
throw new DatabricksSQLFeatureNotImplementedException(
310+
"Not implemented in DatabricksConnection - setSavepoint()");
311+
}
312+
return null;
304313
}
305314

306315
@Override
307316
public Savepoint setSavepoint(String name) throws SQLException {
308-
throw new DatabricksSQLFeatureNotImplementedException(
309-
"Not implemented in DatabricksConnection - setSavepoint(String name)");
317+
LOGGER.debug("public Savepoint setSavepoint(String name = {})", name);
318+
if (!connectionContext.getIgnoreTransactions()) {
319+
throw new DatabricksSQLFeatureNotImplementedException(
320+
"Not implemented in DatabricksConnection - setSavepoint(String name)");
321+
}
322+
return null;
310323
}
311324

312325
@Override
313326
public void rollback(Savepoint savepoint) throws SQLException {
314327
LOGGER.debug("public void rollback(Savepoint savepoint)");
315-
throw new DatabricksSQLFeatureNotImplementedException(
316-
"Not implemented in DatabricksConnection - rollback(Savepoint savepoint)");
328+
if (!connectionContext.getIgnoreTransactions()) {
329+
throw new DatabricksSQLFeatureNotImplementedException(
330+
"Not implemented in DatabricksConnection - rollback(Savepoint savepoint)");
331+
}
317332
}
318333

319334
@Override
320335
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
321336
LOGGER.debug("public void releaseSavepoint(Savepoint savepoint)");
322-
throw new DatabricksSQLFeatureNotImplementedException(
323-
"Not implemented in DatabricksConnection - releaseSavepoint(Savepoint savepoint)");
337+
if (!connectionContext.getIgnoreTransactions()) {
338+
throw new DatabricksSQLFeatureNotImplementedException(
339+
"Not implemented in DatabricksConnection - releaseSavepoint(Savepoint savepoint)");
340+
}
324341
}
325342

326343
@Override

src/main/java/com/databricks/jdbc/api/impl/DatabricksConnectionContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,4 +1045,9 @@ public int getTelemetryFlushIntervalInMilliseconds() {
10451045
public boolean isBatchedInsertsEnabled() {
10461046
return getParameter(DatabricksJdbcUrlParams.ENABLE_BATCHED_INSERTS).equals("1");
10471047
}
1048+
1049+
@Override
1050+
public boolean getIgnoreTransactions() {
1051+
return getParameter(DatabricksJdbcUrlParams.IGNORE_TRANSACTIONS, "0").equals("1");
1052+
}
10481053
}

src/main/java/com/databricks/jdbc/api/internal/IDatabricksConnectionContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,4 +368,7 @@ public interface IDatabricksConnectionContext {
368368

369369
/** Returns whether batched INSERT optimization is enabled */
370370
boolean isBatchedInsertsEnabled();
371+
372+
/** Returns whether transaction-related method calls should be ignored */
373+
boolean getIgnoreTransactions();
371374
}

src/main/java/com/databricks/jdbc/common/DatabricksJdbcUrlParams.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ public enum DatabricksJdbcUrlParams {
162162
ENABLE_SQL_VALIDATION_FOR_IS_VALID(
163163
"EnableSQLValidationForIsValid",
164164
"Enable SQL query execution for connection validation in isValid() method",
165-
"0");
165+
"0"),
166+
IGNORE_TRANSACTIONS("IgnoreTransactions", "Ignore transaction-related method calls", "0");
166167

167168
private final String paramName;
168169
private final String defaultValue;

src/test/java/com/databricks/jdbc/api/impl/DatabricksConnectionTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class DatabricksConnectionTest {
5959
SESSION_CONFIGS.entrySet().stream()
6060
.map(e -> e.getKey() + "=" + e.getValue())
6161
.collect(Collectors.joining(";")));
62+
private static final String IGNORE_TRANSACTIONS_JDBC_URL =
63+
"jdbc:databricks://sample-host.18.azuredatabricks.net:4423/default;transportMode=http;ssl=1;AuthMech=3;httpPath=/sql/1.0/warehouses/99999999;IgnoreTransactions=1";
6264
private static final ImmutableSessionInfo IMMUTABLE_SESSION_INFO =
6365
ImmutableSessionInfo.builder().computeResource(warehouse).sessionId(SESSION_ID).build();
6466
@Mock DatabricksSdkClient databricksClient;
@@ -517,4 +519,49 @@ public void testIsValidWithSQLValidationEnabled() throws SQLException {
517519

518520
connection.close();
519521
}
522+
523+
@Test
524+
public void testIgnoreTransactionsDisabled() throws Exception {
525+
when(databricksClient.createSession(
526+
new Warehouse(WAREHOUSE_ID), null, DEFAULT_SCHEMA, new HashMap<>()))
527+
.thenReturn(IMMUTABLE_SESSION_INFO);
528+
529+
IDatabricksConnectionContext context =
530+
DatabricksConnectionContext.parse(JDBC_URL, new Properties());
531+
connection = new DatabricksConnection(context, databricksClient);
532+
connection.open();
533+
534+
assertFalse(context.getIgnoreTransactions());
535+
536+
assertThrows(
537+
DatabricksSQLFeatureNotSupportedException.class, () -> connection.setAutoCommit(false));
538+
assertThrows(DatabricksSQLFeatureNotImplementedException.class, () -> connection.commit());
539+
assertThrows(
540+
DatabricksSQLFeatureNotImplementedException.class, () -> connection.setSavepoint());
541+
542+
connection.close();
543+
}
544+
545+
@Test
546+
public void testIgnoreTransactionsEnabled() throws Exception {
547+
when(databricksClient.createSession(
548+
new Warehouse(WAREHOUSE_ID), null, DEFAULT_SCHEMA, new HashMap<>()))
549+
.thenReturn(IMMUTABLE_SESSION_INFO);
550+
551+
IDatabricksConnectionContext context =
552+
DatabricksConnectionContext.parse(IGNORE_TRANSACTIONS_JDBC_URL, new Properties());
553+
connection = new DatabricksConnection(context, databricksClient);
554+
connection.open();
555+
556+
assertTrue(context.getIgnoreTransactions());
557+
558+
assertDoesNotThrow(() -> connection.setAutoCommit(false));
559+
assertDoesNotThrow(() -> connection.commit());
560+
assertDoesNotThrow(() -> connection.rollback());
561+
562+
assertNull(connection.setSavepoint());
563+
assertNull(connection.setSavepoint("test"));
564+
565+
connection.close();
566+
}
520567
}

0 commit comments

Comments
 (0)