Skip to content

[PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows - #765

Merged
shivam2680 merged 15 commits into
mainfrom
shivam2680/rows-fetched-per-block
Apr 1, 2025
Merged

shivam2680 merged 15 commits into
mainfrom
shivam2680/rows-fetched-per-block

Conversation

@shivam2680

@shivam2680 shivam2680 commented Mar 24, 2025 •

Copy link
Copy Markdown
Collaborator

Description

add url param RowsFetchedPerBlock. This param is set to maxRows in thrift execute statement request.
Usage doc

Fixed Statement setMaxRows in thrift client. Added resultRowLimit parameter to TExecuteStatementReq

Testing

Additional Notes to the Reviewer

@shivam2680
shivam2680 requested a review from Copilot March 24, 2025 18:25
@shivam2680 shivam2680 self-assigned this Mar 24, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for a configurable row fetch limit in Thrift inline mode by introducing a new URL parameter "RowsFetchedPerBlock".

  • Adds an example test method in DatabricksDriverExamples.java to showcase the new parameter usage.
  • Introduces the ROWS_FETCHED_PER_BLOCK enum along with a corresponding getter in DatabricksConnectionContext and new method signature in IDatabricksConnectionContext.
  • Updates DatabricksThriftAccessor.java and its tests to use the new parameter instead of the legacy maxRows value.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/test/java/com/databricks/client/jdbc/DatabricksDriverExamples.java Added test method demonstrating usage of RowsFetchedPerBlock
src/main/java/com/databricks/jdbc/api/impl/DatabricksConnectionContext.java Added getRowsFetchedPerBlock() method to extract the new parameter
src/main/java/com/databricks/jdbc/common/DatabricksJdbcUrlParams.java Added new enum value ROWS_FETCHED_PER_BLOCK
src/main/java/com/databricks/jdbc/api/IDatabricksConnectionContext.java Added method signature for getRowsFetchedPerBlock()
src/main/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftAccessor.java Integrated new row fetch limit parameter into direct result fetching logic
src/test/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftAccessorTest.java Removed legacy maxRows mocking and updated tests accordingly
Comments suppressed due to low confidence (2)

src/test/java/com/databricks/client/jdbc/DatabricksDriverExamples.java:132

  • The concatenated URL string appears to be missing a delimiter before 'RowsFetchedPerBlock=3'. Consider adding a semicolon before it (e.g., ";RowsFetchedPerBlock=3") to ensure proper URL parameter separation.
String jdbcUrl = JDBC_URL_WAREHOUSE + "EnableTelemetry=1" + ";enableArrow=0" + "RowsFetchedPerBlock=3";

src/main/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftAccessor.java:42

  • [nitpick] The variable name 'max_row_per_block' does not follow standard Java camelCase naming conventions. Consider renaming it to 'maxRowPerBlock' for consistency.
private int max_row_per_block = DEFAULT_ROW_LIMIT;

@shivam2680 shivam2680 changed the title add support for configurable row fetch limit in thrift inline [PECOBLR-161] add support for configurable row fetch limit in thrift inline Mar 24, 2025
@shivam2680
shivam2680 marked this pull request as ready for review March 25, 2025 08:24
@shivam2680 shivam2680 changed the title [PECOBLR-161] add support for configurable row fetch limit in thrift inline [PECOBLR-161] add support for configurable row fetch limit in thrift inline and fix setMaxRows Mar 28, 2025
@shivam2680 shivam2680 changed the title [PECOBLR-161][PECO-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows [PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows Mar 28, 2025
@shivam2680
shivam2680 requested a review from gopalldb March 28, 2025 09:46
.setUseArrowNativeTypes(arrowNativeTypes);

if (parentStatement.getMaxRows()
!= DEFAULT_ROW_LIMIT) { // set request param only if user has set maxRows. Similar behavior

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.

shall we say

maxRows > 0 && maxRows != Default

@shivam2680 shivam2680 Mar 28, 2025 •

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.

No
maxRows = 0 is also allowed, that returns empty result set. verified with legacy driver and sdk flow result also.
And a checkIfNegative() function is called to throw error in case of negative input in Statement.setMaxRows


@Override
public int getRowsFetchedPerBlock() {
int maxRows = DEFAULT_ROW_LIMIT;

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 are there multiple defaults? this one through env variable and 2000000 from UrlParams?

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.

Both are same values.
This way we fallback to default value in case user passes invalid value in url param

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.

in case user provides invalid value, why not just fall back to the default value provided in UrlParams, why have this extra constant DEFAULT_ROW_LIMIT? i feel like this is confusing... let's try to simplify this. This is also used in other places like the comment below i.e. statementMaxRows != DEFAULT_ROW_LIMIT, let's try to simplify if possible by making this statementMaxRows.isDefined or something along those lines.

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.

Doesn't seem to be confusing at all.
I can maybe add a new constant for default statement max row limit to make it more clear. The main problem i sense here is doing both tasks in the same PR.

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.

yeah could be, would be helpful if we can separate the constant being used for the two (one can just be equal to the other)

also, would still recommend just using one default for rowsFetchPerBlock.. but leave it up to your discretion.

if (statementMaxRows != DEFAULT_ROW_LIMIT && rows.size() > statementMaxRows) {
rows = rows.subList(0, statementMaxRows);
}
}

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.

should we break while (resultsResp.hasMoreRows) if rows.size() > statementMaxRows?

@shivam2680 shivam2680 Mar 28, 2025 •

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.

I agree that this might be an added optimization, but i feel the subList call is inevitable.
What's happening here is first rows will have x rows (from initial fetch), then inside while loop certain y(changes every iter) number of rows will get added. So, to trim at exactly maxRows, we have to apply subList. I feel the current implementation is less performant but it's correct and easy to read. And is triggered only if client explicitly sets maxRows in statement.

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.

I think we should fix this. Consider if client sets maxRows to really low value, and there are millions of rows in result. We can at least stop processing once we have extracted required rows.

I am okay to do this in separate PR.

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.

added this.

if (enableDirectResults) {
// if getDirectResults.maxRows > 0, the server will immediately call FetchResults. Fetch
// initial rows limited by maxRows.
// if = 0, server does not call FetchResults.

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 is just FYI right?

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.

yes

if (parentStatement.getMaxRows()
!= DEFAULT_ROW_LIMIT) { // set request param only if user has set maxRows. Similar behavior
// to SEA flow
request.setResultRowLimit(parentStatement.getMaxRows());

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.

should we rename the function IDatabricksStatementInternal#getMaxRows? I'm getting confused between maxRowsPerBlock and resultRowLimit (maybe because both are being changed in the same PR), would be good to rename variables/functions so that it is always clear in code

@shivam2680 shivam2680 Mar 28, 2025 •

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.

I do not think we should change the function name. java.sql.Statement interface has function getMaxRows, we should align
To clarify, these changes are done in same PR because they are dependent. For thrift client, had to update the value that we pass in maxRows param. Earlier it was parentStatement.getMaxRows().

@gopalldb gopalldb 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.

Mostly LG. Have a comment on further optimizing on max rows in the while(hasMoreRows).

ROWS_FETCHED_PER_BLOCK(
"RowsFetchedPerBlock",
"The maximum number of rows that a query returns at a time.",
"2000000"), // works only for inline results.

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.

should we add a warn log when this parameter is set and mode is not inline to communicate that it will not work?

@shivam2680 shivam2680 Apr 1, 2025 •

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.

I agree somewhat,
But the issue here is that this parameter does influence the fetch result response, it's just that when arrow is enabled number of arrow chunks fetched per call is limited and each having fixed number of rows, not exactly equal to the parameter. Have explained this in the doc.

@shivam2680
shivam2680 merged commit b7f5e17 into databricks:main Apr 1, 2025
samikshya-db added a commit that referenced this pull request Apr 12, 2025
* [PECOBLR-272] Retry handler fixes for http client (#764)

* Support Azure Managed Identity OAuth in OSS JDBC (#756)

* draft for azure msi

* add unit tests

* remove debug line

* fmt

* Address comments

* Add debug logs

* [PECOBLR-262] implement todos in DBFS volume client (#763)

* [PECOBLR-182] Add support for retry timeout for UC vol operations (#760)

* Add support for retry timeout for UC vol operations

* [PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows (#765)

* [PECOBLR-126] added DefaultStringColumnLength config (#761)

* Add client-side statement execution timeout (#767)

## Description
- DatabricksStatement uses the same-thread executor for the statement's CompletableFuture. By the time the code reaches the `futureResultSet.get(timeoutInSeconds, TimeUnit.SECONDS)` line, the task has already fully executed (or failed), so the timeout has no practical effect.
- Create a reusable TimeoutHandler utility class that centralizes timeout logic.
- Implement timeout checks during statement execution polling instead of relying on the CompletableFuture timeout.
- Add automatic cancellation of statements when timeouts occur.
- Ensure consistent timeout behavior across both SDK and Thrift client implementations.
- Move the DatabricksSdkClientTest class to the test counterpart of its source package. Delete the duplicate DatabricksSdkClientTest class.
- DatabricksThriftAccessor will now use connection param `asyncPollIntervalMillis`. Previously, the poll interval was hardcoded to 1 second.

## Testing
- Unit tests
- E2E testing

* [PECOBLR-106][PECOBLR-235] Fixes Logging Test intermittent failures and adds support for thriftclient in test (#766)

* logging fixes

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* use printf in place of echo

* use powershell

* try java side fix

* fix comments

* minor fixes

* Hybrid Results are enabled by default in SEA Mode (#771)

* Made Hybrid results default

* Fixed unit test

* Added Fake service stubs

* Added stubs for Default hybrid mode

* Reverted to old stubs

* Reverted stubs

* Fix

* [PECOBLR-289] Throw exception for column not found (#773)

* [PECOBLR-145] Implement OAuth2RedirectUrlPort (#775)

* Support for providing custom headers from URL (#776)

* Support for custom headers

* Made headers case insensitive

* Added back the case matching in headers

* Formatting fix

* Align behaviour for ResultSet#getBoolean (#774)

* Update version to 1.0.3 (#772)

* make changes for 1.0.3 release

* adds changelog

* updates changelog

* updates changelog

* updates changelog

* [PECOBLR-239][PECOBLR-279] added sql types integration tests (#769)

* added edge cases for string and null

* update stubs

* add test for variant type

* add test for timestamp

* [PECOBLR-310] Refactor internal interfaces into internal package, and fix javadoc for public interfaces (#770)

* Fix javadoc for all public interfaces

* [PECOBLR-164] Support connection param SocketTimeout (#777)

- The default value of the param is kept as 900 seconds (same as earlier value and default in databricks-sdk-java)
- Set the param in thrift, dbfs, and sql-exec clients

* Renaming UC Volume retryable codes and retry timeout parameters as per Docs team feedback (#780)

* Rename UC timeout and retryable parameters based on Docs team feedback

* Set default value as null for BigDecimal (#782)

* [PECOBLR-322] Update SDK to the latest version (0.43.0) (#781)

* [PECOBLR-301] Handle server returned Thrift version as part of open session response gracefully (#779)

* init changes

* Refactor TSparkArrowTypes initialization based on protocol version

* added comments

* added several unit tests

* added more unit tests

* ran ProtocolFeatureUtilTest for all protocol versions

* store protocol version as TProtocolVersion enum.

* move db compute check to protocol feature util

---------

Co-authored-by: Vikrant Puppala <[email protected]>
Co-authored-by: Shivam Raj <[email protected]>
Co-authored-by: Gopal Lal <[email protected]>
Co-authored-by: jayant <[email protected]>
Co-authored-by: Madhav Sainanee <[email protected]>
Co-authored-by: Jothi Prakash <[email protected]>
samikshya-db added a commit that referenced this pull request Apr 12, 2025
* [PECOBLR-272] Retry handler fixes for http client (#764)

* Support Azure Managed Identity OAuth in OSS JDBC (#756)

* draft for azure msi

* add unit tests

* remove debug line

* fmt

* Address comments

* Add debug logs

* [PECOBLR-262] implement todos in DBFS volume client (#763)

* [PECOBLR-182] Add support for retry timeout for UC vol operations (#760)

* Add support for retry timeout for UC vol operations

* [PECOBLR-161][PECOBLR-282] add support for configurable row fetch limit in thrift inline and fix setMaxRows (#765)

* [PECOBLR-126] added DefaultStringColumnLength config (#761)

* Add client-side statement execution timeout (#767)

## Description
- DatabricksStatement uses the same-thread executor for the statement's CompletableFuture. By the time the code reaches the `futureResultSet.get(timeoutInSeconds, TimeUnit.SECONDS)` line, the task has already fully executed (or failed), so the timeout has no practical effect.
- Create a reusable TimeoutHandler utility class that centralizes timeout logic.
- Implement timeout checks during statement execution polling instead of relying on the CompletableFuture timeout.
- Add automatic cancellation of statements when timeouts occur.
- Ensure consistent timeout behavior across both SDK and Thrift client implementations.
- Move the DatabricksSdkClientTest class to the test counterpart of its source package. Delete the duplicate DatabricksSdkClientTest class.
- DatabricksThriftAccessor will now use connection param `asyncPollIntervalMillis`. Previously, the poll interval was hardcoded to 1 second.

## Testing
- Unit tests
- E2E testing

* [PECOBLR-106][PECOBLR-235] Fixes Logging Test intermittent failures and adds support for thriftclient in test (#766)

* logging fixes

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* fix logging test

* use printf in place of echo

* use powershell

* try java side fix

* fix comments

* minor fixes

* Hybrid Results are enabled by default in SEA Mode (#771)

* Made Hybrid results default

* Fixed unit test

* Added Fake service stubs

* Added stubs for Default hybrid mode

* Reverted to old stubs

* Reverted stubs

* Fix

* [PECOBLR-289] Throw exception for column not found (#773)

* [PECOBLR-145] Implement OAuth2RedirectUrlPort (#775)

* Support for providing custom headers from URL (#776)

* Support for custom headers

* Made headers case insensitive

* Added back the case matching in headers

* Formatting fix

* Align behaviour for ResultSet#getBoolean (#774)

* Update version to 1.0.3 (#772)

* make changes for 1.0.3 release

* adds changelog

* updates changelog

* updates changelog

* updates changelog

* [PECOBLR-239][PECOBLR-279] added sql types integration tests (#769)

* added edge cases for string and null

* update stubs

* add test for variant type

* add test for timestamp

* [PECOBLR-310] Refactor internal interfaces into internal package, and fix javadoc for public interfaces (#770)

* Fix javadoc for all public interfaces

* [PECOBLR-164] Support connection param SocketTimeout (#777)

- The default value of the param is kept as 900 seconds (same as earlier value and default in databricks-sdk-java)
- Set the param in thrift, dbfs, and sql-exec clients

* Renaming UC Volume retryable codes and retry timeout parameters as per Docs team feedback (#780)

* Rename UC timeout and retryable parameters based on Docs team feedback

* Set default value as null for BigDecimal (#782)

* [PECOBLR-322] Update SDK to the latest version (0.43.0) (#781)

* [PECOBLR-301] Handle server returned Thrift version as part of open session response gracefully (#779)

* init changes

* Refactor TSparkArrowTypes initialization based on protocol version

* added comments

* added several unit tests

* added more unit tests

* ran ProtocolFeatureUtilTest for all protocol versions

* store protocol version as TProtocolVersion enum.

* move db compute check to protocol feature util

---------

Co-authored-by: Vikrant Puppala <[email protected]>
Co-authored-by: Shivam Raj <[email protected]>
Co-authored-by: Gopal Lal <[email protected]>
Co-authored-by: jayant <[email protected]>
Co-authored-by: Madhav Sainanee <[email protected]>
Co-authored-by: Jothi Prakash <[email protected]>

This branch was previously deployed

1 inactive deployment
azure-prod — 1dd9e0b2 Deployed Apr 1, 2025 by shivam2680
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.

4 participants