|
3 | 3 | import itertools |
4 | 4 | import unittest |
5 | 5 | import pytest |
6 | | -from unittest.mock import patch, MagicMock, Mock |
| 6 | +from unittest.mock import patch, MagicMock, Mock, sentinel |
7 | 7 | from ssl import CERT_NONE, CERT_REQUIRED |
8 | 8 | from urllib3 import HTTPSConnectionPool |
9 | 9 |
|
@@ -134,6 +134,51 @@ def test_metadata_catalog_escaping( |
134 | 134 | assert getattr(request, thrift_field) == value |
135 | 135 |
|
136 | 136 |
|
| 137 | +@pytest.mark.skipif(pyarrow is None, reason="PyArrow is not installed") |
| 138 | +@pytest.mark.parametrize("count", [7, 0, None]) |
| 139 | +def test_async_result_reads_status_count_and_preserves_rows(count): |
| 140 | + with ( |
| 141 | + patch( |
| 142 | + "databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True |
| 143 | + ), |
| 144 | + patch("databricks.sql.backend.thrift_backend.ThriftResultSet") as result_set, |
| 145 | + ): |
| 146 | + backend = ThriftDatabricksClient( |
| 147 | + "foobar", |
| 148 | + 443, |
| 149 | + "path", |
| 150 | + [], |
| 151 | + auth_provider=AuthProvider(), |
| 152 | + ssl_options=SSLOptions(), |
| 153 | + http_client=MagicMock(), |
| 154 | + ) |
| 155 | + operation_status = ttypes.TGetOperationStatusResp( |
| 156 | + status=ThriftBackendTestSuite.okay_status, |
| 157 | + operationState=ttypes.TOperationState.FINISHED_STATE, |
| 158 | + numModifiedRows=count, |
| 159 | + ) |
| 160 | + backend._poll_for_status = Mock(return_value=operation_status) |
| 161 | + metadata = ttypes.TGetResultSetMetadataResp( |
| 162 | + schema=ttypes.TTableSchema(columns=[]), |
| 163 | + arrowSchema=pyarrow.schema([]).serialize().to_pybytes(), |
| 164 | + resultFormat=ttypes.TSparkRowSetType.ARROW_BASED_SET, |
| 165 | + ) |
| 166 | + backend.make_request = Mock( |
| 167 | + return_value=Mock( |
| 168 | + resultSetMetadata=metadata, |
| 169 | + results=sentinel.counter_rows, |
| 170 | + hasMoreRows=False, |
| 171 | + ) |
| 172 | + ) |
| 173 | + cid = CommandId.from_thrift_handle(ThriftBackendTestSuite.operation_handle) |
| 174 | + backend.get_execution_result(cid, Mock()) |
| 175 | + |
| 176 | + backend._poll_for_status.assert_called_once_with(cid.to_thrift_handle()) |
| 177 | + response = result_set.call_args.kwargs["execute_response"] |
| 178 | + assert response.num_modified_rows == count |
| 179 | + assert result_set.call_args.kwargs["t_row_set"] is sentinel.counter_rows |
| 180 | + |
| 181 | + |
137 | 182 | @pytest.mark.skipif(pyarrow is None, reason="PyArrow is not installed") |
138 | 183 | class ThriftBackendTestSuite(unittest.TestCase): |
139 | 184 | okay_status = ttypes.TStatus(statusCode=ttypes.TStatusCode.SUCCESS_STATUS) |
|
0 commit comments