1+ """
2+ Abstract client interface for interacting with Databricks SQL services.
3+
4+ Implementations of this class are responsible for:
5+ - Managing connections to Databricks SQL services
6+ - Handling authentication
7+ - Executing SQL queries and commands
8+ - Retrieving query results
9+ - Fetching metadata about catalogs, schemas, tables, and columns
10+ - Managing error handling and retries
11+ """
12+
113from abc import ABC , abstractmethod
2- 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
318
419from databricks .sql .thrift_api .TCLIService import ttypes
520from databricks .sql .backend .types import SessionId , CommandId , CommandState
@@ -22,10 +37,42 @@ def open_session(
2237 catalog : Optional [str ],
2338 schema : Optional [str ],
2439 ) -> SessionId :
40+ """
41+ Opens a new session with the Databricks SQL service.
42+
43+ This method establishes a new session with the server and returns a session
44+ identifier that can be used for subsequent operations.
45+
46+ Args:
47+ session_configuration: Optional dictionary of configuration parameters for the session
48+ catalog: Optional catalog name to use as the initial catalog for the session
49+ schema: Optional schema name to use as the initial schema for the session
50+
51+ Returns:
52+ SessionId: A session identifier object that can be used for subsequent operations
53+
54+ Raises:
55+ Error: If the session configuration is invalid
56+ OperationalError: If there's an error establishing the session
57+ InvalidServerResponseError: If the server response is invalid or unexpected
58+ """
2559 pass
2660
2761 @abstractmethod
2862 def close_session (self , session_id : SessionId ) -> None :
63+ """
64+ Closes an existing session with the Databricks SQL service.
65+
66+ This method terminates the session identified by the given session ID and
67+ releases any resources associated with it.
68+
69+ Args:
70+ session_id: The session identifier returned by open_session()
71+
72+ Raises:
73+ ValueError: If the session ID is invalid
74+ OperationalError: If there's an error closing the session
75+ """
2976 pass
3077
3178 # == Query Execution, Command Management ==
@@ -37,7 +84,7 @@ def execute_command(
3784 max_rows : int ,
3885 max_bytes : int ,
3986 lz4_compression : bool ,
40- cursor : Any ,
87+ cursor : "Cursor" ,
4188 use_cloud_fetch : bool ,
4289 parameters : List [ttypes .TSparkParameter ],
4390 async_op : bool ,
@@ -47,6 +94,19 @@ def execute_command(
4794
4895 @abstractmethod
4996 def cancel_command (self , command_id : CommandId ) -> None :
97+ """
98+ Cancels a running command or query.
99+
100+ This method attempts to cancel a command that is currently being executed.
101+ It can be called from a different thread than the one executing the command.
102+
103+ Args:
104+ command_id: The command identifier to cancel
105+
106+ Raises:
107+ ValueError: If the command ID is invalid
108+ OperationalError: If there's an error canceling the command
109+ """
50110 pass
51111
52112 @abstractmethod
@@ -82,7 +142,7 @@ def get_schemas(
82142 session_id : SessionId ,
83143 max_rows : int ,
84144 max_bytes : int ,
85- cursor : Any ,
145+ cursor : "Cursor" ,
86146 catalog_name : Optional [str ] = None ,
87147 schema_name : Optional [str ] = None ,
88148 ) -> "ResultSet" :
@@ -94,7 +154,7 @@ def get_tables(
94154 session_id : SessionId ,
95155 max_rows : int ,
96156 max_bytes : int ,
97- cursor : Any ,
157+ cursor : "Cursor" ,
98158 catalog_name : Optional [str ] = None ,
99159 schema_name : Optional [str ] = None ,
100160 table_name : Optional [str ] = None ,
@@ -108,35 +168,45 @@ def get_columns(
108168 session_id : SessionId ,
109169 max_rows : int ,
110170 max_bytes : int ,
111- cursor : Any ,
171+ cursor : "Cursor" ,
112172 catalog_name : Optional [str ] = None ,
113173 schema_name : Optional [str ] = None ,
114174 table_name : Optional [str ] = None ,
115175 column_name : Optional [str ] = None ,
116176 ) -> "ResultSet" :
117177 pass
118178
119- # == Utility Methods ==
120- @abstractmethod
121- def handle_to_id (self , session_id : SessionId ) -> Any :
122- pass
123-
124- @abstractmethod
125- def handle_to_hex_id (self , session_id : SessionId ) -> str :
126- pass
127-
128- # Properties related to specific backend features
179+ # == Properties ==
129180 @property
130181 @abstractmethod
131182 def staging_allowed_local_path (self ) -> Union [None , str , List [str ]]:
183+ """
184+ Gets the allowed local paths for staging operations.
185+
186+ Returns:
187+ Union[None, str, List[str]]: The allowed local paths for staging operations,
188+ or None if staging is not allowed
189+ """
132190 pass
133191
134192 @property
135193 @abstractmethod
136194 def ssl_options (self ) -> SSLOptions :
195+ """
196+ Gets the SSL options for this client.
197+
198+ Returns:
199+ SSLOptions: The SSL configuration options
200+ """
137201 pass
138202
139203 @property
140204 @abstractmethod
141205 def max_download_threads (self ) -> int :
206+ """
207+ Gets the maximum number of download threads for cloud fetch operations.
208+
209+ Returns:
210+ int: The maximum number of download threads
211+ """
142212 pass
0 commit comments