You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Motivation

The purpose of this document is to outline the design of refactored HTTP (aka REST) API for AsterixDB.

The reason for HTTP API refactoring is threefold:

 

  • Currently we have various REST endpoints (/ddl, /query, /update, /aql, /queryService), which do similar things (parsing parameters out of the request parameters, assembling the response) but each endpoint does it in a slightly different manner. All of that should be refactored to use the common base endpoint, which . At the same time old endpoints could be kept for backwards-compatibility if that it really needed.

  • Current Web interface does the server-side HTML generation and does not use REST calls whatsoever. It would be better to eat our own dog food here and switch to assembling the result on the client side using JavaScript. Especially since we have a potential GSoC project proposal to build such JS-based interface.

  • As we are moving towards having more query languages under AsterixDB umbrella (AQL, SQL++, XQuery\JSONiq as a part of VXQuery) it would be nice to design a generic language-agnostic REST API, which later could be reused by VXQuery since it's also lacking proper API as of now.

Tools and existing APIs

The design is inspired by N1QL REST API (http://developer.couchbase.com/documentation/server/4.1/n1ql/n1ql-rest-api/index.html) since it is an example of wel thoguht API in the similar system. I believe we don't need to be 100% compatible, although it would be nice to be to reuse the same clients.

We might also consider use Swagger (http://swagger.io/) to describe the API. This library will allow users to seamlessly generate client SDKs in their favorite language, which is especially usefully since we don't provide drivers for any clients. Here is the complete set of features which Swagger will allow us to do:

  • Describe API in developer-friendly way by creating yaml description.
  • Validate correctness of the server-side implementation.
  • Generate client-side SDK for various languages.
  • Generate documentation for API.

REST Endpoints

Proposed API consists of 3 endpoints: Query, Status and Result. The latter two are needed only in a case of asynchronous data delivery, while the former is the main endpoint and serves as an entry point for all client requests.

Query Endpoint (/query)

The following compares various parameters & HTTP headers using in N1QL API and in current AsterixDB API and proposes parameters to be used in new API.

HTTP Request(POST) parameters:

 

N1QL API Parameter

Value

Old Asterix API Parameter

Proposed API Parameter

Comment

statement

string

query

statement

Any valid AQL statement (DDL, update\load statement, flowr query), which should be executed

format

enum

Accept HTTP header

Accept HTTP header

Desired format for the query results. Possible values are ADM (default), JSON, CSV, XML (for VXQuery)

signature

boolean

header

signature

Defines whether to include a header for the results schema in the response. In current Asterix used to include CSV header into response.

 

enum

mode

mode

Result delivery mode. Possible values are asynchronous, asynchronous-deferred, synchronous(default)

 

boolean

lossless

lossless

Defines whether to use  lossless-JSON output for JSON-encoded output ( or keep clean-JSON instead)

 

boolean

wrapper-array

wrapper-array

Defines whether to wrap ADM-encoded output into array-braces

 

boolean

print-expr-tree

expr-tree

Defines whether to include an query expression AST into the result

 

boolean

print-rewritten-expr-tree

rewritten-expr-tree

Defines whether to include a rewritten query expression AST into the result

 

boolean

print-logical-plan

logical-plan

Defines whether to include a logical plan into the result

 

boolean

print-optimized-logical-plan

optimized-plan

Defines whether to include a optimized logical plan into the result

 

boolean

print-job

hyracks-job

Defines whether to include a Hyracks job into the result

 

boolean

execute-query

execute-query

Defines whether to execute a query

HTTP Response parameters:

 

Type of the response - JSON document (even if format in request was XML\CSV it will be serialized as one of JSON attributes)

N1QL API Parameter

Value

Old Asterix API Parameter

Proposed API Parameter

Comment

results

JSONList

HTTP response body

results

One of three possible values depending on result delivery

1) A list of all results returned by the query (sync result delivery).

2) A list of all URIs to QueryStatus endpoint (async result delivery).

3) No value (DDL\update\load)

status

string

HTTP response status

status

The status of the request; possible values are: Success, Running (async result), Error (parse\optimizer error), Fatal (execution error).

error

JSONObject

HTTP response body

error

An object containing details of the error

error.code

int

error-code

error.code

A code that identifies the error.

error.msg

string

summary

error.msg

A message describing the error in detail.

  

stacktrace

 

A stack trace of the error.

metrics

JSONObject

 

metrics

An object containing details of the  execution metrics.

metrics.executionTime

string

 

metrics.executionTime

The time taken for the execution of the request, i.e. time from when query execution started until the results were returned. (if execute-query=true)

metrics.resultCount

unsigned int

 

metrics.resultCount

The total number of objects in the results (sync result & execute-query=true)

 

JSONObject

 

metrics.expr_tree

Serialized query expression tree (if expr-tree=true)

 

JSONObject

 

metrics.rewritten_expr_tree

Serialized rewritten query expression tree (if rewritten-expr-tree=true)

 

JSONObject

 

metrics.logical_plan

Serialized query logical plan (if logical-plan=true)

 

JSONObject

 

metrics.optimized_plan

Serialized query optimized logical plan (if optimized-plan=true)

 

JSONObject

 

metrics.hyracks_job

Serialized Hyracks job (if hyracks-job=true)

 


  • No labels