Skip to content

Commit f23ef8f

Browse files
introduce req resp models, update example tester script
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 1da5694 commit f23ef8f

File tree

9 files changed

+272
-354
lines changed

9 files changed

+272
-354
lines changed

examples/experimental/sea_connector_test.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,26 @@
66
logging.basicConfig(level=logging.DEBUG)
77
logger = logging.getLogger(__name__)
88

9+
910
def 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+
6371
def 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+
118132
if __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()

src/databricks/sql/backend/models/__init__.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ExternalLink,
1111
ResultData,
1212
ColumnInfo,
13-
ResultManifest
13+
ResultManifest,
1414
)
1515

1616
from databricks.sql.backend.models.requests import (
@@ -20,35 +20,33 @@
2020
CancelStatementRequest,
2121
CloseStatementRequest,
2222
CreateSessionRequest,
23-
DeleteSessionRequest
23+
DeleteSessionRequest,
2424
)
2525

2626
from databricks.sql.backend.models.responses import (
2727
ExecuteStatementResponse,
2828
GetStatementResponse,
29-
CreateSessionResponse
29+
CreateSessionResponse,
3030
)
3131

3232
__all__ = [
3333
# Base models
34-
'ServiceError',
35-
'StatementStatus',
36-
'ExternalLink',
37-
'ResultData',
38-
'ColumnInfo',
39-
'ResultManifest',
40-
34+
"ServiceError",
35+
"StatementStatus",
36+
"ExternalLink",
37+
"ResultData",
38+
"ColumnInfo",
39+
"ResultManifest",
4140
# Request models
42-
'StatementParameter',
43-
'ExecuteStatementRequest',
44-
'GetStatementRequest',
45-
'CancelStatementRequest',
46-
'CloseStatementRequest',
47-
'CreateSessionRequest',
48-
'DeleteSessionRequest',
49-
41+
"StatementParameter",
42+
"ExecuteStatementRequest",
43+
"GetStatementRequest",
44+
"CancelStatementRequest",
45+
"CloseStatementRequest",
46+
"CreateSessionRequest",
47+
"DeleteSessionRequest",
5048
# Response models
51-
'ExecuteStatementResponse',
52-
'GetStatementResponse',
53-
'CreateSessionResponse'
54-
]
49+
"ExecuteStatementResponse",
50+
"GetStatementResponse",
51+
"CreateSessionResponse",
52+
]

src/databricks/sql/backend/models/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
@dataclass
1212
class ServiceError:
1313
"""Error information returned by the SEA API."""
14+
1415
message: str
1516
error_code: Optional[str] = None
1617

1718

1819
@dataclass
1920
class StatementStatus:
2021
"""Status information for a statement execution."""
22+
2123
state: str
2224
error: Optional[ServiceError] = None
2325
sql_state: Optional[str] = None
@@ -26,6 +28,7 @@ class StatementStatus:
2628
@dataclass
2729
class ExternalLink:
2830
"""External link information for result data."""
31+
2932
external_link: str
3033
expiration: str
3134
chunk_index: int
@@ -34,13 +37,15 @@ class ExternalLink:
3437
@dataclass
3538
class ResultData:
3639
"""Result data from a statement execution."""
40+
3741
data: Optional[List[List[Any]]] = None
3842
external_links: Optional[List[ExternalLink]] = None
3943

4044

4145
@dataclass
4246
class ColumnInfo:
4347
"""Information about a column in the result set."""
48+
4449
name: str
4550
type_name: str
4651
type_text: str
@@ -53,8 +58,9 @@ class ColumnInfo:
5358
@dataclass
5459
class ResultManifest:
5560
"""Manifest information for a result set."""
61+
5662
schema: List[ColumnInfo]
5763
total_row_count: int
5864
total_byte_count: int
5965
truncated: bool = False
60-
chunk_count: Optional[int] = None
66+
chunk_count: Optional[int] = None

0 commit comments

Comments
 (0)