REST Endpoint
This documentation is for an unreleased version of Apache Flink. We recommend you use the latest stable version.

REST Endpoint #

The REST endpoint allows user to connect to SQL Gateway with REST API.

Overview of SQL Processing #

Open Session #

When the client connects to the SQL Gateway, the SQL Gateway creates a Session as the context to store the users-specified information during the interactions between the client and SQL Gateway. After the creation of the Session, the SQL Gateway server returns an identifier named SessionHandle for later interactions.

Submit SQL #

After the registration of the Session, the client can submit the SQL to the SQL Gateway server. When submitting the SQL, the SQL is translated to an Operation and an identifier named OperationHandle is returned for fetch results later. The Operation has its lifecycle, the client is able to cancel the execution of the Operation or close the Operation to release the resources used by the Operation.

Fetch Results #

With the OperationHandle, the client can fetch the results from the Operation. If the Operation is ready, the SQL Gateway will return a batch of the data with the corresponding schema and a URI that is used to fetch the next batch of the data. When all results have been fetched, the SQL Gateway will fill the resultType in the response with value EOS and the URI to the next batch of the data is null.

SQL Gateway Interactions

Endpoint Options #

Key Default Type Description
sql-gateway.endpoint.rest.address
(none) String The address that should be used by clients to connect to the sql gateway server.
sql-gateway.endpoint.rest.bind-address
(none) String The address that the sql gateway server binds itself.
sql-gateway.endpoint.rest.bind-port
"8083" String The port that the sql gateway server binds itself. Accepts a list of ports (“50100,50101”), ranges (“50100-50200”) or a combination of both. It is recommended to set a range of ports to avoid collisions when multiple sql gateway servers are running on the same machine.
sql-gateway.endpoint.rest.port
8083 Integer The port that the client connects to. If bind-port has not been specified, then the sql gateway server will bind to this port.

REST API #

The available OpenAPI specification is as follows. The default version is v2.

Version Description
Open API v1 specification Allow users to submit statements to the gateway and execute.
Open API v2 specification Supports SQL Client to connect to the gateway.
The OpenAPI specification is still experimental.

API reference #

/api_versions
Verb: GET Response code: 200 OK
Get the current available versions for the Rest Endpoint. The client can choose one of the return version as the protocol for later communicate.
/info
Verb: GET Response code: 200 OK
Get meta data for this cluster.
/sessions
Verb: POST Response code: 200 OK
Opens a new session with specific properties. Specific properties can be given for current session which will override the default properties of gateway.
/sessions/:session_handle
Verb: DELETE Response code: 200 OK
Closes the specific session.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle
Verb: GET Response code: 200 OK
Get the session configuration.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/complete-statement
Verb: GET Response code: 200 OK
Get the completion hints for the given statement at the given position.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/configure-session
Verb: POST Response code: 200 OK
Configures the session with the statement which could be: CREATE TABLE, DROP TABLE, ALTER TABLE, CREATE DATABASE, DROP DATABASE, ALTER DATABASE, CREATE FUNCTION, DROP FUNCTION, ALTER FUNCTION, CREATE CATALOG, DROP CATALOG, USE CATALOG, USE [CATALOG.]DATABASE, CREATE VIEW, DROP VIEW, LOAD MODULE, UNLOAD MODULE, USE MODULE, ADD JAR.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/heartbeat
Verb: POST Response code: 200 OK
Trigger heartbeat to tell the server that the client is active, and to keep the session alive as long as configured timeout value.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/operations/:operation_handle/cancel
Verb: POST Response code: 200 OK
Cancel the operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/operations/:operation_handle/close
Verb: DELETE Response code: 200 OK
Close the operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/operations/:operation_handle/result/:token
Verb: GET Response code: 200 OK
Fetch results of Operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
  • token - The OperationHandle that identifies a operation.
Query parameters
  • rowFormat (mandatory): The row format to serialize the RowData.
/sessions/:session_handle/operations/:operation_handle/status
Verb: GET Response code: 200 OK
Get the status of operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/statements
Verb: POST Response code: 200 OK
Execute a statement.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/api_versions
Verb: GET Response code: 200 OK
Get the current available versions for the Rest Endpoint. The client can choose one of the return version as the protocol for later communicate.
/info
Verb: GET Response code: 200 OK
Get meta data for this cluster.
/sessions
Verb: POST Response code: 200 OK
Opens a new session with specific properties. Specific properties can be given for current session which will override the default properties of gateway.
/sessions/:session_handle
Verb: DELETE Response code: 200 OK
Closes the specific session.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle
Verb: GET Response code: 200 OK
Get the session configuration.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/heartbeat
Verb: POST Response code: 200 OK
Trigger heartbeat to tell the server that the client is active, and to keep the session alive as long as configured timeout value.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/operations/:operation_handle/cancel
Verb: POST Response code: 200 OK
Cancel the operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/operations/:operation_handle/close
Verb: DELETE Response code: 200 OK
Close the operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/operations/:operation_handle/result/:token
Verb: GET Response code: 200 OK
Fetch results of Operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
  • token - The OperationHandle that identifies a operation.
/sessions/:session_handle/operations/:operation_handle/status
Verb: GET Response code: 200 OK
Get the status of operation.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
  • operation_handle - The OperationHandle that identifies a operation.
/sessions/:session_handle/statements
Verb: POST Response code: 200 OK
Execute a statement.
Path parameters
  • session_handle - The SessionHandle that identifies a session.

Data Type Mapping #

Currently, REST endpoint supports to serialize the RowData with query parameter rowFormat. REST endpoint uses JSON format to serialize the Table Objects. Please refer JSON format to the mappings.

REST endpoint also supports to serialize the RowData with PLAIN_TEXT format that automatically cast all columns to the String.

Back to top