11
11
"""
12
12
13
13
from abc import ABC , abstractmethod
14
- from typing import Dict , Tuple , List , Optional , Any , Union
14
+ from typing import Dict , Tuple , List , Optional , Any , Union , TYPE_CHECKING
15
+
16
+ if TYPE_CHECKING :
17
+ from databricks .sql .client import Cursor
15
18
16
- from databricks .sql .client import Cursor
17
19
from databricks .sql .thrift_api .TCLIService import ttypes
18
20
from databricks .sql .backend .types import SessionId , CommandId
19
21
from databricks .sql .utils import ExecuteResponse
@@ -76,7 +78,7 @@ def execute_command(
76
78
max_rows : int ,
77
79
max_bytes : int ,
78
80
lz4_compression : bool ,
79
- cursor : Cursor ,
81
+ cursor : " Cursor" ,
80
82
use_cloud_fetch : bool ,
81
83
parameters : List [ttypes .TSparkParameter ],
82
84
async_op : bool ,
@@ -174,7 +176,7 @@ def get_query_state(self, command_id: CommandId) -> ttypes.TOperationState:
174
176
def get_execution_result (
175
177
self ,
176
178
command_id : CommandId ,
177
- cursor : Cursor ,
179
+ cursor : " Cursor" ,
178
180
) -> ExecuteResponse :
179
181
"""
180
182
Retrieves the results of a previously executed command.
@@ -202,13 +204,13 @@ def get_catalogs(
202
204
session_id : SessionId ,
203
205
max_rows : int ,
204
206
max_bytes : int ,
205
- cursor : Cursor ,
207
+ cursor : " Cursor" ,
206
208
) -> ExecuteResponse :
207
209
"""
208
210
Retrieves a list of available catalogs.
209
211
210
- This method fetches metadata about the catalogs that are available
211
- in the current session.
212
+ This method fetches metadata about all catalogs available in the current
213
+ session's context .
212
214
213
215
Args:
214
216
session_id: The session identifier
@@ -231,23 +233,23 @@ def get_schemas(
231
233
session_id : SessionId ,
232
234
max_rows : int ,
233
235
max_bytes : int ,
234
- cursor : Cursor ,
236
+ cursor : " Cursor" ,
235
237
catalog_name : Optional [str ] = None ,
236
238
schema_name : Optional [str ] = None ,
237
239
) -> ExecuteResponse :
238
240
"""
239
- Retrieves a list of available schemas.
241
+ Retrieves a list of schemas, optionally filtered by catalog and schema name patterns .
240
242
241
- This method fetches metadata about the schemas that are available
242
- in the specified catalog.
243
+ This method fetches metadata about schemas available in the specified catalog
244
+ or all catalogs if no catalog is specified .
243
245
244
246
Args:
245
247
session_id: The session identifier
246
248
max_rows: Maximum number of rows to fetch in a single batch
247
249
max_bytes: Maximum number of bytes to fetch in a single batch
248
250
cursor: The cursor object that will handle the results
249
- catalog_name: Optional catalog name to filter schemas
250
- schema_name: Optional schema pattern to filter schemas by name
251
+ catalog_name: Optional catalog name pattern to filter by
252
+ schema_name: Optional schema name pattern to filter by
251
253
252
254
Returns:
253
255
ExecuteResponse: An object containing the schema metadata
@@ -264,27 +266,27 @@ def get_tables(
264
266
session_id : SessionId ,
265
267
max_rows : int ,
266
268
max_bytes : int ,
267
- cursor : Cursor ,
269
+ cursor : " Cursor" ,
268
270
catalog_name : Optional [str ] = None ,
269
271
schema_name : Optional [str ] = None ,
270
272
table_name : Optional [str ] = None ,
271
273
table_types : Optional [List [str ]] = None ,
272
274
) -> ExecuteResponse :
273
275
"""
274
- Retrieves a list of available tables.
276
+ Retrieves a list of tables, optionally filtered by catalog, schema, table name, and table types .
275
277
276
- This method fetches metadata about the tables that are available
277
- in the specified catalog and schema .
278
+ This method fetches metadata about tables available in the specified catalog
279
+ and schema, or all catalogs and schemas if not specified .
278
280
279
281
Args:
280
282
session_id: The session identifier
281
283
max_rows: Maximum number of rows to fetch in a single batch
282
284
max_bytes: Maximum number of bytes to fetch in a single batch
283
285
cursor: The cursor object that will handle the results
284
- catalog_name: Optional catalog name to filter tables
285
- schema_name: Optional schema name to filter tables
286
- table_name: Optional table pattern to filter tables by name
287
- table_types: Optional list of table types to include (e.g., " TABLE", " VIEW" )
286
+ catalog_name: Optional catalog name pattern to filter by
287
+ schema_name: Optional schema name pattern to filter by
288
+ table_name: Optional table name pattern to filter by
289
+ table_types: Optional list of table types to filter by (e.g., [' TABLE', ' VIEW'] )
288
290
289
291
Returns:
290
292
ExecuteResponse: An object containing the table metadata
@@ -301,27 +303,27 @@ def get_columns(
301
303
session_id : SessionId ,
302
304
max_rows : int ,
303
305
max_bytes : int ,
304
- cursor : Cursor ,
306
+ cursor : " Cursor" ,
305
307
catalog_name : Optional [str ] = None ,
306
308
schema_name : Optional [str ] = None ,
307
309
table_name : Optional [str ] = None ,
308
310
column_name : Optional [str ] = None ,
309
311
) -> ExecuteResponse :
310
312
"""
311
- Retrieves column metadata for tables .
313
+ Retrieves a list of columns, optionally filtered by catalog, schema, table, and column name patterns .
312
314
313
- This method fetches metadata about the columns in the specified
314
- catalog, schema, and table .
315
+ This method fetches metadata about columns available in the specified table,
316
+ or all tables if not specified .
315
317
316
318
Args:
317
319
session_id: The session identifier
318
320
max_rows: Maximum number of rows to fetch in a single batch
319
321
max_bytes: Maximum number of bytes to fetch in a single batch
320
322
cursor: The cursor object that will handle the results
321
- catalog_name: Optional catalog name to filter columns
322
- schema_name: Optional schema name to filter columns
323
- table_name: Optional table name to filter columns
324
- column_name: Optional column pattern to filter columns by name
323
+ catalog_name: Optional catalog name pattern to filter by
324
+ schema_name: Optional schema name pattern to filter by
325
+ table_name: Optional table name pattern to filter by
326
+ column_name: Optional column name pattern to filter by
325
327
326
328
Returns:
327
329
ExecuteResponse: An object containing the column metadata
@@ -332,68 +334,24 @@ def get_columns(
332
334
"""
333
335
pass
334
336
335
- # == Utility Methods ==
336
- @abstractmethod
337
- def handle_to_id (self , session_id : SessionId ) -> Any :
338
- """
339
- Gets the raw session ID from a SessionId object.
340
-
341
- This method extracts the underlying protocol-specific identifier
342
- from the SessionId abstraction.
343
-
344
- Args:
345
- session_id: The session identifier
346
-
347
- Returns:
348
- The raw session ID as used by the underlying protocol
349
-
350
- Raises:
351
- ValueError: If the session ID is not valid for this client's backend type
352
- """
353
- pass
354
-
355
- @abstractmethod
356
- def handle_to_hex_id (self , session_id : SessionId ) -> str :
357
- """
358
- Gets a hexadecimal string representation of a session ID.
359
-
360
- This method converts the session ID to a human-readable hexadecimal string
361
- that can be used for logging and debugging.
362
-
363
- Args:
364
- session_id: The session identifier
365
-
366
- Returns:
367
- str: A hexadecimal string representation of the session ID
368
-
369
- Raises:
370
- ValueError: If the session ID is not valid for this client's backend type
371
- """
372
- pass
373
-
374
- # Properties related to specific backend features
337
+ # == Properties ==
375
338
@property
376
339
@abstractmethod
377
340
def staging_allowed_local_path (self ) -> Union [None , str , List [str ]]:
378
341
"""
379
- Gets the local path(s) allowed for staging data.
380
-
381
- This property returns the path or paths on the local filesystem that
382
- are allowed to be used for staging data when uploading to the server.
342
+ Gets the allowed local paths for staging operations.
383
343
384
344
Returns:
385
- Union[None, str, List[str]]: The allowed local path(s) or None if staging is not allowed
345
+ Union[None, str, List[str]]: The allowed local paths for staging operations,
346
+ or None if staging is not allowed
386
347
"""
387
348
pass
388
349
389
350
@property
390
351
@abstractmethod
391
352
def ssl_options (self ) -> SSLOptions :
392
353
"""
393
- Gets the SSL options used by this client.
394
-
395
- This property returns the SSL configuration options that are used
396
- for secure communication with the server.
354
+ Gets the SSL options for this client.
397
355
398
356
Returns:
399
357
SSLOptions: The SSL configuration options
@@ -404,10 +362,7 @@ def ssl_options(self) -> SSLOptions:
404
362
@abstractmethod
405
363
def max_download_threads (self ) -> int :
406
364
"""
407
- Gets the maximum number of threads for handling cloud fetch downloads.
408
-
409
- This property returns the maximum number of concurrent threads that
410
- can be used for downloading result data when using cloud fetch.
365
+ Gets the maximum number of download threads for cloud fetch operations.
411
366
412
367
Returns:
413
368
int: The maximum number of download threads
0 commit comments