Statement Resource

POST /v1/statement()

  • Query query:

    SQL Query to execute

    Reqheader X-Presto-User:

    User to execute statement on behalf of (optional)

    Reqheader X-Presto-Source:

    Source of query

    Reqheader X-Presto-Catalog:

    Catalog to execute query against

    Reqheader X-Presto-Schema:

    Schema to execute query against

Submits a statement to Presto for execution. The Presto client executes queries on behalf of a user against a catalog and a schema. When you run a query with the Presto CLI, it is calling out to the statement resource on the Presto coordinator.

The request to the statement resource is the SQL query to execute as a post along with the standard X-Presto-Catalog, X-Presto-Source, X-Presto-Schema, and X-Presto-User headers.

The response from the statement resource contains a query identifier which can be used to gather detailed information about a query. This initial response also includes information about the stages that have been created to execute this query on Presto workers. Every query has a root stage and the root stage is given a stage identifier of “0” as shown in the following example response.

This root stage aggregates the responses from other stages running on Presto workers and delivers them to the client via the Presto coordinator. When a client receives a response to this POST it will contain a “nextUri” property which directs the client to query this address for additional results from the query.

Example request:

  1. POST /v1/statement HTTP/1.1
  2. Host: localhost:8001
  3. X-Presto-Catalog: jmx
  4. X-Presto-Source: presto-cli
  5. X-Presto-Schema: jmx
  6. User-Agent: StatementClient/0.55-SNAPSHOT
  7. X-Presto-User: tobrie1
  8. Content-Length: 41
  9. select name from "java.lang:type=runtime"

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json
  3. X-Content-Type-Options: nosniff
  4. Transfer-Encoding: chunked
  5. {
  6. "id":"20140108_110629_00011_dk5x2",
  7. "infoUri":"http://localhost:8001/v1/query/20140108_110629_00011_dk5x2",
  8. "partialCancelUri":"http://10.193.207.128:8080/v1/stage/20140108_110629_00011_dk5x2.1",
  9. "nextUri":"http://localhost:8001/v1/statement/20140108_110629_00011_dk5x2/1",
  10. "columns":
  11. [
  12. {
  13. "name":"name",
  14. "type":"varchar"
  15. }
  16. ],
  17. "stats":
  18. {
  19. "state":"RUNNING",
  20. "scheduled":false,
  21. "nodes":1,
  22. "totalSplits":0,
  23. "queuedSplits":0,
  24. "runningSplits":0,
  25. "completedSplits":0,
  26. "cpuTimeMillis":0,
  27. "wallTimeMillis":0,
  28. "processedRows":0,
  29. "processedBytes":0,
  30. "rootStage":
  31. {
  32. "stageId":"0",
  33. "state":"SCHEDULED",
  34. "done":false,
  35. "nodes":1,
  36. "totalSplits":0,
  37. "queuedSplits":0,
  38. "runningSplits":0,
  39. "completedSplits":0,
  40. "cpuTimeMillis":0,
  41. "wallTimeMillis":0,
  42. "processedRows":0,
  43. "processedBytes":0,
  44. "subStages":
  45. [
  46. {
  47. "stageId":"1",
  48. "state":"SCHEDULED",
  49. "done":false,
  50. "nodes":1,
  51. "totalSplits":0,
  52. "queuedSplits":0,
  53. "runningSplits":0,
  54. "completedSplits":0,
  55. "cpuTimeMillis":0,
  56. "wallTimeMillis":0,
  57. "processedRows":0,
  58. "processedBytes":0,
  59. "subStages":[]
  60. }
  61. ]
  62. }
  63. }
  64. }

GET /v1/statement/{queryId}/{token}()

  • Query queryId:

    The query identifier returned from the initial POST to /v1/statement

    Query token:

    The token returned from the initial POST to /v1/statement or from a previous call to this same call

When a Presto client submits a statement for execution, Presto creates a query and then it returns a nextUri to the client. This call corresponds to that nextUri call and can contain either a status update for a query in progress or it can deliver the final results to the client.

Example request:

  1. GET /v1/statement/20140108_110629_00011_dk5x2/1 HTTP/1.1
  2. Host: localhost:8001
  3. User-Agent: StatementClient/0.55-SNAPSHOT

Example response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json
  3. X-Content-Type-Options: nosniff
  4. Vary: Accept-Encoding, User-Agent
  5. Transfer-Encoding: chunked
  6. 383
  7. {
  8. "id":"20140108_110629_00011_dk5x2",
  9. "infoUri":"http://localhost:8001/v1/query/20140108_110629_00011_dk5x2",
  10. "columns":
  11. [
  12. {
  13. "name":"name",
  14. "type":"varchar"
  15. }
  16. ],
  17. "data":
  18. [
  19. ["4165@domU-12-31-39-0F-CC-72"]
  20. ],
  21. "stats":
  22. {
  23. "state":"FINISHED",
  24. "scheduled":true,
  25. "nodes":1,
  26. "totalSplits":2,
  27. "queuedSplits":0,
  28. "runningSplits":0,
  29. "completedSplits":2,
  30. "cpuTimeMillis":1,
  31. "wallTimeMillis":4,
  32. "processedRows":1,
  33. "processedBytes":27,
  34. "rootStage":
  35. {
  36. "stageId":"1",
  37. "state":"FINISHED",
  38. "done":true,
  39. "nodes":1,
  40. "totalSplits":1,
  41. "queuedSplits":0,
  42. "runningSplits":0,
  43. "completedSplits":1,
  44. "cpuTimeMillis":0,
  45. "wallTimeMillis":0,
  46. "processedRows":1,
  47. "processedBytes":32,
  48. "subStages":
  49. [
  50. {
  51. "stageId":"1",
  52. "state":"FINISHED",
  53. "done":true,
  54. "nodes":1,
  55. "totalSplits":1,
  56. "queuedSplits":0,
  57. "runningSplits":0,
  58. "completedSplits":1,
  59. "cpuTimeMillis":0,
  60. "wallTimeMillis":4,
  61. "processedRows":1,
  62. "processedBytes":27,
  63. "subStages":[]
  64. }
  65. ]
  66. }
  67. }
  68. }

DELETE /v1/statement/{queryId}/{token}()

  • Query queryId:

    The query identifier returned from the initial POST to /v1/statement

    Reqheader X-Presto-User:

    User to execute statement on behalf of (optional)

    Reqheader X-Presto-Source:

    Source of query

    Reqheader X-Presto-Catalog:

    Catalog to execute query against

    Reqheader X-Presto-Schema:

    Schema to execute query against