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

KeyDefaultTypeDescription
sql-gateway.endpoint.rest.address
(none)StringThe address that should be used by clients to connect to the sql gateway server.
sql-gateway.endpoint.rest.bind-address
(none)StringThe address that the sql gateway server binds itself.
sql-gateway.endpoint.rest.bind-port
“8083”StringThe 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
8083IntegerThe 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

[OpenAPI specification](http://nightlies.apache.org/flink/flink-docs-release-1.16/zh/docs/dev/table/sql-gateway/rest/

/nightlies.apache.org/flink/flink-docs-release-1.16/generated/rest_v1_sql_gateway.yml )

The OpenAPI specification is still experimental.

API reference

v1

/api_versions
Verb: GETResponse 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: GETResponse code: 200 OK
Get meta data for this cluster.
/sessions
Verb: POSTResponse 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: DELETEResponse code: 200 OK
Closes the specific session.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle
Verb: GETResponse code: 200 OK
Get the session configuration.
Path parameters
  • session_handle - The SessionHandle that identifies a session.
/sessions/:session_handle/heartbeat
Verb: POSTResponse 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: POSTResponse 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: DELETEResponse 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: GETResponse 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: GETResponse 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: POSTResponse code: 200 OK
Execute a statement.
Path parameters
  • session_handle - The SessionHandle that identifies a session.

Data Type Mapping

Currently, REST endpoint uses JSON format to serialize the Table Objects. Please refer JSON format to the mappings.