语句资源¶
- POST /v1/statement()¶
- 查询 query:
要执行的 SQL 查询
- 请求头 X-Presto-User:
代表其执行语句的用户(可选)
- 请求头 X-Presto-Source:
查询来源
- 请求头 X-Presto-Catalog:
要执行查询的目标目录
- 请求头 X-Presto-Schema:
要执行查询的目标模式
将语句提交给 Presto 以执行。Presto 客户端代表用户对目录和模式执行查询。当使用 Presto CLI 运行查询时,它会调用 Presto 协调器上的语句资源。
对语句资源的请求是要执行的 SQL 查询,以及标准的 X-Presto-Catalog、X-Presto-Source、X-Presto-Schema 和 X-Presto-User 头部信息。
来自语句资源的响应包含一个查询标识符,可用于收集有关查询的详细信息。此初始响应还包括有关为在 Presto 工作器上执行此查询而创建的阶段的信息。每个查询都有一个根阶段,并且根阶段被赋予一个阶段标识符“0”,如以下示例响应所示。
此根阶段汇总来自在 Presto 工作器上运行的其他阶段的响应,并通过 Presto 协调器将它们传递给客户端。当客户端接收到此 POST 的响应时,它将包含一个“nextUri”属性,该属性指示客户端查询此地址以获取查询的更多结果。
示例请求:
POST /v1/statement HTTP/1.1 Host: localhost:8001 X-Presto-Catalog: jmx X-Presto-Source: presto-cli X-Presto-Schema: jmx User-Agent: StatementClient/0.55-SNAPSHOT X-Presto-User: tobrie1 Content-Length: 41 select name from "java.lang:type=runtime"
示例响应:
HTTP/1.1 200 OK Content-Type: application/json X-Content-Type-Options: nosniff Transfer-Encoding: chunked { "id":"20140108_110629_00011_dk5x2", "infoUri":"https://127.0.0.1:8001/v1/query/20140108_110629_00011_dk5x2", "partialCancelUri":"http://10.193.207.128:8080/v1/stage/20140108_110629_00011_dk5x2.1", "nextUri":"https://127.0.0.1:8001/v1/statement/20140108_110629_00011_dk5x2/1", "columns": [ { "name":"name", "type":"varchar" } ], "stats": { "state":"RUNNING", "scheduled":false, "nodes":1, "totalSplits":0, "queuedSplits":0, "runningSplits":0, "completedSplits":0, "cpuTimeMillis":0, "wallTimeMillis":0, "processedRows":0, "processedBytes":0, "rootStage": { "stageId":"0", "state":"SCHEDULED", "done":false, "nodes":1, "totalSplits":0, "queuedSplits":0, "runningSplits":0, "completedSplits":0, "cpuTimeMillis":0, "wallTimeMillis":0, "processedRows":0, "processedBytes":0, "subStages": [ { "stageId":"1", "state":"SCHEDULED", "done":false, "nodes":1, "totalSplits":0, "queuedSplits":0, "runningSplits":0, "completedSplits":0, "cpuTimeMillis":0, "wallTimeMillis":0, "processedRows":0, "processedBytes":0, "subStages":[] } ] } } }
- GET /v1/statement/{queryId}/{token}()¶
- 查询 queryId:
从初始 POST 到 /v1/statement 返回的查询标识符
- 查询 token:
从初始 POST 到 /v1/statement 或从之前对同一调用的调用返回的令牌
当 Presto 客户端提交要执行的语句时,Presto 会创建一个查询,然后将 nextUri 返回给客户端。此调用对应于该 nextUri 调用,并且可以包含正在进行的查询的状态更新,或者可以将最终结果传递给客户端。
示例请求:
GET /v1/statement/20140108_110629_00011_dk5x2/1 HTTP/1.1 Host: localhost:8001 User-Agent: StatementClient/0.55-SNAPSHOT
示例响应:
HTTP/1.1 200 OK Content-Type: application/json X-Content-Type-Options: nosniff Vary: Accept-Encoding, User-Agent Transfer-Encoding: chunked 383 { "id":"20140108_110629_00011_dk5x2", "infoUri":"https://127.0.0.1:8001/v1/query/20140108_110629_00011_dk5x2", "columns": [ { "name":"name", "type":"varchar" } ], "data": [ ["4165@domU-12-31-39-0F-CC-72"] ], "stats": { "state":"FINISHED", "scheduled":true, "nodes":1, "totalSplits":2, "queuedSplits":0, "runningSplits":0, "completedSplits":2, "cpuTimeMillis":1, "wallTimeMillis":4, "processedRows":1, "processedBytes":27, "rootStage": { "stageId":"1", "state":"FINISHED", "done":true, "nodes":1, "totalSplits":1, "queuedSplits":0, "runningSplits":0, "completedSplits":1, "cpuTimeMillis":0, "wallTimeMillis":0, "processedRows":1, "processedBytes":32, "subStages": [ { "stageId":"1", "state":"FINISHED", "done":true, "nodes":1, "totalSplits":1, "queuedSplits":0, "runningSplits":0, "completedSplits":1, "cpuTimeMillis":0, "wallTimeMillis":4, "processedRows":1, "processedBytes":27, "subStages":[] } ] } } }
- DELETE /v1/statement/{queryId}/{token}()¶
- 查询 queryId:
从初始 POST 到 /v1/statement 返回的查询标识符
- 请求头 X-Presto-User:
代表其执行语句的用户(可选)
- 请求头 X-Presto-Source:
查询来源
- 请求头 X-Presto-Catalog:
要执行查询的目标目录
- 请求头 X-Presto-Schema:
要执行查询的目标模式