66logging .basicConfig (level = logging .DEBUG )
77logger = logging .getLogger (__name__ )
88
9+
910def test_sea_query_execution ():
1011 """
1112 Test executing a query using the SEA backend.
12-
13+
1314 This function connects to a Databricks SQL endpoint using the SEA backend,
1415 executes a simple query, and verifies that execution completes successfully.
1516 """
1617 server_hostname = os .environ .get ("DATABRICKS_SERVER_HOSTNAME" )
1718 http_path = os .environ .get ("DATABRICKS_HTTP_PATH" )
1819 access_token = os .environ .get ("DATABRICKS_TOKEN" )
1920 catalog = os .environ .get ("DATABRICKS_CATALOG" )
20-
21+
2122 if not all ([server_hostname , http_path , access_token ]):
2223 logger .error ("Missing required environment variables." )
23- logger .error ("Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN." )
24+ logger .error (
25+ "Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN."
26+ )
2427 sys .exit (1 )
25-
28+
2629 try :
2730 # Create connection with SEA backend
2831 connection = Connection (
@@ -32,41 +35,46 @@ def test_sea_query_execution():
3235 catalog = catalog ,
3336 schema = "default" ,
3437 use_sea = True ,
35- user_agent_entry = "SEA-Test-Client"
38+ user_agent_entry = "SEA-Test-Client" ,
39+ use_cloud_fetch = False ,
40+ )
41+
42+ logger .info (
43+ f"Successfully opened SEA session with ID: { connection .get_session_id_hex ()} "
3644 )
37-
38- logger .info (f"Successfully opened SEA session with ID: { connection .get_session_id_hex ()} " )
3945 logger .info (f"backend type: { type (connection .session .backend )} " )
40-
46+
4147 # Create a cursor and execute a simple query
42- cursor = connection .cursor ()
43-
48+ cursor = connection .cursor (buffer_size_bytes = 0 )
49+
4450 logger .info ("Executing query: SELECT 1 as test_value" )
4551 cursor .execute ("SELECT 1 as test_value" )
46-
52+
4753 # We don't fetch results yet since we haven't implemented the fetch functionality
4854 logger .info ("Query executed successfully" )
49-
55+
5056 # Close cursor and connection
5157 cursor .close ()
5258 connection .close ()
5359 logger .info ("Successfully closed SEA session" )
54-
60+
5561 except Exception as e :
5662 logger .error (f"Error during SEA query execution test: { str (e )} " )
5763 import traceback
64+
5865 logger .error (traceback .format_exc ())
5966 sys .exit (1 )
60-
67+
6168 logger .info ("SEA query execution test completed successfully" )
6269
70+
6371def test_sea_session ():
6472 """
6573 Test opening and closing a SEA session using the connector.
66-
74+
6775 This function connects to a Databricks SQL endpoint using the SEA backend,
6876 opens a session, and then closes it.
69-
77+
7078 Required environment variables:
7179 - DATABRICKS_SERVER_HOSTNAME: Databricks server hostname
7280 - DATABRICKS_HTTP_PATH: HTTP path for the SQL endpoint
@@ -76,17 +84,19 @@ def test_sea_session():
7684 http_path = os .environ .get ("DATABRICKS_HTTP_PATH" )
7785 access_token = os .environ .get ("DATABRICKS_TOKEN" )
7886 catalog = os .environ .get ("DATABRICKS_CATALOG" )
79-
87+
8088 if not all ([server_hostname , http_path , access_token ]):
8189 logger .error ("Missing required environment variables." )
82- logger .error ("Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN." )
90+ logger .error (
91+ "Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN."
92+ )
8393 sys .exit (1 )
84-
94+
8595 logger .info (f"Connecting to { server_hostname } " )
8696 logger .info (f"HTTP Path: { http_path } " )
8797 if catalog :
8898 logger .info (f"Using catalog: { catalog } " )
89-
99+
90100 try :
91101 logger .info ("Creating connection with SEA backend..." )
92102 connection = Connection (
@@ -95,29 +105,33 @@ def test_sea_session():
95105 access_token = access_token ,
96106 catalog = catalog ,
97107 schema = "default" ,
98- use_sea = True ,
99- user_agent_entry = "SEA-Test-Client" # add custom user agent
108+ use_sea = True ,
109+ user_agent_entry = "SEA-Test-Client" , # add custom user agent
110+ )
111+
112+ logger .info (
113+ f"Successfully opened SEA session with ID: { connection .get_session_id_hex ()} "
100114 )
101-
102- logger .info (f"Successfully opened SEA session with ID: { connection .get_session_id_hex ()} " )
103115 logger .info (f"backend type: { type (connection .session .backend )} " )
104-
116+
105117 # Close the connection
106118 logger .info ("Closing the SEA session..." )
107119 connection .close ()
108120 logger .info ("Successfully closed SEA session" )
109-
121+
110122 except Exception as e :
111123 logger .error (f"Error testing SEA session: { str (e )} " )
112124 import traceback
125+
113126 logger .error (traceback .format_exc ())
114127 sys .exit (1 )
115-
128+
116129 logger .info ("SEA session test completed successfully" )
117130
131+
118132if __name__ == "__main__" :
119133 # Test session management
120134 test_sea_session ()
121-
135+
122136 # Test query execution
123- test_sea_query_execution ()
137+ test_sea_query_execution ()
0 commit comments