Skip to content

Commit e129fe4

Browse files
NiallEgansusodapop
authored andcommitted
Thrift-backed new Python client
This PR completely removes all gRPC functionality from the Python SQL client and replaces the backend with Thrift only. It does not add any new features, just brings in line with the previous functionality of the client. * New unit tests which tests the behaviour of the backend on a message-by-message basis * Manual test with test image - Did you add usage logs or metrics? Please mention them here. - Create dashboards or monitoring notebooks? Please link them here. - See http://go/obs/user for docs on our observability tools.
1 parent 5166365 commit e129fe4

File tree

15 files changed

+88014
-463
lines changed

15 files changed

+88014
-463
lines changed

cmdexec/clients/python/setup.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
version="0.0.0",
66
package_dir={"": "src"},
77
packages=setuptools.find_packages(where="src"),
8-
install_requires=[
9-
"grpcio", # TODO: Minimum versions
10-
"pyarrow",
11-
"protobuf",
12-
"cryptography",
13-
],
8+
install_requires=["pyarrow", 'thrift>=0.10.0'],
149
author="Databricks",
1510
)

cmdexec/clients/python/src/databricks/sql/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from databricks.sql.errors import *
1+
from databricks.sql.exc import *
22

33

44
class _DBAPITypeObject(object):
@@ -9,7 +9,7 @@ def __eq__(self, other):
99
return other in self.values
1010

1111
def __repr__(self):
12-
return "DBAPITypeObject(%s)" % self.values
12+
return "DBAPITypeObject({})".format(self.values)
1313

1414

1515
STRING = _DBAPITypeObject('string')
@@ -20,7 +20,7 @@ def __repr__(self):
2020
DATE = _DBAPITypeObject('date')
2121
ROWID = _DBAPITypeObject()
2222

23-
__version__ = "1.0.0"
23+
__version__ = "2.0.0-rc1"
2424
USER_AGENT_NAME = "PyDatabricksSqlConnector"
2525

2626

cmdexec/clients/python/src/databricks/sql/client.py

Lines changed: 128 additions & 321 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#!/usr/bin/env python
2+
#
3+
# Autogenerated by Thrift Compiler (0.15.0)
4+
#
5+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
6+
#
7+
# options string: py
8+
#
9+
10+
import sys
11+
import pprint
12+
if sys.version_info[0] > 2:
13+
from urllib.parse import urlparse
14+
else:
15+
from urlparse import urlparse
16+
from thrift.transport import TTransport, TSocket, TSSLSocket, THttpClient
17+
from thrift.protocol.TBinaryProtocol import TBinaryProtocol
18+
19+
from TCLIService import TCLIService
20+
from TCLIService.ttypes import *
21+
22+
if len(sys.argv) <= 1 or sys.argv[1] == '--help':
23+
print('')
24+
print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] [-novalidate] [-ca_certs certs] [-keyfile keyfile] [-certfile certfile] function [arg1 [arg2...]]')
25+
print('')
26+
print('Functions:')
27+
print(' TOpenSessionResp OpenSession(TOpenSessionReq req)')
28+
print(' TCloseSessionResp CloseSession(TCloseSessionReq req)')
29+
print(' TGetInfoResp GetInfo(TGetInfoReq req)')
30+
print(' TExecuteStatementResp ExecuteStatement(TExecuteStatementReq req)')
31+
print(' TGetTypeInfoResp GetTypeInfo(TGetTypeInfoReq req)')
32+
print(' TGetCatalogsResp GetCatalogs(TGetCatalogsReq req)')
33+
print(' TGetSchemasResp GetSchemas(TGetSchemasReq req)')
34+
print(' TGetTablesResp GetTables(TGetTablesReq req)')
35+
print(' TGetTableTypesResp GetTableTypes(TGetTableTypesReq req)')
36+
print(' TGetColumnsResp GetColumns(TGetColumnsReq req)')
37+
print(' TGetFunctionsResp GetFunctions(TGetFunctionsReq req)')
38+
print(' TGetPrimaryKeysResp GetPrimaryKeys(TGetPrimaryKeysReq req)')
39+
print(' TGetCrossReferenceResp GetCrossReference(TGetCrossReferenceReq req)')
40+
print(' TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req)')
41+
print(' TCancelOperationResp CancelOperation(TCancelOperationReq req)')
42+
print(' TCloseOperationResp CloseOperation(TCloseOperationReq req)')
43+
print(' TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req)')
44+
print(' TFetchResultsResp FetchResults(TFetchResultsReq req)')
45+
print(' TGetDelegationTokenResp GetDelegationToken(TGetDelegationTokenReq req)')
46+
print(' TCancelDelegationTokenResp CancelDelegationToken(TCancelDelegationTokenReq req)')
47+
print(' TRenewDelegationTokenResp RenewDelegationToken(TRenewDelegationTokenReq req)')
48+
print('')
49+
sys.exit(0)
50+
51+
pp = pprint.PrettyPrinter(indent=2)
52+
host = 'localhost'
53+
port = 9090
54+
uri = ''
55+
framed = False
56+
ssl = False
57+
validate = True
58+
ca_certs = None
59+
keyfile = None
60+
certfile = None
61+
http = False
62+
argi = 1
63+
64+
if sys.argv[argi] == '-h':
65+
parts = sys.argv[argi + 1].split(':')
66+
host = parts[0]
67+
if len(parts) > 1:
68+
port = int(parts[1])
69+
argi += 2
70+
71+
if sys.argv[argi] == '-u':
72+
url = urlparse(sys.argv[argi + 1])
73+
parts = url[1].split(':')
74+
host = parts[0]
75+
if len(parts) > 1:
76+
port = int(parts[1])
77+
else:
78+
port = 80
79+
uri = url[2]
80+
if url[4]:
81+
uri += '?%s' % url[4]
82+
http = True
83+
argi += 2
84+
85+
if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
86+
framed = True
87+
argi += 1
88+
89+
if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
90+
ssl = True
91+
argi += 1
92+
93+
if sys.argv[argi] == '-novalidate':
94+
validate = False
95+
argi += 1
96+
97+
if sys.argv[argi] == '-ca_certs':
98+
ca_certs = sys.argv[argi+1]
99+
argi += 2
100+
101+
if sys.argv[argi] == '-keyfile':
102+
keyfile = sys.argv[argi+1]
103+
argi += 2
104+
105+
if sys.argv[argi] == '-certfile':
106+
certfile = sys.argv[argi+1]
107+
argi += 2
108+
109+
cmd = sys.argv[argi]
110+
args = sys.argv[argi + 1:]
111+
112+
if http:
113+
transport = THttpClient.THttpClient(host, port, uri)
114+
else:
115+
if ssl:
116+
socket = TSSLSocket.TSSLSocket(host, port, validate=validate, ca_certs=ca_certs, keyfile=keyfile, certfile=certfile)
117+
else:
118+
socket = TSocket.TSocket(host, port)
119+
if framed:
120+
transport = TTransport.TFramedTransport(socket)
121+
else:
122+
transport = TTransport.TBufferedTransport(socket)
123+
protocol = TBinaryProtocol(transport)
124+
client = TCLIService.Client(protocol)
125+
transport.open()
126+
127+
if cmd == 'OpenSession':
128+
if len(args) != 1:
129+
print('OpenSession requires 1 args')
130+
sys.exit(1)
131+
pp.pprint(client.OpenSession(eval(args[0]),))
132+
133+
elif cmd == 'CloseSession':
134+
if len(args) != 1:
135+
print('CloseSession requires 1 args')
136+
sys.exit(1)
137+
pp.pprint(client.CloseSession(eval(args[0]),))
138+
139+
elif cmd == 'GetInfo':
140+
if len(args) != 1:
141+
print('GetInfo requires 1 args')
142+
sys.exit(1)
143+
pp.pprint(client.GetInfo(eval(args[0]),))
144+
145+
elif cmd == 'ExecuteStatement':
146+
if len(args) != 1:
147+
print('ExecuteStatement requires 1 args')
148+
sys.exit(1)
149+
pp.pprint(client.ExecuteStatement(eval(args[0]),))
150+
151+
elif cmd == 'GetTypeInfo':
152+
if len(args) != 1:
153+
print('GetTypeInfo requires 1 args')
154+
sys.exit(1)
155+
pp.pprint(client.GetTypeInfo(eval(args[0]),))
156+
157+
elif cmd == 'GetCatalogs':
158+
if len(args) != 1:
159+
print('GetCatalogs requires 1 args')
160+
sys.exit(1)
161+
pp.pprint(client.GetCatalogs(eval(args[0]),))
162+
163+
elif cmd == 'GetSchemas':
164+
if len(args) != 1:
165+
print('GetSchemas requires 1 args')
166+
sys.exit(1)
167+
pp.pprint(client.GetSchemas(eval(args[0]),))
168+
169+
elif cmd == 'GetTables':
170+
if len(args) != 1:
171+
print('GetTables requires 1 args')
172+
sys.exit(1)
173+
pp.pprint(client.GetTables(eval(args[0]),))
174+
175+
elif cmd == 'GetTableTypes':
176+
if len(args) != 1:
177+
print('GetTableTypes requires 1 args')
178+
sys.exit(1)
179+
pp.pprint(client.GetTableTypes(eval(args[0]),))
180+
181+
elif cmd == 'GetColumns':
182+
if len(args) != 1:
183+
print('GetColumns requires 1 args')
184+
sys.exit(1)
185+
pp.pprint(client.GetColumns(eval(args[0]),))
186+
187+
elif cmd == 'GetFunctions':
188+
if len(args) != 1:
189+
print('GetFunctions requires 1 args')
190+
sys.exit(1)
191+
pp.pprint(client.GetFunctions(eval(args[0]),))
192+
193+
elif cmd == 'GetPrimaryKeys':
194+
if len(args) != 1:
195+
print('GetPrimaryKeys requires 1 args')
196+
sys.exit(1)
197+
pp.pprint(client.GetPrimaryKeys(eval(args[0]),))
198+
199+
elif cmd == 'GetCrossReference':
200+
if len(args) != 1:
201+
print('GetCrossReference requires 1 args')
202+
sys.exit(1)
203+
pp.pprint(client.GetCrossReference(eval(args[0]),))
204+
205+
elif cmd == 'GetOperationStatus':
206+
if len(args) != 1:
207+
print('GetOperationStatus requires 1 args')
208+
sys.exit(1)
209+
pp.pprint(client.GetOperationStatus(eval(args[0]),))
210+
211+
elif cmd == 'CancelOperation':
212+
if len(args) != 1:
213+
print('CancelOperation requires 1 args')
214+
sys.exit(1)
215+
pp.pprint(client.CancelOperation(eval(args[0]),))
216+
217+
elif cmd == 'CloseOperation':
218+
if len(args) != 1:
219+
print('CloseOperation requires 1 args')
220+
sys.exit(1)
221+
pp.pprint(client.CloseOperation(eval(args[0]),))
222+
223+
elif cmd == 'GetResultSetMetadata':
224+
if len(args) != 1:
225+
print('GetResultSetMetadata requires 1 args')
226+
sys.exit(1)
227+
pp.pprint(client.GetResultSetMetadata(eval(args[0]),))
228+
229+
elif cmd == 'FetchResults':
230+
if len(args) != 1:
231+
print('FetchResults requires 1 args')
232+
sys.exit(1)
233+
pp.pprint(client.FetchResults(eval(args[0]),))
234+
235+
elif cmd == 'GetDelegationToken':
236+
if len(args) != 1:
237+
print('GetDelegationToken requires 1 args')
238+
sys.exit(1)
239+
pp.pprint(client.GetDelegationToken(eval(args[0]),))
240+
241+
elif cmd == 'CancelDelegationToken':
242+
if len(args) != 1:
243+
print('CancelDelegationToken requires 1 args')
244+
sys.exit(1)
245+
pp.pprint(client.CancelDelegationToken(eval(args[0]),))
246+
247+
elif cmd == 'RenewDelegationToken':
248+
if len(args) != 1:
249+
print('RenewDelegationToken requires 1 args')
250+
sys.exit(1)
251+
pp.pprint(client.RenewDelegationToken(eval(args[0]),))
252+
253+
else:
254+
print('Unrecognized method %s' % cmd)
255+
sys.exit(1)
256+
257+
transport.close()

0 commit comments

Comments
 (0)