Skip to content

Commit 53989bb

Browse files
authored
Add support for Stored Procedures in JDBC driver (Phase 1) (#1051)
## Description <!-- Provide a brief summary of the changes made and the issue they aim to address.--> This PR introduces phase 1 of stored procedure support in the Databricks JDBC driver. The driver now supports executing CALL statements that invoke stored procedures on the server. Key Capabilities - ✅ Supports CALL syntax for stored procedure execution (e.g., CALL my_proc(?, ?)). - ✅ Supports input parameters, which can be set using standard JDBC APIs (setInt, setString, etc.). - ⚙️ Output parameters are currently supported only via SQL scripting (e.g., procedures returning results via SELECT statements or variables assigned inside scripts). - 🚧 This is phase 1 — additional support for true OUT/INOUT parameters will be introduced in a future phase (full fledged support using CallableStatement.) ## Testing <!-- Describe how the changes have been tested--> Tested using unit tests, will also test manually. ## 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. -->
1 parent 25552de commit 53989bb

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Note: Large batches are chunked for execution. If a chunk fails, previous chunks remain committed (no transaction rollback). Consider using staging tables for critical workflows.
1414
- Added a new config attribute `DisableOauthRefreshToken` to control whether refresh tokens are requested in OAuth exchanges. By default, the driver does not include the `offline_access` scope. If `offline_access` is explicitly provided by the user, it is preserved and not removed.
1515
- Added Feature-flag integration for SQL Exec API rollout
16+
- Call statements will return result sets in response
1617

1718
### Updated
1819
- Minimized OAuth requests by reducing calls in feature flags and telemetry.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ static boolean shouldReturnResultSet(String query) {
695695
|| GET_PATTERN.matcher(trimmedQuery).find()
696696
|| REMOVE_PATTERN.matcher(trimmedQuery).find()
697697
|| LIST_PATTERN.matcher(trimmedQuery).find()
698-
|| BEGIN_PATTERN_FOR_SQL_SCRIPT.matcher(trimmedQuery).find();
698+
|| BEGIN_PATTERN_FOR_SQL_SCRIPT.matcher(trimmedQuery).find()
699+
|| CALL_PATTERN.matcher(trimmedQuery).find();
699700

700701
// Otherwise, it should not return a ResultSet
701702
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,17 @@ public enum FakeServiceType {
159159
public static final Pattern DECLARE_PATTERN =
160160
Pattern.compile("^(\\s*\\()*\\s*DECLARE", Pattern.CASE_INSENSITIVE);
161161
public static final Pattern PUT_PATTERN =
162-
Pattern.compile("^(\\s*\\()*\\s*GET", Pattern.CASE_INSENSITIVE);
163-
public static final Pattern GET_PATTERN =
164162
Pattern.compile("^(\\s*\\()*\\s*PUT", Pattern.CASE_INSENSITIVE);
163+
public static final Pattern GET_PATTERN =
164+
Pattern.compile("^(\\s*\\()*\\s*GET", Pattern.CASE_INSENSITIVE);
165165
public static final Pattern REMOVE_PATTERN =
166166
Pattern.compile("^(\\s*\\()*\\s*REMOVE", Pattern.CASE_INSENSITIVE);
167167
public static final Pattern LIST_PATTERN =
168168
Pattern.compile("^(\\s*\\()*\\s*LIST", Pattern.CASE_INSENSITIVE);
169169
public static final Pattern INSERT_PATTERN =
170170
Pattern.compile("^(\\s*\\()*\\s*INSERT\\s+INTO", Pattern.CASE_INSENSITIVE);
171+
public static final Pattern CALL_PATTERN =
172+
Pattern.compile("^(\\s*\\()*\\s*CALL", Pattern.CASE_INSENSITIVE);
171173

172174
/** Maximum number of parameters allowed in a single Databricks query */
173175
public static final int MAX_QUERY_PARAMETERS = 256;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,14 @@ public void testShouldReturnResultSet_CommentSurroundingQuery() {
675675
assertTrue(DatabricksStatement.shouldReturnResultSet(query));
676676
}
677677

678+
@Test
679+
public void testShouldReturnResultSet_CallStatement() {
680+
String query =
681+
"-- Single-line comment\n/* Multi-line comment */ CALL send_notifications(12); /* Another comment */ -- End comment";
682+
assertTrue(DatabricksStatement.shouldReturnResultSet(query));
683+
assertTrue(DatabricksStatement.shouldReturnResultSet("CALL send_notifications(12);"));
684+
}
685+
678686
@Test
679687
public void testShouldReturnResultSet_StartWithBegin() {
680688
assertTrue(DatabricksStatement.shouldReturnResultSet("BEGIN"));

0 commit comments

Comments
 (0)