Skip to content

Add NonRowcountQueryPrefixes configuration parameter - #1189

Merged
gopalldb merged 5 commits into
mainfrom
prefix-flag
Jan 30, 2026
Merged

gopalldb merged 5 commits into
mainfrom
prefix-flag

Conversation

@gopalldb

Copy link
Copy Markdown
Collaborator

Description

Implements NonRowcountQueryPrefixes flag to match exiting JDBC driver behavior. This allows users to specify comma-separated query prefixes (like INSERT, UPDATE, DELETE) that should return result sets instead of row counts.

Changes:

  • Added NON_ROWCOUNT_QUERY_PREFIXES parameter to DatabricksJdbcUrlParams
  • Added getNonRowcountQueryPrefixes() method to connection context interface and implementation
  • Updated shouldReturnResultSet() logic to check configured prefixes before SQL patterns
  • Added 11 comprehensive unit tests covering various scenarios
  • Updated NEXT_CHANGELOG.md with feature description

Usage:
NonRowcountQueryPrefixes=INSERT,UPDATE,DELETE,MERGE

Testing

Tests: All 75 tests pass (64 existing + 11 new)

Additional Notes to the Reviewer

Implements NonRowcountQueryPrefixes flag to match Simba JDBC driver behavior.
This allows users to specify comma-separated query prefixes (like INSERT, UPDATE, DELETE)
that should return result sets instead of row counts.

Changes:
- Added NON_ROWCOUNT_QUERY_PREFIXES parameter to DatabricksJdbcUrlParams
- Added getNonRowcountQueryPrefixes() method to connection context interface and implementation
- Updated shouldReturnResultSet() logic to check configured prefixes before SQL patterns
- Added 11 comprehensive unit tests covering various scenarios
- Updated NEXT_CHANGELOG.md with feature description

Usage:
NonRowcountQueryPrefixes=INSERT,UPDATE,DELETE,MERGE

Tests: All 75 tests pass (64 existing + 11 new)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Comment on lines +694 to +699
String upperQuery = trimmedQuery.toUpperCase();
for (String prefix : nonRowcountQueryPrefixes) {
if (upperQuery.startsWith(prefix)) {
return true;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a simple lambda to write this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

String prefixesStr = getParameter(DatabricksJdbcUrlParams.NON_ROWCOUNT_QUERY_PREFIXES);
if (prefixesStr == null || prefixesStr.trim().isEmpty()) {
return Collections.emptyList();
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will actually never be null because default value is empty? and empty condition will be handled by the lambda below

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

String trimmedQuery = trimCommentsAndWhitespaces(query);

// Check configured non-rowcount prefixes first
if (nonRowcountQueryPrefixes != null && !nonRowcountQueryPrefixes.isEmpty()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have this null and empty check? it can never be null and empty is implicitly handled

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

gopalldb and others added 3 commits January 29, 2026 18:51
Removed the single-parameter static method shouldReturnResultSet(String)
in favor of requiring callers to explicitly pass the list of
non-rowcount query prefixes. This improves code clarity by making the
prefix configuration explicit at all call sites.

Updated all test cases to pass Collections.emptyList() or specific
prefix lists (INSERT, UPDATE, DELETE) as appropriate. Enhanced UPDATE
and DELETE tests to verify behavior both with and without configured
prefixes.

All 75 tests passing.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- Use lambda/stream for prefix matching instead of explicit loop
- Remove unnecessary null/empty checks in getNonRowcountQueryPrefixes()
  since default value is empty string and filter handles empty strings
- Remove null test case as the method is only called from connection
  context which always returns a non-null list

All 74 tests passing.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>

@sreekanth-db sreekanth-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the tests we have seems to be focused on the functionality of shouldReturnResultSet and shouldReturnResultSetWithConfig. Can we also add an e2e test (or a fake service test) to test the end user behaviour ?

@sreekanth-db

Copy link
Copy Markdown
Collaborator

All the tests we have seems to be focused on the functionality of shouldReturnResultSet and shouldReturnResultSetWithConfig. Can we also add an e2e test (or a fake service test) to test the end user behaviour ?

or we can just cover it in unit tests for execute / executeQuery methods

Added two unit tests to verify execute() method behavior:
1. testExecuteInsertWithNonRowcountQueryPrefixes - verifies INSERT
   returns result set when NonRowcountQueryPrefixes=INSERT
2. testExecuteInsertWithoutNonRowcountQueryPrefixes - verifies INSERT
   returns update count (not result set) without prefix configuration

These tests demonstrate end-to-end behavior of the configuration
parameter through the Statement.execute() API.

All 76 tests passing (74 original + 2 new).

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@gopalldb

Copy link
Copy Markdown
Collaborator Author

All the tests we have seems to be focused on the functionality of shouldReturnResultSet and shouldReturnResultSetWithConfig. Can we also add an e2e test (or a fake service test) to test the end user behaviour ?

or we can just cover it in unit tests for execute / executeQuery methods

done

@gopalldb
gopalldb merged commit 8aed472 into main Jan 30, 2026
12 of 13 checks passed
@gopalldb
gopalldb deleted the prefix-flag branch January 30, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants