Skip to content

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

Merged
shivam2680 merged 8 commits into
mainfrom
shivam2680/thrift-version-handling
Apr 11, 2025
Merged

shivam2680 merged 8 commits into
mainfrom
shivam2680/thrift-version-handling

Conversation

@shivam2680

@shivam2680 shivam2680 commented Apr 8, 2025 •

Copy link
Copy Markdown
Collaborator

Description

Introduced a new utility class ProtocolFeatureUtil to handle thrift protocol version checks for using thrift functionalities like cloud fetch, compression, parameterized queries etc.

Introduction of ProtocolFeatureUtil:

  • Added a new utility class ProtocolFeatureUtil to check Spark protocol version features. This class includes methods to determine if specific features are supported, such as supportsGetInfosInOpenSession, supportsDirectResults, supportsCloudFetch, etc based on server protocol version

Integration and Usage of ProtocolFeatureUtil:

  • Cached server protocol version in DatabricksThriftClient and DatabricksThriftAccessor
  • Updated the method getResultSetResp to use supportsResultSetMetadataFromFetch from ProtocolFeatureUtil.
  • Updated the getRequest method to conditionally set parameters based on protocol version checks using ProtocolFeatureUtil.

Protocol version enum taken from src

Testing

Driver test by overriding clientProtocolVersion to V1 in open session request. Verified that following are working

  • different data types (ml.feature_store_ol_dynamodb_.test_ft_data_types)
  • metadata queries
  • large and small queries
    Unit tests
    CI/CD

@shivam2680
shivam2680 marked this pull request as ready for review April 9, 2025 00:13

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.

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

Comments suppressed due to low confidence (1)

src/test/java/com/databricks/jdbc/dbclient/impl/thrift/DatabricksThriftServiceClientTest.java:207

  • [nitpick] In the parameterized test 'testGetRequestWithDifferentProtocolVersions', when supportsParameterizedQueries is true, the test only verifies that the entire request object is non-null. It would be more robust to explicitly assert that the parameters are correctly set (e.g. that request.getParameters() is not null) for supported versions.
if (supportsParameterizedQueries) {

@shivam2680
shivam2680 requested a review from gopalldb April 9, 2025 05:36
private final boolean enableDirectResults;
private final int asyncPollIntervalMillis;
private final int maxRowsPerBlock;
private int serverProtocolVersion = JDBC_THRIFT_VERSION.getValue();

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.

Not sure why we're converting to int everywhere and storing the protocol version, why not just have the data type as TProtocolVersion?

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.

JDBC_THRIFT_VERSION.getValue() returns int

/** Get the integer value of this enum value, as defined in the Thrift IDL. */
  @Override
  public int getValue() {
    return value;
  }

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, my question is why aren't we doing this instead:

private TProtocolVersion serverProtocolVersion = JDBC_THRIFT_VERSION;

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.

seemed like a cleaner approach. less number of .getValue() calls in both ProtocolFeatureUtil and DatabricksThriftServiceClient

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.

not happy storing an enum as an int, let's use methods like compareTo etc if we do not want to call getValue but this isn't ideal.

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.

right, I'll update this

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

lgtm minor comment

* @return true if direct results are supported, false otherwise
*/
public static boolean supportsDirectResults(TProtocolVersion protocolVersion) {
return protocolVersion.compareTo(TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V1) >= 0;

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 these are in v1? getInfos, directResults, hasMoreRows?

@shivam2680 shivam2680 Apr 10, 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.

yes

// Spark V1:
  // - On top of HIVE_CLI_SERVICE_PROTOCOL_V8
  // - Adds optional list<TGetInfoType> getInfos to TOpenSessionReq
  //   and responds with list<TGetInfoValue> getInfos in TOpenSessionResp
  // - Adds TSparkGetDirectResults to TExecuteStatementReq and other operation req.
  //   Responds with TSparkDirectResults, which shortcuts the sequence of
  //   GetOperationStatus, GetResultSetMetadata, FetchResults and CloseOperation,
  //   normally triggered by operation requests.
  // - Changes semantics of TFetchResultsResp.hasMoreRows:
  //   - If hasMoreRows == false, there are no more rows
  //   - If hasMoreRows == true, there may be more rows, even if returned row count is 0
  //   (Hive protocol always returned hasMoreRows == false)
  //   This way, an empty FetchResults is not needed at end of fetching, while an empty fetch
  //   result may not always mean end of results.

* @param protocolVersion The protocol version to check
* @return true if multiple catalogs are supported, false otherwise
*/
public static boolean supportsMultipleCatalogs(TProtocolVersion protocolVersion) {

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.

where is this used?

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

Add details in the testing section how you tested for different protocol versions

@shivam2680
shivam2680 merged commit d3c767d into databricks:main Apr 11, 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 — 1bfe7479 Deployed Apr 10, 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