Skip to content

Commit 4ec8703

Browse files
introduce databricksClient interface and thrift backend implementation
WARNING: incomplete - result set still aligned heavily with thrift and the necessity of some defined functions is to be validated Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 677e66a commit 4ec8703

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

src/databricks/sql/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ def execute(
804804
self.active_result_set = ResultSet(
805805
self.connection,
806806
execute_response,
807-
self.thrift_backend,
807+
self.backend,
808808
self.buffer_size_bytes,
809809
self.arraysize,
810810
self.connection.use_cloud_fetch,
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Dict, Tuple, List, Optional, Any, Union
3+
4+
from databricks.sql.thrift_api.TCLIService import ttypes
5+
from databricks.sql.utils import ExecuteResponse
6+
from databricks.sql.types import SSLOptions
7+
8+
9+
class DatabricksClient(ABC):
10+
# == Connection and Session Management ==
11+
@abstractmethod
12+
def open_session(
13+
self,
14+
session_configuration: Optional[Dict[str, Any]],
15+
catalog: Optional[str],
16+
schema: Optional[str],
17+
) -> ttypes.TOpenSessionResp:
18+
pass
19+
20+
@abstractmethod
21+
def close_session(self, session_handle: ttypes.TSessionHandle) -> None:
22+
pass
23+
24+
# == Query Execution, Command Management ==
25+
@abstractmethod
26+
def execute_command(
27+
self,
28+
operation: str,
29+
session_handle: ttypes.TSessionHandle,
30+
max_rows: int,
31+
max_bytes: int,
32+
lz4_compression: bool,
33+
cursor: Any,
34+
use_cloud_fetch: bool,
35+
parameters: List[ttypes.TSparkParameter],
36+
async_op: bool,
37+
enforce_embedded_schema_correctness: bool,
38+
) -> Any:
39+
pass
40+
41+
@abstractmethod
42+
def cancel_command(self, operation_handle: ttypes.TOperationHandle) -> None:
43+
pass
44+
45+
@abstractmethod
46+
def close_command(self, operation_handle: ttypes.TOperationHandle) -> ttypes.TStatus:
47+
pass
48+
49+
@abstractmethod
50+
def get_query_state(self, operation_handle: ttypes.TOperationHandle) -> ttypes.TOperationState:
51+
pass
52+
53+
@abstractmethod
54+
def get_execution_result(
55+
self,
56+
operation_handle: ttypes.TOperationHandle,
57+
cursor: Any,
58+
) -> ExecuteResponse:
59+
pass
60+
61+
# == Metadata Operations ==
62+
@abstractmethod
63+
def get_catalogs(
64+
self,
65+
session_handle: ttypes.TSessionHandle,
66+
max_rows: int,
67+
max_bytes: int,
68+
cursor: Any,
69+
) -> Any:
70+
pass
71+
72+
@abstractmethod
73+
def get_schemas(
74+
self,
75+
session_handle: ttypes.TSessionHandle,
76+
max_rows: int,
77+
max_bytes: int,
78+
cursor: Any,
79+
catalog_name: Optional[str] = None,
80+
schema_name: Optional[str] = None,
81+
) -> Any:
82+
pass
83+
84+
@abstractmethod
85+
def get_tables(
86+
self,
87+
session_handle: ttypes.TSessionHandle,
88+
max_rows: int,
89+
max_bytes: int,
90+
cursor: Any,
91+
catalog_name: Optional[str] = None,
92+
schema_name: Optional[str] = None,
93+
table_name: Optional[str] = None,
94+
table_types: Optional[List[str]] = None,
95+
) -> Any:
96+
pass
97+
98+
@abstractmethod
99+
def get_columns(
100+
self,
101+
session_handle: ttypes.TSessionHandle,
102+
max_rows: int,
103+
max_bytes: int,
104+
cursor: Any,
105+
catalog_name: Optional[str] = None,
106+
schema_name: Optional[str] = None,
107+
table_name: Optional[str] = None,
108+
column_name: Optional[str] = None,
109+
) -> Any:
110+
pass
111+
112+
# == Utility Methods ==
113+
@abstractmethod
114+
def handle_to_id(self, handle: ttypes.TSessionHandle) -> bytes:
115+
pass
116+
117+
@abstractmethod
118+
def handle_to_hex_id(self, handle: ttypes.TSessionHandle) -> str:
119+
pass
120+
121+
# Properties related to specific backend features
122+
@property
123+
@abstractmethod
124+
def staging_allowed_local_path(self) -> Union[None, str, List[str]]:
125+
pass
126+
127+
@property
128+
@abstractmethod
129+
def ssl_options(self) -> SSLOptions:
130+
pass
131+
132+
@property
133+
@abstractmethod
134+
def max_download_threads(self) -> int:
135+
pass

0 commit comments

Comments
 (0)