Skip to content

Commit e84b09f

Browse files
fix: sql.thrift_backend -> sql.backend.thrift_backend in tests and examples
1 parent 1fba927 commit e84b09f

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

examples/v3_retries_query_execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# which means all redirects will be followed. In this case, a redirect will count toward the
2727
# _retry_stop_after_attempts_count which means that by default the connector will not enter an endless retry loop.
2828
#
29-
# For complete information about configuring retries, see the docstring for databricks.sql.thrift_backend.ThriftBackend
29+
# For complete information about configuring retries, see the docstring for databricks.sql.backend.thrift_backend.ThriftBackend
3030

3131
with sql.connect(
3232
server_hostname=os.getenv("DATABRICKS_SERVER_HOSTNAME"),

tests/unit/test_thrift_backend.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_hive_schema_to_arrow_schema_preserves_column_names(self):
133133
self.assertEqual(arrow_schema.field(2).name, "column 2")
134134
self.assertEqual(arrow_schema.field(3).name, "")
135135

136-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
136+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
137137
def test_bad_protocol_versions_are_rejected(self, tcli_service_client_cass):
138138
t_http_client_instance = tcli_service_client_cass.return_value
139139
bad_protocol_versions = [
@@ -163,7 +163,7 @@ def test_bad_protocol_versions_are_rejected(self, tcli_service_client_cass):
163163
"expected server to use a protocol version", str(cm.exception)
164164
)
165165

166-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
166+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
167167
def test_okay_protocol_versions_succeed(self, tcli_service_client_cass):
168168
t_http_client_instance = tcli_service_client_cass.return_value
169169
good_protocol_versions = [
@@ -642,7 +642,7 @@ def test_handle_execute_response_sets_compression_in_direct_results(
642642
)
643643
self.assertEqual(execute_response.lz4_compressed, lz4Compressed)
644644

645-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
645+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
646646
def test_handle_execute_response_checks_operation_state_in_polls(
647647
self, tcli_service_class
648648
):
@@ -686,7 +686,7 @@ def test_handle_execute_response_checks_operation_state_in_polls(
686686
if op_state_resp.errorMessage:
687687
self.assertIn(op_state_resp.errorMessage, str(cm.exception))
688688

689-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
689+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
690690
def test_get_status_uses_display_message_if_available(self, tcli_service_class):
691691
tcli_service_instance = tcli_service_class.return_value
692692

@@ -724,7 +724,7 @@ def test_get_status_uses_display_message_if_available(self, tcli_service_class):
724724
self.assertEqual(display_message, str(cm.exception))
725725
self.assertIn(diagnostic_info, str(cm.exception.message_with_context()))
726726

727-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
727+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
728728
def test_direct_results_uses_display_message_if_available(self, tcli_service_class):
729729
tcli_service_instance = tcli_service_class.return_value
730730

@@ -825,7 +825,7 @@ def test_handle_execute_response_checks_direct_results_for_error_statuses(self):
825825
thrift_backend._handle_execute_response(error_resp, Mock())
826826
self.assertIn("this is a bad error", str(cm.exception))
827827

828-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
828+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
829829
def test_handle_execute_response_can_handle_without_direct_results(
830830
self, tcli_service_class
831831
):
@@ -917,7 +917,7 @@ def test_handle_execute_response_can_handle_with_direct_results(self):
917917
ttypes.TOperationState.FINISHED_STATE,
918918
)
919919

920-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
920+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
921921
def test_use_arrow_schema_if_available(self, tcli_service_class):
922922
tcli_service_instance = tcli_service_class.return_value
923923
arrow_schema_mock = MagicMock(name="Arrow schema mock")
@@ -946,7 +946,7 @@ def test_use_arrow_schema_if_available(self, tcli_service_class):
946946

947947
self.assertEqual(execute_response.arrow_schema_bytes, arrow_schema_mock)
948948

949-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
949+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
950950
def test_fall_back_to_hive_schema_if_no_arrow_schema(self, tcli_service_class):
951951
tcli_service_instance = tcli_service_class.return_value
952952
hive_schema_mock = MagicMock(name="Hive schema mock")
@@ -976,7 +976,7 @@ def test_fall_back_to_hive_schema_if_no_arrow_schema(self, tcli_service_class):
976976
@patch(
977977
"databricks.sql.utils.ResultSetQueueFactory.build_queue", return_value=Mock()
978978
)
979-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
979+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
980980
def test_handle_execute_response_reads_has_more_rows_in_direct_results(
981981
self, tcli_service_class, build_queue
982982
):
@@ -1020,7 +1020,7 @@ def test_handle_execute_response_reads_has_more_rows_in_direct_results(
10201020
@patch(
10211021
"databricks.sql.utils.ResultSetQueueFactory.build_queue", return_value=Mock()
10221022
)
1023-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1023+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
10241024
def test_handle_execute_response_reads_has_more_rows_in_result_response(
10251025
self, tcli_service_class, build_queue
10261026
):
@@ -1075,7 +1075,7 @@ def test_handle_execute_response_reads_has_more_rows_in_result_response(
10751075

10761076
self.assertEqual(has_more_rows, has_more_rows_resp)
10771077

1078-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1078+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
10791079
def test_arrow_batches_row_count_are_respected(self, tcli_service_class):
10801080
# make some semi-real arrow batches and check the number of rows is correct in the queue
10811081
tcli_service_instance = tcli_service_class.return_value
@@ -1128,7 +1128,7 @@ def test_arrow_batches_row_count_are_respected(self, tcli_service_class):
11281128

11291129
self.assertEqual(arrow_queue.n_valid_rows, 15 * 10)
11301130

1131-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1131+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
11321132
def test_execute_statement_calls_client_and_handle_execute_response(
11331133
self, tcli_service_class
11341134
):
@@ -1157,7 +1157,7 @@ def test_execute_statement_calls_client_and_handle_execute_response(
11571157
response, cursor_mock
11581158
)
11591159

1160-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1160+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
11611161
def test_get_catalogs_calls_client_and_handle_execute_response(
11621162
self, tcli_service_class
11631163
):
@@ -1185,7 +1185,7 @@ def test_get_catalogs_calls_client_and_handle_execute_response(
11851185
response, cursor_mock
11861186
)
11871187

1188-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1188+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
11891189
def test_get_schemas_calls_client_and_handle_execute_response(
11901190
self, tcli_service_class
11911191
):
@@ -1222,7 +1222,7 @@ def test_get_schemas_calls_client_and_handle_execute_response(
12221222
response, cursor_mock
12231223
)
12241224

1225-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1225+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
12261226
def test_get_tables_calls_client_and_handle_execute_response(
12271227
self, tcli_service_class
12281228
):
@@ -1263,7 +1263,7 @@ def test_get_tables_calls_client_and_handle_execute_response(
12631263
response, cursor_mock
12641264
)
12651265

1266-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1266+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
12671267
def test_get_columns_calls_client_and_handle_execute_response(
12681268
self, tcli_service_class
12691269
):
@@ -1304,7 +1304,7 @@ def test_get_columns_calls_client_and_handle_execute_response(
13041304
response, cursor_mock
13051305
)
13061306

1307-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1307+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
13081308
def test_open_session_user_provided_session_id_optional(self, tcli_service_class):
13091309
tcli_service_instance = tcli_service_class.return_value
13101310
tcli_service_instance.OpenSession.return_value = self.open_session_resp
@@ -1320,7 +1320,7 @@ def test_open_session_user_provided_session_id_optional(self, tcli_service_class
13201320
thrift_backend.open_session({}, None, None)
13211321
self.assertEqual(len(tcli_service_instance.OpenSession.call_args_list), 1)
13221322

1323-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1323+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
13241324
def test_op_handle_respected_in_close_command(self, tcli_service_class):
13251325
tcli_service_instance = tcli_service_class.return_value
13261326
thrift_backend = ThriftDatabricksClient(
@@ -1337,7 +1337,7 @@ def test_op_handle_respected_in_close_command(self, tcli_service_class):
13371337
self.operation_handle,
13381338
)
13391339

1340-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1340+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
13411341
def test_session_handle_respected_in_close_session(self, tcli_service_class):
13421342
tcli_service_instance = tcli_service_class.return_value
13431343
thrift_backend = ThriftDatabricksClient(
@@ -1354,7 +1354,7 @@ def test_session_handle_respected_in_close_session(self, tcli_service_class):
13541354
self.session_handle,
13551355
)
13561356

1357-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1357+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
13581358
def test_non_arrow_non_column_based_set_triggers_exception(
13591359
self, tcli_service_class
13601360
):
@@ -1403,8 +1403,8 @@ def test_create_arrow_table_raises_error_for_unsupported_type(self):
14031403
with self.assertRaises(OperationalError):
14041404
thrift_backend._create_arrow_table(t_row_set, Mock(), None, Mock())
14051405

1406-
@patch("databricks.sql.thrift_backend.convert_arrow_based_set_to_arrow_table")
1407-
@patch("databricks.sql.thrift_backend.convert_column_based_set_to_arrow_table")
1406+
@patch("databricks.sql.backend.thrift_backend.convert_arrow_based_set_to_arrow_table")
1407+
@patch("databricks.sql.backend.thrift_backend.convert_column_based_set_to_arrow_table")
14081408
def test_create_arrow_table_calls_correct_conversion_method(
14091409
self, convert_col_mock, convert_arrow_mock
14101410
):
@@ -1597,7 +1597,7 @@ def test_convert_column_based_set_to_arrow_table_uses_types_from_col_set(self):
15971597
self.assertEqual(arrow_table.column(2).to_pylist(), [1.15, 2.2, 3.3])
15981598
self.assertEqual(arrow_table.column(3).to_pylist(), [b"\x11", b"\x22", b"\x33"])
15991599

1600-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1600+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
16011601
def test_cancel_command_uses_active_op_handle(self, tcli_service_class):
16021602
tcli_service_instance = tcli_service_class.return_value
16031603

@@ -1627,7 +1627,7 @@ def test_handle_execute_response_sets_active_op_handle(self):
16271627
"databricks.sql.thrift_api.TCLIService.TCLIService.Client.GetOperationStatus"
16281628
)
16291629
@patch(
1630-
"databricks.sql.thrift_backend._retry_policy", new_callable=retry_policy_factory
1630+
"databricks.sql.backend.thrift_backend._retry_policy", new_callable=retry_policy_factory
16311631
)
16321632
def test_make_request_will_retry_GetOperationStatus(
16331633
self, mock_retry_policy, mock_GetOperationStatus, t_transport_class
@@ -1681,7 +1681,7 @@ def test_make_request_will_retry_GetOperationStatus(
16811681
)
16821682

16831683
with self.assertLogs(
1684-
"databricks.sql.thrift_backend", level=logging.WARNING
1684+
"databricks.sql.backend.thrift_backend", level=logging.WARNING
16851685
) as cm:
16861686
with self.assertRaises(RequestError):
16871687
thrift_backend.make_request(client.GetOperationStatus, req)
@@ -1702,7 +1702,7 @@ def test_make_request_will_retry_GetOperationStatus(
17021702
"databricks.sql.thrift_api.TCLIService.TCLIService.Client.GetOperationStatus"
17031703
)
17041704
@patch(
1705-
"databricks.sql.thrift_backend._retry_policy", new_callable=retry_policy_factory
1705+
"databricks.sql.backend.thrift_backend._retry_policy", new_callable=retry_policy_factory
17061706
)
17071707
def test_make_request_will_retry_GetOperationStatus_for_http_error(
17081708
self, mock_retry_policy, mock_gos
@@ -1779,7 +1779,7 @@ def test_make_request_wont_retry_if_error_code_not_429_or_503(
17791779

17801780
@patch("databricks.sql.auth.thrift_http_client.THttpClient")
17811781
@patch(
1782-
"databricks.sql.thrift_backend._retry_policy", new_callable=retry_policy_factory
1782+
"databricks.sql.backend.thrift_backend._retry_policy", new_callable=retry_policy_factory
17831783
)
17841784
def test_make_request_will_retry_stop_after_attempts_count_if_retryable(
17851785
self, mock_retry_policy, t_transport_class
@@ -1959,7 +1959,7 @@ def test_retry_args_passthrough(self, mock_http_client):
19591959
@patch("thrift.transport.THttpClient.THttpClient")
19601960
def test_retry_args_bounding(self, mock_http_client):
19611961
retry_delay_test_args_and_expected_values = {}
1962-
for k, (_, _, min, max) in databricks.sql.thrift_backend._retry_policy.items():
1962+
for k, (_, _, min, max) in databricks.sql.backend.thrift_backend._retry_policy.items():
19631963
retry_delay_test_args_and_expected_values[k] = (
19641964
(min - 1, min),
19651965
(max + 1, max),
@@ -1986,7 +1986,7 @@ def test_retry_args_bounding(self, mock_http_client):
19861986
for arg, val in retry_delay_expected_vals.items():
19871987
self.assertEqual(getattr(backend, arg), val)
19881988

1989-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
1989+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
19901990
def test_configuration_passthrough(self, tcli_client_class):
19911991
tcli_service_instance = tcli_client_class.return_value
19921992
tcli_service_instance.OpenSession.return_value = self.open_session_resp
@@ -2011,7 +2011,7 @@ def test_configuration_passthrough(self, tcli_client_class):
20112011
open_session_req = tcli_client_class.return_value.OpenSession.call_args[0][0]
20122012
self.assertEqual(open_session_req.configuration, expected_config)
20132013

2014-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2014+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
20152015
def test_cant_set_timestamp_as_string_to_true(self, tcli_client_class):
20162016
tcli_service_instance = tcli_client_class.return_value
20172017
tcli_service_instance.OpenSession.return_value = self.open_session_resp
@@ -2038,7 +2038,7 @@ def _construct_open_session_with_namespace(self, can_use_multiple_cats, cat, sch
20382038
initialNamespace=ttypes.TNamespace(catalogName=cat, schemaName=schem),
20392039
)
20402040

2041-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2041+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
20422042
def test_initial_namespace_passthrough_to_open_session(self, tcli_client_class):
20432043
tcli_service_instance = tcli_client_class.return_value
20442044

@@ -2066,7 +2066,7 @@ def test_initial_namespace_passthrough_to_open_session(self, tcli_client_class):
20662066
self.assertEqual(open_session_req.initialNamespace.catalogName, cat)
20672067
self.assertEqual(open_session_req.initialNamespace.schemaName, schem)
20682068

2069-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2069+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
20702070
def test_can_use_multiple_catalogs_is_set_in_open_session_req(
20712071
self, tcli_client_class
20722072
):
@@ -2086,7 +2086,7 @@ def test_can_use_multiple_catalogs_is_set_in_open_session_req(
20862086
open_session_req = tcli_client_class.return_value.OpenSession.call_args[0][0]
20872087
self.assertTrue(open_session_req.canUseMultipleCatalogs)
20882088

2089-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2089+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
20902090
def test_can_use_multiple_catalogs_is_false_fails_with_initial_catalog(
20912091
self, tcli_client_class
20922092
):
@@ -2126,7 +2126,7 @@ def test_can_use_multiple_catalogs_is_false_fails_with_initial_catalog(
21262126
)
21272127
backend.open_session({}, cat, schem)
21282128

2129-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2129+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
21302130
def test_protocol_v3_fails_if_initial_namespace_set(self, tcli_client_class):
21312131
tcli_service_instance = tcli_client_class.return_value
21322132

@@ -2154,8 +2154,8 @@ def test_protocol_v3_fails_if_initial_namespace_set(self, tcli_client_class):
21542154
str(cm.exception),
21552155
)
21562156

2157-
@patch("databricks.sql.thrift_backend.TCLIService.Client", autospec=True)
2158-
@patch("databricks.sql.thrift_backend.ThriftDatabricksClient._handle_execute_response")
2157+
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
2158+
@patch("databricks.sql.backend.thrift_backend.ThriftDatabricksClient._handle_execute_response")
21592159
def test_execute_command_sets_complex_type_fields_correctly(
21602160
self, mock_handle_execute_response, tcli_service_class
21612161
):

0 commit comments

Comments
 (0)