美文网首页
presto(九)——restful api之execute

presto(九)——restful api之execute

作者: hello高world | 来源:发表于2017-03-15 22:43 被阅读0次

    1、看状态

    @Path("/v1/execute")
    public class ExecuteResource
    {
        private final HttpServerInfo serverInfo;
        private final HttpClient httpClient;
        private final JsonCodec<QueryResults> queryResultsCodec;
    

    2、看执行方法

    ExecuteResource.java(@Path("/v1/execute"))

     @POST
        @Produces(MediaType.APPLICATION_JSON)
        public Response createQuery(String query, @Context HttpServletRequest servletRequest)
        {
            assertRequest(!isNullOrEmpty(query), "SQL query is empty");
    
            ClientSession clientSession = createClientSessionForRequest(servletRequest, serverUri(), new Duration(2, MINUTES));
            StatementClient client = new StatementClient(httpClient, queryResultsCodec, clientSession, query);
    
            List<Column> columns = getColumns(client);
            Iterator<List<Object>> iterator = flatten(new ResultsPageIterator(client));
            SimpleQueryResults results = new SimpleQueryResults(columns, iterator);
    
            return Response.ok(results, MediaType.APPLICATION_JSON_TYPE).build();
        }
        
    

    有没有发现跟上一节的很相似:

    QueryResource.java(@Path("/v1/query"))

        @POST
        @Produces(MediaType.APPLICATION_JSON)
        public Response createQuery(
                String statement,
                @Context HttpServletRequest servletRequest,
                @Context UriInfo uriInfo)
        {
            assertRequest(!isNullOrEmpty(statement), "SQL statement is empty");
    
            Session session = createSessionForRequest(servletRequest, transactionManager, accessControl, sessionPropertyManager, queryIdGenerator.createNextQueryId());
    
            QueryInfo queryInfo = queryManager.createQuery(session, statement);
            URI pagesUri = uriBuilderFrom(uriInfo.getRequestUri()).appendPath(queryInfo.getQueryId().toString()).build();
            return Response.created(pagesUri).entity(queryInfo).build();
        }
    

    我们先看看返回值:
    QueryResource返回的是uri+queryInfo (链接地址+查询信息)
    ExecuteResource返回的是results (结果)

    其实还有一个类:

    @Path("/v1/statement")
    public class StatementResource
    

    同样也有createQuery方法:

    @POST
        @Produces(MediaType.APPLICATION_JSON)
        public Response createQuery(
                String statement,
                @Context HttpServletRequest servletRequest,
                @Context UriInfo uriInfo)
                throws InterruptedException
        {
            assertRequest(!isNullOrEmpty(statement), "SQL statement is empty");
    
            Session session = createSessionForRequest(servletRequest, transactionManager, accessControl, sessionPropertyManager, queryIdGenerator.createNextQueryId());
    
            ExchangeClient exchangeClient = exchangeClientSupplier.get(deltaMemoryInBytes -> { });
            Query query = new Query(session, statement, queryManager, exchangeClient);
            queries.put(query.getQueryId(), query);
    
            return getQueryResults(query, Optional.empty(), uriInfo, new Duration(1, MILLISECONDS));
        }
    

    3、三个不同的类相同方法对比

    Execute Resource

    The execute resource is what the client sends queries to. It is
    available at the path ``/v1/execute``, and accepts a query as a POST
    and returns JSON.
    

    Query Resource

    The query resource takes a SQL query. It is available at the path
    ``/v1/query`` and accepts several HTTP methods.
    

    Statement Resource

    This is the standard resource used by the client to execute a
    statement. When executing a statement, the Presto client will
    call this resource repeatedly to get the status of an ongoing
    statement execution as well as the results of a completed
    statement.
    

    可以看出来Statement Resource这种是标准的用于client查询用的。

    相关文章

      网友评论

          本文标题:presto(九)——restful api之execute

          本文链接:https://www.haomeiwen.com/subject/gavrnttx.html