Skip to content

Commit ce30838

Browse files
author
easydatawarehousing
committed
Update 0.2.0
1 parent 9fbe789 commit ce30838

11 files changed

+818
-588
lines changed

README.md

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
prestoclient
1+
PrestoClient
22
============
33

44
PrestoClient implements a Python class to communicate with a Presto server.
@@ -8,7 +8,7 @@ Hadoop HDFS servers (http://hadoop.apache.org/).
88
Presto uses SQL as its query language. Presto is an alternative for
99
Hadoop-Hive.
1010

11-
PrestoClient was developed using Presto 0.52 and tested on Presto 0.52 and 0.54.
11+
PrestoClient was developed using Presto 0.52 and tested on Presto 0.52 and 0.54. Python version used is 2.7.6
1212

1313
You can use this class with this sample code:
1414

@@ -20,43 +20,52 @@ You can use this class with this sample code:
2020
presto = prestoclient.PrestoClient("localhost")
2121

2222
if not presto.startquery(sql):
23-
print presto.getlasterrormessage()
23+
print "Error: ", presto.getlasterrormessage()
2424
else:
25-
presto.waituntilfinished(True) # Remove True parameter to skip printing status messages
26-
print "Columns: ", presto.getcolumns()
27-
print "Datalength: ", presto.getdatalength(), " Data: ", presto.getdata()
25+
presto.waituntilfinished(True) # Remove True parameter to skip printing status messages
26+
27+
# We're done now, so let's show the results
28+
print "Columns: ", presto.getcolumns()
29+
if presto.getstatus() == "FAILED": print "Error : ", presto.getlasterrormessage()
30+
if presto.getdata(): print "Datalength: ", presto.getnumberofdatarows(), " Data: ", presto.getdata()
2831

2932

3033
Presto client protocol
3134
----------------------
32-
33-
The communication protocol used between Presto clients and servers is not documented. It seems to
35+
The communication protocol used between Presto clients and servers is not documented yet. It seems to
3436
be as follows:
3537

36-
Client sends http POST request. Headerinformation should include: X-Presto-Catalog, X-Presto-Source,
37-
X-Presto-Schema, User-Agent, X-Presto-User. The body of the request should contain the sql statement.
38-
The server responds by returning JSON data. This data should contain 2 uri's. One giving the link
39-
to get more information about the query execution (infoUri) and the other one giving the link to fetch
40-
the next packet of data (nextUri).
41-
42-
The client should send GET requests to the server (header: X-Presto-Source, User-Agent, X-Presto-User.
43-
Body: empty) following the nextUri link from the last response
44-
until the server response does not give any more nextUri links. The server response also contains a
45-
'state' variable. When there is no nextUri the state should be one of: FINISHED, FAILED or CANCELED.
46-
Each response by the server to a 'nextUri' may contain information about the columns returned by the
47-
query and all- or part of the querydata.
48-
49-
The server reponse may contain a variable with the uri to cancel the query (partialCancelUri). The
50-
client may issue a DELETE request to the server using this link.
51-
The Presto server will retain information about finished queries for 15 minutes. When a client does
52-
not respond to the server (by following the nextUri links) the server will cancel these 'dead' queries
53-
after 5 minutes. These timeouts are hardcoded in the Presto server source code.
38+
Client sends http POST request to the Presto server, page: "/v1/statement". Header information should
39+
include: X-Presto-Catalog, X-Presto-Source, X-Presto-Schema, User-Agent, X-Presto-User. The body of the
40+
request should contain the sql statement. The server responds by returning JSON data (http status-code 200).
41+
This reply may contain up to 3 uri's. One giving the link to get more information about the query execution
42+
('infoUri'), another giving the link to fetch the next packet of data ('nextUri') and one with the uri to
43+
cancel the query ('partialCancelUri').
44+
45+
The client should send GET requests to the server (Header: X-Presto-Source, User-Agent, X-Presto-User.
46+
Body: empty) following the 'nextUri' link from the previous response until the servers response does not
47+
contain an 'nextUri' link anymore. When there is no 'nextUri' the query is finished. If the last response
48+
from the server included an error section ('error') the query failed, otherwise the query succeeded. If
49+
the http status of the server response is anything other than 200 with Content-Type application/json, the
50+
query should also be considered failed. A 503 http response means that the server is (too) busy. Retry the
51+
request after waiting at least 50ms.
52+
The server response may contain a 'state' variable. This is for informational purposes only (may be subject
53+
to change in future implementations).
54+
Each response by the server to a 'nextUri' may contain information about the columns returned by the query
55+
and all- or part of the querydata. If the response contains a data section the columns section will always
56+
be available.
57+
58+
The server reponse may contain a variable with the uri to cancel the query ('partialCancelUri'). The client
59+
may issue a DELETE request to the server using this link. Response http status-code is 204.
60+
61+
The Presto server will retain information about finished queries for 15 minutes. When a client does not
62+
respond to the server (by following the 'nextUri' links) the server will cancel these 'dead' queries after
63+
5 minutes. These timeouts are hardcoded in the Presto server source code.
5464

5565
ToDo
5666
----
57-
- Make the PrestoClient class re-usable. Currently you can only start one query per instance of
58-
this class.
59-
67+
- Enable PrestoClient to handle multiple running queries simultaneously. Currently you can only run one query per instance of this class.
68+
- Add support for https connections
6069
- Add support for insert/update queries (if and when Presto server supports this).
6170

6271
Availability
@@ -80,4 +89,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
8089
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8190
See the License for the specific language governing permissions and
8291
limitations under the License.
83-

VERSION

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
VERSION INFORMATION: PrestoClient
2+
=================================
3+
4+
Version 0.2.0 BETA - Dec 03, 2013
5+
---------------------------------
6+
Python version:
7+
- Client properly detects when a request is finished. The instance of the client may then be re-used for a new query
8+
- Updated the presto client protocol. Client no longer uses the 'state' variable, only the presence of a 'nextUri' link
9+
If server responds with http code 503, the request will be retried.
10+
- Some changes in naming of methods
11+
- Added the error message from the database if the query failed
12+
- Improved error handling
13+
- Updated documentation
14+
15+
Version 0.1.0 BETA - Nov 28, 2013
16+
---------------------------------
17+
- This the first public release. Support for Python

python/doc/api-objects.txt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ prestoclient.PrestoClient.__data prestoclient.PrestoClient-class.html#__data
55
prestoclient.PrestoClient.__columns prestoclient.PrestoClient-class.html#__columns
66
prestoclient.PrestoClient.getcolumns prestoclient.PrestoClient-class.html#getcolumns
77
prestoclient.PrestoClient.__updatewaittimemsec prestoclient.PrestoClient-class.html#__updatewaittimemsec
8-
prestoclient.PrestoClient.__port prestoclient.PrestoClient-class.html#__port
8+
prestoclient.PrestoClient.__useragent prestoclient.PrestoClient-class.html#__useragent
99
prestoclient.PrestoClient.__lasterror prestoclient.PrestoClient-class.html#__lasterror
1010
prestoclient.PrestoClient.__cancelquery prestoclient.PrestoClient-class.html#__cancelquery
11-
prestoclient.PrestoClient.cleardata prestoclient.PrestoClient-class.html#cleardata
11+
prestoclient.PrestoClient.getlastresponse prestoclient.PrestoClient-class.html#getlastresponse
12+
prestoclient.PrestoClient.getnumberofdatarows prestoclient.PrestoClient-class.html#getnumberofdatarows
1213
prestoclient.PrestoClient.__init__ prestoclient.PrestoClient-class.html#__init__
13-
prestoclient.PrestoClient.getdatalength prestoclient.PrestoClient-class.html#getdatalength
14+
prestoclient.PrestoClient.getlastserverstate prestoclient.PrestoClient-class.html#getlastserverstate
15+
prestoclient.PrestoClient.getdata prestoclient.PrestoClient-class.html#getdata
16+
prestoclient.PrestoClient.cleardata prestoclient.PrestoClient-class.html#cleardata
17+
prestoclient.PrestoClient.__maximumretries prestoclient.PrestoClient-class.html#__maximumretries
1418
prestoclient.PrestoClient.getlasterrormessage prestoclient.PrestoClient-class.html#getlasterrormessage
15-
prestoclient.PrestoClient.__response prestoclient.PrestoClient-class.html#__response
1619
prestoclient.PrestoClient.__cancel prestoclient.PrestoClient-class.html#__cancel
1720
prestoclient.PrestoClient.queryisrunning prestoclient.PrestoClient-class.html#queryisrunning
21+
prestoclient.PrestoClient.__retrywaittimemsec prestoclient.PrestoClient-class.html#__retrywaittimemsec
1822
prestoclient.PrestoClient.getqueryinfo prestoclient.PrestoClient-class.html#getqueryinfo
1923
prestoclient.PrestoClient.__lastinfouri prestoclient.PrestoClient-class.html#__lastinfouri
2024
prestoclient.PrestoClient.startquery prestoclient.PrestoClient-class.html#startquery
@@ -27,13 +31,12 @@ prestoclient.PrestoClient.__urltimeout prestoclient.PrestoClient-class.html#__ur
2731
prestoclient.PrestoClient.__catalog prestoclient.PrestoClient-class.html#__catalog
2832
prestoclient.PrestoClient.__lastnexturi prestoclient.PrestoClient-class.html#__lastnexturi
2933
prestoclient.PrestoClient.__lastcanceluri prestoclient.PrestoClient-class.html#__lastcanceluri
30-
prestoclient.PrestoClient.__useragent prestoclient.PrestoClient-class.html#__useragent
31-
prestoclient.PrestoClient.__isstarted prestoclient.PrestoClient-class.html#__isstarted
32-
prestoclient.PrestoClient.getdata prestoclient.PrestoClient-class.html#getdata
34+
prestoclient.PrestoClient.__lastresponse prestoclient.PrestoClient-class.html#__lastresponse
35+
prestoclient.PrestoClient.getstatus prestoclient.PrestoClient-class.html#getstatus
36+
prestoclient.PrestoClient.__port prestoclient.PrestoClient-class.html#__port
37+
prestoclient.PrestoClient.__clientstatus prestoclient.PrestoClient-class.html#__clientstatus
3338
prestoclient.PrestoClient.__getvarsfromresponse prestoclient.PrestoClient-class.html#__getvarsfromresponse
3439
prestoclient.PrestoClient.waituntilfinished prestoclient.PrestoClient-class.html#waituntilfinished
3540
prestoclient.PrestoClient.__user prestoclient.PrestoClient-class.html#__user
3641
prestoclient.PrestoClient.__source prestoclient.PrestoClient-class.html#__source
37-
prestoclient.PrestoClient.getresponse prestoclient.PrestoClient-class.html#getresponse
3842
prestoclient.PrestoClient.getversion prestoclient.PrestoClient-class.html#getversion
39-
prestoclient.PrestoClient.__getnext prestoclient.PrestoClient-class.html#__getnext

python/doc/class-tree.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ <h1 class="epydoc">Class Hierarchy</h1>
8686
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
8787
<tr>
8888
<td align="left" class="footer">
89-
Generated by Epydoc 3.0.1 on Thu Nov 28 13:59:59 2013
89+
Generated by Epydoc 3.0.1 on Tue Dec 3 09:02:07 2013
9090
</td>
9191
<td align="right" class="footer">
9292
<a target="mainFrame" href="http://epydoc.sourceforge.net"

python/doc/help.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ <h2> The Navigation Bar </h2>
246246
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
247247
<tr>
248248
<td align="left" class="footer">
249-
Generated by Epydoc 3.0.1 on Thu Nov 28 13:59:59 2013
249+
Generated by Epydoc 3.0.1 on Tue Dec 3 09:02:07 2013
250250
</td>
251251
<td align="right" class="footer">
252252
<a target="mainFrame" href="http://epydoc.sourceforge.net"

0 commit comments

Comments
 (0)