-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathsea_connector_test.py
More file actions
66 lines (53 loc) · 2.26 KB
/
sea_connector_test.py
File metadata and controls
66 lines (53 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import sys
import logging
from databricks.sql.client import Connection
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def test_sea_session():
"""
Test opening and closing a SEA session using the connector.
This function connects to a Databricks SQL endpoint using the SEA backend,
opens a session, and then closes it.
Required environment variables:
- DATABRICKS_SERVER_HOSTNAME: Databricks server hostname
- DATABRICKS_HTTP_PATH: HTTP path for the SQL endpoint
- DATABRICKS_TOKEN: Personal access token for authentication
"""
server_hostname = os.environ.get("DATABRICKS_SERVER_HOSTNAME")
http_path = os.environ.get("DATABRICKS_HTTP_PATH")
access_token = os.environ.get("DATABRICKS_TOKEN")
catalog = os.environ.get("DATABRICKS_CATALOG")
if not all([server_hostname, http_path, access_token]):
logger.error("Missing required environment variables.")
logger.error("Please set DATABRICKS_SERVER_HOSTNAME, DATABRICKS_HTTP_PATH, and DATABRICKS_TOKEN.")
sys.exit(1)
logger.info(f"Connecting to {server_hostname}")
logger.info(f"HTTP Path: {http_path}")
if catalog:
logger.info(f"Using catalog: {catalog}")
try:
logger.info("Creating connection with SEA backend...")
connection = Connection(
server_hostname=server_hostname,
http_path=http_path,
access_token=access_token,
catalog=catalog,
schema="default",
use_sea=True,
user_agent_entry="SEA-Test-Client" # add custom user agent
)
logger.info(f"Successfully opened SEA session with ID: {connection.get_session_id_hex()}")
logger.info(f"backend type: {type(connection.session.backend)}")
# Close the connection
logger.info("Closing the SEA session...")
connection.close()
logger.info("Successfully closed SEA session")
except Exception as e:
logger.error(f"Error testing SEA session: {str(e)}")
import traceback
logger.error(traceback.format_exc())
sys.exit(1)
logger.info("SEA session test completed successfully")
if __name__ == "__main__":
test_sea_session()