Skip to content

[ES-1436915] Pass context to public classes and their dependencies#806

Merged
jayantsing-db merged 2 commits into
mainfrom
jayantsing-db/remove-context-holder-usage
Apr 28, 2025
Merged

[ES-1436915] Pass context to public classes and their dependencies#806
jayantsing-db merged 2 commits into
mainfrom
jayantsing-db/remove-context-holder-usage

Conversation

@jayantsing-db
Copy link
Copy Markdown
Collaborator

@jayantsing-db jayantsing-db commented Apr 24, 2025

Description

For public classes and interfaces, we can't make assumptions about the threading environment in which they will be used. Specifically, host applications may utilize these classes, such as ResultSet, in a thread that is different from the one that created the JDBC connection resource.

In the current implementation of certain APIs, along with the execution flow of DatabricksResultSet, there is an expectation that the thread will automatically be populated with an internal context object. This assumption is problematic, given the scenario described above, where threads may not have the expected context object set by default.

To address this issue, this pull request explicitly passes the context object to the areas where it was previously missing, correcting the faulty implementation.

Key changes in this PR:

  • The metadata result set builder class has been refactored from a static utility class to an instance-based class, with the context object now stored as a member variable.

  • The context object is now passed explicitly to the DatabricksResultSet class, ensuring that it functions correctly in multithreaded environments.

These changes eliminate the previous assumption about the thread's context

Testing

#807

Additional Notes to the Reviewer

@jayantsing-db jayantsing-db changed the title Pass connection context to public classes and their dependencies [ES-1436915] Pass context to public classes and their dependencies Apr 24, 2025
@jayantsing-db jayantsing-db requested a review from Copilot April 25, 2025 09:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 explicitly passes the context object to public classes and their dependencies, ensuring thread safety in multithreaded environments. Key changes include refactoring static utility classes (e.g. MetadataResultSetBuilder) into instance-based classes that take an explicit context, updating client and test code to use the new constructors, and modifying tests to pass a proper connection context.

Reviewed Changes

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

File Description
src/test/java/com/databricks/jdbc/dbclient/impl/sqlexec/DatabricksMetadataSdkClientTest.java Fixed a spelling error in a comment.
src/test/java/com/databricks/jdbc/dbclient/impl/sqlexec/DatabricksEmptyMetadataClientTest.java Updated test mocks to pass the connection context explicitly.
src/test/java/com/databricks/jdbc/dbclient/impl/common/MetadataResultSetBuilderTest.java Updated tests to use instance-based MetadataResultSetBuilder.
Multiple files under src/main/java/com/databricks/jdbc/… Replaced static calls to MetadataResultSetBuilder with instance calls using the explicit context.
Comments suppressed due to low confidence (1)

src/test/java/com/databricks/jdbc/dbclient/impl/sqlexec/DatabricksMetadataSdkClientTest.java:217

  • There's a typo in the comment: 'recieved' should be 'received'.
    // mockedMetaData represents resultManifest recieved from the server

@jayantsing-db jayantsing-db merged commit e41db81 into databricks:main Apr 28, 2025
15 checks passed
@jayantsing-db jayantsing-db deleted the jayantsing-db/remove-context-holder-usage branch April 28, 2025 04:57
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