15
15
from databricks .sql .client import Cursor
16
16
17
17
from databricks .sql .thrift_api .TCLIService import ttypes
18
- from databricks .sql .backend .types import SessionId , CommandId
18
+ from databricks .sql .backend .types import SessionId , CommandId , CommandState
19
19
from databricks .sql .utils import ExecuteResponse
20
20
from databricks .sql .types import SSLOptions
21
21
22
+ # Forward reference for type hints
23
+ from typing import TYPE_CHECKING
24
+
25
+ if TYPE_CHECKING :
26
+ from databricks .sql .result_set import ResultSet
27
+
22
28
23
29
class DatabricksClient (ABC ):
24
30
# == Connection and Session Management ==
@@ -81,7 +87,7 @@ def execute_command(
81
87
parameters : List [ttypes .TSparkParameter ],
82
88
async_op : bool ,
83
89
enforce_embedded_schema_correctness : bool ,
84
- ) -> Optional [ ExecuteResponse ]:
90
+ ) -> Union [ "ResultSet" , None ]:
85
91
"""
86
92
Executes a SQL command or query within the specified session.
87
93
@@ -101,7 +107,7 @@ def execute_command(
101
107
enforce_embedded_schema_correctness: Whether to enforce schema correctness
102
108
103
109
Returns:
104
- If async_op is False, returns an ExecuteResponse object containing the
110
+ If async_op is False, returns a ResultSet object containing the
105
111
query results and metadata. If async_op is True, returns None and the
106
112
results must be fetched later using get_execution_result().
107
113
@@ -130,7 +136,7 @@ def cancel_command(self, command_id: CommandId) -> None:
130
136
pass
131
137
132
138
@abstractmethod
133
- def close_command (self , command_id : CommandId ) -> ttypes . TStatus :
139
+ def close_command (self , command_id : CommandId ) -> None :
134
140
"""
135
141
Closes a command and releases associated resources.
136
142
@@ -140,17 +146,14 @@ def close_command(self, command_id: CommandId) -> ttypes.TStatus:
140
146
Args:
141
147
command_id: The command identifier to close
142
148
143
- Returns:
144
- ttypes.TStatus: The status of the close operation
145
-
146
149
Raises:
147
150
ValueError: If the command ID is invalid
148
151
OperationalError: If there's an error closing the command
149
152
"""
150
153
pass
151
154
152
155
@abstractmethod
153
- def get_query_state (self , command_id : CommandId ) -> ttypes . TOperationState :
156
+ def get_query_state (self , command_id : CommandId ) -> CommandState :
154
157
"""
155
158
Gets the current state of a query or command.
156
159
@@ -160,7 +163,7 @@ def get_query_state(self, command_id: CommandId) -> ttypes.TOperationState:
160
163
command_id: The command identifier to check
161
164
162
165
Returns:
163
- ttypes.TOperationState : The current state of the command
166
+ CommandState : The current state of the command
164
167
165
168
Raises:
166
169
ValueError: If the command ID is invalid
@@ -175,7 +178,7 @@ def get_execution_result(
175
178
self ,
176
179
command_id : CommandId ,
177
180
cursor : "Cursor" ,
178
- ) -> ExecuteResponse :
181
+ ) -> "ResultSet" :
179
182
"""
180
183
Retrieves the results of a previously executed command.
181
184
@@ -187,7 +190,7 @@ def get_execution_result(
187
190
cursor: The cursor object that will handle the results
188
191
189
192
Returns:
190
- ExecuteResponse : An object containing the query results and metadata
193
+ ResultSet : An object containing the query results and metadata
191
194
192
195
Raises:
193
196
ValueError: If the command ID is invalid
@@ -203,7 +206,7 @@ def get_catalogs(
203
206
max_rows : int ,
204
207
max_bytes : int ,
205
208
cursor : "Cursor" ,
206
- ) -> ExecuteResponse :
209
+ ) -> "ResultSet" :
207
210
"""
208
211
Retrieves a list of available catalogs.
209
212
@@ -217,7 +220,7 @@ def get_catalogs(
217
220
cursor: The cursor object that will handle the results
218
221
219
222
Returns:
220
- ExecuteResponse : An object containing the catalog metadata
223
+ ResultSet : An object containing the catalog metadata
221
224
222
225
Raises:
223
226
ValueError: If the session ID is invalid
@@ -234,7 +237,7 @@ def get_schemas(
234
237
cursor : "Cursor" ,
235
238
catalog_name : Optional [str ] = None ,
236
239
schema_name : Optional [str ] = None ,
237
- ) -> ExecuteResponse :
240
+ ) -> "ResultSet" :
238
241
"""
239
242
Retrieves a list of schemas, optionally filtered by catalog and schema name patterns.
240
243
@@ -250,7 +253,7 @@ def get_schemas(
250
253
schema_name: Optional schema name pattern to filter by
251
254
252
255
Returns:
253
- ExecuteResponse : An object containing the schema metadata
256
+ ResultSet : An object containing the schema metadata
254
257
255
258
Raises:
256
259
ValueError: If the session ID is invalid
@@ -269,7 +272,7 @@ def get_tables(
269
272
schema_name : Optional [str ] = None ,
270
273
table_name : Optional [str ] = None ,
271
274
table_types : Optional [List [str ]] = None ,
272
- ) -> ExecuteResponse :
275
+ ) -> "ResultSet" :
273
276
"""
274
277
Retrieves a list of tables, optionally filtered by catalog, schema, table name, and table types.
275
278
@@ -287,7 +290,7 @@ def get_tables(
287
290
table_types: Optional list of table types to filter by (e.g., ['TABLE', 'VIEW'])
288
291
289
292
Returns:
290
- ExecuteResponse : An object containing the table metadata
293
+ ResultSet : An object containing the table metadata
291
294
292
295
Raises:
293
296
ValueError: If the session ID is invalid
@@ -306,7 +309,7 @@ def get_columns(
306
309
schema_name : Optional [str ] = None ,
307
310
table_name : Optional [str ] = None ,
308
311
column_name : Optional [str ] = None ,
309
- ) -> ExecuteResponse :
312
+ ) -> "ResultSet" :
310
313
"""
311
314
Retrieves a list of columns, optionally filtered by catalog, schema, table, and column name patterns.
312
315
@@ -324,7 +327,7 @@ def get_columns(
324
327
column_name: Optional column name pattern to filter by
325
328
326
329
Returns:
327
- ExecuteResponse : An object containing the column metadata
330
+ ResultSet : An object containing the column metadata
328
331
329
332
Raises:
330
333
ValueError: If the session ID is invalid
0 commit comments