66logging .basicConfig (level = logging .DEBUG )
77logger = logging .getLogger (__name__ )
88
9+ def test_sea_query_execution ():
10+ """
11+ Test executing a query using the SEA backend.
12+
13+ This function connects to a Databricks SQL endpoint using the SEA backend,
14+ executes a simple query, and verifies that execution completes successfully.
15+ """
16+ server_hostname = os .environ .get ("DATABRICKS_SERVER_HOSTNAME" )
17+ http_path = os .environ .get ("DATABRICKS_HTTP_PATH" )
18+ access_token = os .environ .get ("DATABRICKS_TOKEN" )
19+ catalog = os .environ .get ("DATABRICKS_CATALOG" )
20+
21+ if not all ([server_hostname , http_path , access_token ]):
22+ logger .error ("Missing required environment variables." )
23+ logger .error ("Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN." )
24+ sys .exit (1 )
25+
26+ try :
27+ # Create connection with SEA backend
28+ connection = Connection (
29+ server_hostname = server_hostname ,
30+ http_path = http_path ,
31+ access_token = access_token ,
32+ catalog = catalog ,
33+ schema = "default" ,
34+ use_sea = True ,
35+ user_agent_entry = "SEA-Test-Client"
36+ )
37+
38+ logger .info (f"Successfully opened SEA session with ID: { connection .get_session_id_hex ()} " )
39+ logger .info (f"backend type: { type (connection .session .backend )} " )
40+
41+ # Create a cursor and execute a simple query
42+ cursor = connection .cursor ()
43+
44+ logger .info ("Executing query: SELECT 1 as test_value" )
45+ cursor .execute ("SELECT 1 as test_value" )
46+
47+ # We don't fetch results yet since we haven't implemented the fetch functionality
48+ logger .info ("Query executed successfully" )
49+
50+ # Close cursor and connection
51+ cursor .close ()
52+ connection .close ()
53+ logger .info ("Successfully closed SEA session" )
54+
55+ except Exception as e :
56+ logger .error (f"Error during SEA query execution test: { str (e )} " )
57+ import traceback
58+ logger .error (traceback .format_exc ())
59+ sys .exit (1 )
60+
61+ logger .info ("SEA query execution test completed successfully" )
62+
963def test_sea_session ():
1064 """
1165 Test opening and closing a SEA session using the connector.
@@ -62,4 +116,8 @@ def test_sea_session():
62116 logger .info ("SEA session test completed successfully" )
63117
64118if __name__ == "__main__" :
65- test_sea_session ()
119+ # Test session management
120+ test_sea_session ()
121+
122+ # Test query execution
123+ test_sea_query_execution ()
0 commit comments