-
Notifications
You must be signed in to change notification settings - Fork 129
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 67 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
138c2ae
[squash from exec-sea] bring over execution phase changes
varun-edachali-dbx 3e3ab94
remove excess test
varun-edachali-dbx 4a78165
add docstring
varun-edachali-dbx 0dac4aa
remvoe exec func in sea backend
varun-edachali-dbx 1b794c7
remove excess files
varun-edachali-dbx da5a6fe
remove excess models
varun-edachali-dbx 686ade4
remove excess sea backend tests
varun-edachali-dbx 31e6c83
cleanup
varun-edachali-dbx 69ea238
re-introduce get_schema_desc
varun-edachali-dbx 66d7517
remove SeaResultSet
varun-edachali-dbx 71feef9
clean imports and attributes
varun-edachali-dbx ae9862f
pass CommandId to ExecResp
varun-edachali-dbx d8aa69e
remove changes in types
varun-edachali-dbx db139bc
add back essential types (ExecResponse, from_sea_state)
varun-edachali-dbx b977b12
fix fetch types
varun-edachali-dbx da615c0
excess imports
varun-edachali-dbx 0da04a6
reduce diff by maintaining logs
varun-edachali-dbx ea9d456
fix int test types
varun-edachali-dbx 8985c62
[squashed from exec-sea] init execution func
varun-edachali-dbx d9bcdbe
remove irrelevant changes
varun-edachali-dbx ee9fa1c
remove ResultSetFilter functionality
varun-edachali-dbx 24c6152
remove more irrelevant changes
varun-edachali-dbx 67fd101
remove more irrelevant changes
varun-edachali-dbx 271fcaf
even more irrelevant changes
varun-edachali-dbx bf26ea3
remove sea response as init option
varun-edachali-dbx d97463b
move guid_to_hex_id import to utils
varun-edachali-dbx 139e246
reduce diff in guid utils import
varun-edachali-dbx e3ee4e4
move arrow_schema_bytes back into ExecuteResult
varun-edachali-dbx f448a8f
maintain log
varun-edachali-dbx 82ca1ee
remove un-necessary assignment
varun-edachali-dbx e96a078
remove un-necessary tuple response
varun-edachali-dbx 27158b1
remove un-ncessary verbose mocking
varun-edachali-dbx d3200c4
move Queue construction to ResultSert
varun-edachali-dbx 8a014f0
move description to List[Tuple]
varun-edachali-dbx 39c41ab
frmatting (black)
varun-edachali-dbx 2cd04df
reduce diff (remove explicit tuple conversion)
varun-edachali-dbx 067a019
remove has_more_rows from ExecuteResponse
varun-edachali-dbx 48c83e0
remove un-necessary has_more_rows aclc
varun-edachali-dbx 281a9e9
default has_more_rows to True
varun-edachali-dbx 192901d
return has_more_rows from ExecResponse conversion during GetRespMetadata
varun-edachali-dbx 55f5c45
remove unnecessary replacement
varun-edachali-dbx edc36b5
better mocked backend naming
varun-edachali-dbx 81280e7
remove has_more_rows test in ExecuteResponse
varun-edachali-dbx c1d3be2
introduce replacement of original has_more_rows read test
varun-edachali-dbx 5ee4136
call correct method in test_use_arrow_schema
varun-edachali-dbx b881ab0
call correct method in test_fall_back_to_hive_schema
varun-edachali-dbx 53bf715
re-introduce result response read test
varun-edachali-dbx 45a32be
simplify test
varun-edachali-dbx e3fe299
remove excess fetch_results mocks
varun-edachali-dbx e8038d3
more minimal changes to thrift_backend tests
varun-edachali-dbx 2f6ec19
move back to old table types
varun-edachali-dbx 73bc282
remove outdated arrow_schema_bytes return
varun-edachali-dbx 4e07f1e
align SeaResultSet with new structure
varun-edachali-dbx 65e7c6b
correct sea res set tests
varun-edachali-dbx 7c483f2
remove duplicate import
varun-edachali-dbx 8cbeb08
rephrase model docstrings to explicitly denote that they are represen…
varun-edachali-dbx 36b9cfb
has_more_rows -> is_direct_results
varun-edachali-dbx c04d583
switch docstring format to align with Connection class
varun-edachali-dbx ba91138
Merge branch 'exec-resp-norm' into sea-res-set
varun-edachali-dbx ed7079e
has_more_rows -> is_direct_results
varun-edachali-dbx 0384b65
fix type errors with arrow_schema_bytes
varun-edachali-dbx 218e547
spaces after multi line pydocs
varun-edachali-dbx c7b0701
Merge branch 'sea-migration' into sea-res-set
varun-edachali-dbx a6788f8
remove duplicate queue init (merge artifact)
varun-edachali-dbx 93468e6
reduce diff (remove newlines)
varun-edachali-dbx a70a6ce
remove un-necessary changes
varun-edachali-dbx de181d8
Revert "remove un-necessary changes"
varun-edachali-dbx 8c65345
b"" -> None
varun-edachali-dbx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.