学习 Presto(二):RESTful API

Presto Client、Presto Coordinator 和 Presto Worker 之间通过 RESTful API 进行通信

Presto 使用 AirLift 框架构建其 REST 服务

Cluster

源代码:com.facebook.presto.server.ClusterStatsResource

获取集群状态

HTTP 方法:GET

接口:/v1/cluster

返回数据:

{
    "runningQueries": 0,
    "blockedQueries": 0,
    "queuedQueries": 0,
    "activeWorkers": 6,
    "runningDrivers": 0,
    "reservedMemory": 0,
    "rowInputRate": 0,
    "byteInputRate": 0,
    "cpuTimeRate": 0
}

Statement

源代码:com.facebook.presto.server.StatementResource

提交查询

HTTP 方法:POST

接口:/v1/statement

HTTP Header:

键值 说明 🌰
X-Presto-User 用户名 presto
X-Presto-Time-Zone 时区 Asia/Shanghai
X-Presto-Language 语言 zh-CN
X-Presto-Transaction-Id 事务 ID NONE
Content-Type 请求内容类型 application/json; charset=utf-8

更多 HTTP Header 参数,参考类:com.facebook.presto.client.PrestoHeaders

返回数据:

{
    "id": "<query_id>",
    "infoUri": "http://<presto_coordinator>/query.html?<query_id>",
    "nextUri": "http://<presto_coordinator>/v1/statement/<query_id>/<token>",
    "stats": {
        "state": "QUEUED",
        "queued": true,
        "scheduled": false,
        "nodes": 0,
        "totalSplits": 0,
        "queuedSplits": 0,
        "runningSplits": 0,
        "completedSplits": 0,
        "userTimeMillis": 0,
        "cpuTimeMillis": 0,
        "wallTimeMillis": 0,
        "processedRows": 0,
        "processedBytes": 0
    }
}

获取查询结果

HTTP 方法:POST

接口:/v1/statement/<query_id>/<token>

返回数据:

{
    "id": "<query_id>",
    "infoUri": "http://<presto_coordinator>/query.html?<query_id>",
    "partialCancelUri": "http://<presto_coordinator>/v1/stage/<stage_id>",
    "nextUri": "http://<presto_coordinator>/v1/statement/<query_id>/<token>",
    "columns": [
        {
            "name": "order_id",
            "type": "bigint",
            "typeSignature": {
                "rawType": "bigint",
                "typeArguments": [],
                "literalArguments": [],
                "arguments": []
            }
        },
        ...
    ],
    "data": [
        [ ... ]
    ],
    "stats": {
        "state": "RUNNING",
        "queued": false,
        "scheduled": true,
        "nodes": 6,
        "totalSplits": 786,
        "queuedSplits": 0,
        "runningSplits": 0,
        "completedSplits": 786,
        "userTimeMillis": 1880,
        "cpuTimeMillis": 2193,
        "wallTimeMillis": 57282,
        "processedRows": 167383,
        "processedBytes": 167381,
        "rootStage": {
            "stageId": "0",
            "state": "RUNNING",
            "done": false,
            "nodes": 1,
            "totalSplits": 17,
            "queuedSplits": 0,
            "runningSplits": 0,
            "completedSplits": 17,
            "userTimeMillis": 0,
            "cpuTimeMillis": 4,
            "wallTimeMillis": 12,
            "processedRows": 1803,
            "processedBytes": 448245,
            "subStages": [
                {
                    "stageId": "1",
                    "state": "FINISHED",
                    "done": true,
                    "nodes": 6,
                    "totalSplits": 769,
                    "queuedSplits": 0,
                    "runningSplits": 0,
                    "completedSplits": 769,
                    "userTimeMillis": 1880,
                    "cpuTimeMillis": 2189,
                    "wallTimeMillis": 57270,
                    "processedRows": 167383,
                    "processedBytes": 167381,
                    "subStages": []
                }
            ]
        }
    }
}

参考:https://prestodb.io/docs/0.166/admin/web-interface.html