-
Notifications
You must be signed in to change notification settings - Fork 5.4k
HTTP Protocol
Timothy Meehan edited this page May 22, 2019
·
8 revisions
- Make a
POST
to/v1/statement
with the query - The
POST
will require the headerX-Presto-User
(generally populated with username) - You get back a JSON document that might contain a
nextUri
link - The document will contain
columns
if available - The document will contain
data
if available - The
columns
field will always be set ifdata
is set (and usually earlier) - If there is no
nextUri
link, then the query is finished (either successfully completed or failed) - Otherwise, keep following the
nextUri
link - The
status
field is only for displaying to humans as a hint about the query's state on the server. It is not in sync in the query state from the client's perspective and must not be used to determine whether the query is finished. - The document will contain an
error
field if the query has failed -- this is how you distinguish between a successfully completed query and a failed query when there is no morenextUri
link - If the response is an HTTP
503
, sleep 50-100ms and try again - Otherwise, if the response is anything other than an HTTP
200
with Content-Typeapplication/json
, then consider the query failed (this means something has gone wrong, for example, you might receive a404
or410
) - The document format is exactly the same for the POST response and the
nextUri
link response -- you might getdata
immediately as a response to thePOST
, or it might take many requests for a longer query -
SET SESSION
statements- Will return an
updateType
(top-level key of the returned JSON) of "SET SESSION", and a single "true" in the data list - Will return the key-value pair in the header
X-Presto-Set-Session
in the formatkey=value
- The
updateType
and header may exist in the first response, or a subsequent response from anextUri
- Will return an
- Statements submitted following
SET SESSION
statements should include any key-value pairs (returned by the serversX-Presto-Set-Session
) in the headerX-Presto-Session
. Multiple pairs can be comma-separated and included in a single header. -
RESET SESSION
statements- Will return an
updateType
(top-level key of the returned JSON) of "RESET SESSION", and a single "true" in the data list - Will return the session key in the header
X-Presto-Clear-Session
- The
updateType
and header may exist in the first response, or a subsequent response from anextUri
- Will return an
- Statements submitted following
RESET SESSION
statements should no longer include any key-value pairs previously added by SET SESSION statements. - Cancel a running query with a
DELETE
to/v1/query/<query-id>
The top level JSON document returned is QueryResults
. You can find the structure of this and related documents here: