55the Databricks SQL connector's SEA backend functionality.
66"""
77
8+ import json
89import pytest
910from unittest .mock import patch , MagicMock , Mock
1011
1112from databricks .sql .backend .sea_backend import SeaDatabricksClient
13+ from databricks .sql .backend .sea_result_set import SeaResultSet
1214from databricks .sql .backend .types import SessionId , CommandId , CommandState , BackendType
1315from databricks .sql .types import SSLOptions
1416from databricks .sql .auth .authenticators import AuthProvider
@@ -178,7 +180,7 @@ def test_close_session_valid_id(self, sea_client, mock_http_client):
178180 mock_http_client ._make_request .assert_called_once_with (
179181 method = "DELETE" ,
180182 path = sea_client .SESSION_PATH_WITH_ID .format ("test-session-789" ),
181- data = {"warehouse_id" : "abc123" },
183+ data = {"session_id" : "test-session-789" , " warehouse_id" : "abc123" },
182184 )
183185
184186 def test_close_session_invalid_id_type (self , sea_client ):
@@ -451,8 +453,6 @@ def test_cancel_command(self, sea_client, mock_http_client, sea_command_id):
451453 assert kwargs ["path" ] == sea_client .CANCEL_STATEMENT_PATH_WITH_ID .format (
452454 "test-statement-123"
453455 )
454- assert "warehouse_id" in kwargs ["data" ]
455- assert kwargs ["data" ]["warehouse_id" ] == "abc123"
456456
457457 def test_close_command (self , sea_client , mock_http_client , sea_command_id ):
458458 """Test closing a command."""
@@ -469,8 +469,6 @@ def test_close_command(self, sea_client, mock_http_client, sea_command_id):
469469 assert kwargs ["path" ] == sea_client .STATEMENT_PATH_WITH_ID .format (
470470 "test-statement-123"
471471 )
472- assert "warehouse_id" in kwargs ["data" ]
473- assert kwargs ["data" ]["warehouse_id" ] == "abc123"
474472
475473 def test_get_query_state (self , sea_client , mock_http_client , sea_command_id ):
476474 """Test getting the state of a query."""
@@ -493,40 +491,50 @@ def test_get_query_state(self, sea_client, mock_http_client, sea_command_id):
493491 assert kwargs ["path" ] == sea_client .STATEMENT_PATH_WITH_ID .format (
494492 "test-statement-123"
495493 )
496- assert "warehouse_id" in kwargs ["data" ]
497- assert kwargs ["data" ]["warehouse_id" ] == "abc123"
498494
499495 def test_get_execution_result (
500496 self , sea_client , mock_http_client , mock_cursor , sea_command_id
501497 ):
502498 """Test getting the result of a command execution."""
503499 # Set up mock response
504- mock_http_client . _make_request . return_value = {
500+ sea_response = {
505501 "statement_id" : "test-statement-123" ,
506502 "status" : {"state" : "SUCCEEDED" },
507503 "manifest" : {
508- "schema" : [
509- {
510- "name" : "col1" ,
511- "type_name" : "STRING" ,
512- "type_text" : "string" ,
513- "nullable" : True ,
514- }
515- ],
504+ "format" : "JSON_ARRAY" ,
505+ "schema" : {
506+ "column_count" : 1 ,
507+ "columns" : [
508+ {
509+ "name" : "test_value" ,
510+ "type_text" : "INT" ,
511+ "type_name" : "INT" ,
512+ "position" : 0 ,
513+ }
514+ ],
515+ },
516+ "total_chunk_count" : 1 ,
517+ "chunks" : [{"chunk_index" : 0 , "row_offset" : 0 , "row_count" : 1 }],
516518 "total_row_count" : 1 ,
517- "total_byte_count" : 100 ,
519+ "truncated" : False ,
520+ },
521+ "result" : {
522+ "chunk_index" : 0 ,
523+ "row_offset" : 0 ,
524+ "row_count" : 1 ,
525+ "data_array" : [["1" ]],
518526 },
519- "result" : {"data" : [["value1" ]]},
520527 }
528+ mock_http_client ._make_request .return_value = sea_response
521529
522530 # Create a real result set to verify the implementation
523531 result = sea_client .get_execution_result (sea_command_id , mock_cursor )
532+ print (result )
524533
525534 # Verify basic properties of the result
526535 assert result .statement_id == "test-statement-123"
527536 assert result .status .state == CommandState .SUCCEEDED
528- assert len (result .description ) == 1
529- assert result .description [0 ][0 ] == "col1" # column name
537+ assert result .manifest .schema [0 ].name == "test_value"
530538
531539 # Verify the HTTP request
532540 mock_http_client ._make_request .assert_called_once ()
@@ -535,8 +543,6 @@ def test_get_execution_result(
535543 assert kwargs ["path" ] == sea_client .STATEMENT_PATH_WITH_ID .format (
536544 "test-statement-123"
537545 )
538- assert "warehouse_id" in kwargs ["data" ]
539- assert kwargs ["data" ]["warehouse_id" ] == "abc123"
540546
541547 # Tests for metadata operations
542548
0 commit comments