- Notifications
You must be signed in to change notification settings - Fork126
Introduce preliminary SEA Result Set#588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
68 commits Select commitHold shift + click to select a range
138c2ae [squash from exec-sea] bring over execution phase changes
varun-edachali-dbx3e3ab94 remove excess test
varun-edachali-dbx4a78165 add docstring
varun-edachali-dbx0dac4aa remvoe exec func in sea backend
varun-edachali-dbx1b794c7 remove excess files
varun-edachali-dbxda5a6fe remove excess models
varun-edachali-dbx686ade4 remove excess sea backend tests
varun-edachali-dbx31e6c83 cleanup
varun-edachali-dbx69ea238 re-introduce get_schema_desc
varun-edachali-dbx66d7517 remove SeaResultSet
varun-edachali-dbx71feef9 clean imports and attributes
varun-edachali-dbxae9862f pass CommandId to ExecResp
varun-edachali-dbxd8aa69e remove changes in types
varun-edachali-dbxdb139bc add back essential types (ExecResponse, from_sea_state)
varun-edachali-dbxb977b12 fix fetch types
varun-edachali-dbxda615c0 excess imports
varun-edachali-dbx0da04a6 reduce diff by maintaining logs
varun-edachali-dbxea9d456 fix int test types
varun-edachali-dbx8985c62 [squashed from exec-sea] init execution func
varun-edachali-dbxd9bcdbe remove irrelevant changes
varun-edachali-dbxee9fa1c remove ResultSetFilter functionality
varun-edachali-dbx24c6152 remove more irrelevant changes
varun-edachali-dbx67fd101 remove more irrelevant changes
varun-edachali-dbx271fcaf even more irrelevant changes
varun-edachali-dbxbf26ea3 remove sea response as init option
varun-edachali-dbxd97463b move guid_to_hex_id import to utils
varun-edachali-dbx139e246 reduce diff in guid utils import
varun-edachali-dbxe3ee4e4 move arrow_schema_bytes back into ExecuteResult
varun-edachali-dbxf448a8f maintain log
varun-edachali-dbx82ca1ee remove un-necessary assignment
varun-edachali-dbxe96a078 remove un-necessary tuple response
varun-edachali-dbx27158b1 remove un-ncessary verbose mocking
varun-edachali-dbxd3200c4 move Queue construction to ResultSert
varun-edachali-dbx8a014f0 move description to List[Tuple]
varun-edachali-dbx39c41ab frmatting (black)
varun-edachali-dbx2cd04df reduce diff (remove explicit tuple conversion)
varun-edachali-dbx067a019 remove has_more_rows from ExecuteResponse
varun-edachali-dbx48c83e0 remove un-necessary has_more_rows aclc
varun-edachali-dbx281a9e9 default has_more_rows to True
varun-edachali-dbx192901d return has_more_rows from ExecResponse conversion during GetRespMetadata
varun-edachali-dbx55f5c45 remove unnecessary replacement
varun-edachali-dbxedc36b5 better mocked backend naming
varun-edachali-dbx81280e7 remove has_more_rows test in ExecuteResponse
varun-edachali-dbxc1d3be2 introduce replacement of original has_more_rows read test
varun-edachali-dbx5ee4136 call correct method in test_use_arrow_schema
varun-edachali-dbxb881ab0 call correct method in test_fall_back_to_hive_schema
varun-edachali-dbx53bf715 re-introduce result response read test
varun-edachali-dbx45a32be simplify test
varun-edachali-dbxe3fe299 remove excess fetch_results mocks
varun-edachali-dbxe8038d3 more minimal changes to thrift_backend tests
varun-edachali-dbx2f6ec19 move back to old table types
varun-edachali-dbx73bc282 remove outdated arrow_schema_bytes return
varun-edachali-dbx4e07f1e align SeaResultSet with new structure
varun-edachali-dbx65e7c6b correct sea res set tests
varun-edachali-dbx7c483f2 remove duplicate import
varun-edachali-dbx8cbeb08 rephrase model docstrings to explicitly denote that they are represen…
varun-edachali-dbx36b9cfb has_more_rows -> is_direct_results
varun-edachali-dbxc04d583 switch docstring format to align with Connection class
varun-edachali-dbxba91138 Merge branch 'exec-resp-norm' into sea-res-set
varun-edachali-dbxed7079e has_more_rows -> is_direct_results
varun-edachali-dbx0384b65 fix type errors with arrow_schema_bytes
varun-edachali-dbx218e547 spaces after multi line pydocs
varun-edachali-dbxc7b0701 Merge branch 'sea-migration' into sea-res-set
varun-edachali-dbxa6788f8 remove duplicate queue init (merge artifact)
varun-edachali-dbx93468e6 reduce diff (remove newlines)
varun-edachali-dbxa70a6ce remove un-necessary changes
varun-edachali-dbxde181d8 Revert "remove un-necessary changes"
varun-edachali-dbx8c65345 b"" -> None
varun-edachali-dbxFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
89 changes: 87 additions & 2 deletionssrc/databricks/sql/result_set.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletionstests/unit/test_sea_result_set.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| """ | ||
| Tests for the SeaResultSet class. | ||
| This module contains tests for the SeaResultSet class, which implements | ||
| the result set functionality for the SEA (Statement Execution API) backend. | ||
| """ | ||
| import pytest | ||
| from unittest.mock import patch, MagicMock, Mock | ||
| from databricks.sql.result_set import SeaResultSet | ||
| from databricks.sql.backend.types import CommandId, CommandState, BackendType | ||
| class TestSeaResultSet: | ||
| """Test suite for the SeaResultSet class.""" | ||
| @pytest.fixture | ||
| def mock_connection(self): | ||
| """Create a mock connection.""" | ||
| connection = Mock() | ||
| connection.open = True | ||
| return connection | ||
| @pytest.fixture | ||
| def mock_sea_client(self): | ||
| """Create a mock SEA client.""" | ||
| return Mock() | ||
| @pytest.fixture | ||
| def execute_response(self): | ||
| """Create a sample execute response.""" | ||
| mock_response = Mock() | ||
| mock_response.command_id = CommandId.from_sea_statement_id("test-statement-123") | ||
| mock_response.status = CommandState.SUCCEEDED | ||
| mock_response.has_been_closed_server_side = False | ||
| mock_response.is_direct_results = False | ||
| mock_response.results_queue = None | ||
| mock_response.description = [ | ||
| ("test_value", "INT", None, None, None, None, None) | ||
| ] | ||
| mock_response.is_staging_operation = False | ||
| return mock_response | ||
| def test_init_with_execute_response( | ||
| self, mock_connection, mock_sea_client, execute_response | ||
| ): | ||
| """Test initializing SeaResultSet with an execute response.""" | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| # Verify basic properties | ||
| assert result_set.command_id == execute_response.command_id | ||
| assert result_set.status == CommandState.SUCCEEDED | ||
| assert result_set.connection == mock_connection | ||
| assert result_set.backend == mock_sea_client | ||
| assert result_set.buffer_size_bytes == 1000 | ||
| assert result_set.arraysize == 100 | ||
| assert result_set.description == execute_response.description | ||
| def test_close(self, mock_connection, mock_sea_client, execute_response): | ||
| """Test closing a result set.""" | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| # Close the result set | ||
| result_set.close() | ||
| # Verify the backend's close_command was called | ||
| mock_sea_client.close_command.assert_called_once_with(result_set.command_id) | ||
| assert result_set.has_been_closed_server_side is True | ||
| assert result_set.status == CommandState.CLOSED | ||
| def test_close_when_already_closed_server_side( | ||
| self, mock_connection, mock_sea_client, execute_response | ||
| ): | ||
| """Test closing a result set that has already been closed server-side.""" | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| result_set.has_been_closed_server_side = True | ||
| # Close the result set | ||
| result_set.close() | ||
| # Verify the backend's close_command was NOT called | ||
| mock_sea_client.close_command.assert_not_called() | ||
| assert result_set.has_been_closed_server_side is True | ||
| assert result_set.status == CommandState.CLOSED | ||
| def test_close_when_connection_closed( | ||
| self, mock_connection, mock_sea_client, execute_response | ||
| ): | ||
| """Test closing a result set when the connection is closed.""" | ||
| mock_connection.open = False | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| # Close the result set | ||
| result_set.close() | ||
| # Verify the backend's close_command was NOT called | ||
| mock_sea_client.close_command.assert_not_called() | ||
| assert result_set.has_been_closed_server_side is True | ||
| assert result_set.status == CommandState.CLOSED | ||
| def test_unimplemented_methods( | ||
| self, mock_connection, mock_sea_client, execute_response | ||
| ): | ||
| """Test that unimplemented methods raise NotImplementedError.""" | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| # Test each unimplemented method individually with specific error messages | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchone is not implemented for SEA backend" | ||
| ): | ||
| result_set.fetchone() | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchmany is not implemented for SEA backend" | ||
| ): | ||
| result_set.fetchmany(10) | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchmany is not implemented for SEA backend" | ||
| ): | ||
| # Test with default parameter value | ||
| result_set.fetchmany() | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchall is not implemented for SEA backend" | ||
| ): | ||
| result_set.fetchall() | ||
| with pytest.raises( | ||
| NotImplementedError, | ||
| match="fetchmany_arrow is not implemented for SEA backend", | ||
| ): | ||
| result_set.fetchmany_arrow(10) | ||
| with pytest.raises( | ||
| NotImplementedError, | ||
| match="fetchall_arrow is not implemented for SEA backend", | ||
| ): | ||
| result_set.fetchall_arrow() | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchone is not implemented for SEA backend" | ||
| ): | ||
| # Test iteration protocol (calls fetchone internally) | ||
| next(iter(result_set)) | ||
| with pytest.raises( | ||
| NotImplementedError, match="fetchone is not implemented for SEA backend" | ||
| ): | ||
| # Test using the result set in a for loop | ||
| for row in result_set: | ||
| pass | ||
| def test_fill_results_buffer_not_implemented( | ||
| self, mock_connection, mock_sea_client, execute_response | ||
| ): | ||
| """Test that _fill_results_buffer raises NotImplementedError.""" | ||
| result_set = SeaResultSet( | ||
| connection=mock_connection, | ||
| execute_response=execute_response, | ||
| sea_client=mock_sea_client, | ||
| buffer_size_bytes=1000, | ||
| arraysize=100, | ||
| ) | ||
| with pytest.raises( | ||
| NotImplementedError, | ||
| match="_fill_results_buffer is not implemented for SEA backend", | ||
| ): | ||
| result_set._fill_results_buffer() |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.