Class SqlGatewayServiceImpl
- java.lang.Object
-
- org.apache.flink.table.gateway.service.SqlGatewayServiceImpl
-
- All Implemented Interfaces:
SqlGatewayService
public class SqlGatewayServiceImpl extends Object implements SqlGatewayService
The implementation of theSqlGatewayService
interface.
-
-
Constructor Summary
Constructors Constructor Description SqlGatewayServiceImpl(SessionManager sessionManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelOperation(SessionHandle sessionHandle, OperationHandle operationHandle)
Cancel the operation when it is not in terminal status.void
closeOperation(SessionHandle sessionHandle, OperationHandle operationHandle)
Close the operation and release all used resource by the operation.void
closeSession(SessionHandle sessionHandle)
Close theSession
.List<String>
completeStatement(SessionHandle sessionHandle, String statement, int position)
Returns a list of completion hints for the given statement at the given position.void
configureSession(SessionHandle sessionHandle, String statement, long executionTimeoutMs)
Using the statement to initialize the Session.OperationHandle
executeStatement(SessionHandle sessionHandle, String statement, long executionTimeoutMs, Configuration executionConfig)
Execute the submitted statement.ResultSet
fetchResults(SessionHandle sessionHandle, OperationHandle operationHandle, long token, int maxRows)
Fetch the results from the operation.ResultSet
fetchResults(SessionHandle sessionHandle, OperationHandle operationHandle, FetchOrientation orientation, int maxRows)
Fetch the results from the operation.String
getCurrentCatalog(SessionHandle sessionHandle)
Return current catalog name.FunctionDefinition
getFunctionDefinition(SessionHandle sessionHandle, UnresolvedIdentifier functionIdentifier)
Get the specific definition of the function.GatewayInfo
getGatewayInfo()
Get the info about theSqlGatewayService
.OperationInfo
getOperationInfo(SessionHandle sessionHandle, OperationHandle operationHandle)
Get theOperationInfo
of the operation.ResolvedSchema
getOperationResultSchema(SessionHandle sessionHandle, OperationHandle operationHandle)
Get the result schema for the specified Operation.Session
getSession(SessionHandle sessionHandle)
Map<String,String>
getSessionConfig(SessionHandle sessionHandle)
Get the current configuration of theSession
.EndpointVersion
getSessionEndpointVersion(SessionHandle sessionHandle)
Get endpoint version that is negotiated in the openSession.ResolvedCatalogBaseTable<?>
getTable(SessionHandle sessionHandle, ObjectIdentifier tableIdentifier)
Return table of the given fully qualified name.Set<String>
listCatalogs(SessionHandle sessionHandle)
Return all available catalogs in the current session.Set<String>
listDatabases(SessionHandle sessionHandle, String catalogName)
Return all available schemas in the given catalog.Set<FunctionInfo>
listSystemFunctions(SessionHandle sessionHandle)
List all available system functions.Set<TableInfo>
listTables(SessionHandle sessionHandle, String catalogName, String databaseName, Set<CatalogBaseTable.TableKind> tableKinds)
Return all available tables/views in the given catalog and database.Set<FunctionInfo>
listUserDefinedFunctions(SessionHandle sessionHandle, String catalogName, String databaseName)
List all user defined functions.SessionHandle
openSession(SessionEnvironment environment)
Open theSession
.OperationHandle
refreshMaterializedTable(SessionHandle sessionHandle, String materializedTableIdentifier, boolean isPeriodic, String scheduleTime, Map<String,String> dynamicOptions, Map<String,String> staticPartitions, Map<String,String> executionConfig)
Trigger a refresh operation of specific materialized table.OperationHandle
submitOperation(SessionHandle sessionHandle, Callable<ResultSet> executor)
Submit an operation and execute.
-
-
-
Constructor Detail
-
SqlGatewayServiceImpl
public SqlGatewayServiceImpl(SessionManager sessionManager)
-
-
Method Detail
-
openSession
public SessionHandle openSession(SessionEnvironment environment) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Open theSession
.- Specified by:
openSession
in interfaceSqlGatewayService
- Parameters:
environment
- Environment to initialize the Session.- Returns:
- Returns a handle that used to identify the Session.
- Throws:
SqlGatewayException
-
closeSession
public void closeSession(SessionHandle sessionHandle) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Close theSession
.- Specified by:
closeSession
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the Session needs to be closed.- Throws:
SqlGatewayException
-
configureSession
public void configureSession(SessionHandle sessionHandle, String statement, long executionTimeoutMs) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Using the statement to initialize the Session. It's only allowed to execute SET/RESET/CREATE/DROP/USE/ALTER/LOAD MODULE/UNLOAD MODULE/ADD JAR.It returns until the execution finishes.
- Specified by:
configureSession
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.statement
- the statement used to configure the session.executionTimeoutMs
- the execution timeout. Please use non-positive value to forbid the timeout mechanism.- Throws:
SqlGatewayException
-
getSessionConfig
public Map<String,String> getSessionConfig(SessionHandle sessionHandle) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Get the current configuration of theSession
.- Specified by:
getSessionConfig
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.- Returns:
- Returns configuration of the session.
- Throws:
SqlGatewayException
-
getSessionEndpointVersion
public EndpointVersion getSessionEndpointVersion(SessionHandle sessionHandle) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Get endpoint version that is negotiated in the openSession.- Specified by:
getSessionEndpointVersion
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.- Returns:
- Returns the version.
- Throws:
SqlGatewayException
-
submitOperation
public OperationHandle submitOperation(SessionHandle sessionHandle, Callable<ResultSet> executor) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Submit an operation and execute. TheSqlGatewayService
will take care of the execution and assign theOperationHandle
for later to retrieve the results.- Specified by:
submitOperation
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.executor
- the main logic to get the execution results.- Returns:
- Returns the handle for later retrieve results.
- Throws:
SqlGatewayException
-
cancelOperation
public void cancelOperation(SessionHandle sessionHandle, OperationHandle operationHandle)
Description copied from interface:SqlGatewayService
Cancel the operation when it is not in terminal status.It can't cancel an Operation if it is terminated.
- Specified by:
cancelOperation
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.JarURLConnection
-
closeOperation
public void closeOperation(SessionHandle sessionHandle, OperationHandle operationHandle)
Description copied from interface:SqlGatewayService
Close the operation and release all used resource by the operation.- Specified by:
closeOperation
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.
-
getOperationInfo
public OperationInfo getOperationInfo(SessionHandle sessionHandle, OperationHandle operationHandle)
Description copied from interface:SqlGatewayService
Get theOperationInfo
of the operation.- Specified by:
getOperationInfo
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.
-
getOperationResultSchema
public ResolvedSchema getOperationResultSchema(SessionHandle sessionHandle, OperationHandle operationHandle) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Get the result schema for the specified Operation.Note: The result schema is available when the Operation is in the
OperationStatus.FINISHED
.- Specified by:
getOperationResultSchema
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.- Throws:
SqlGatewayException
-
executeStatement
public OperationHandle executeStatement(SessionHandle sessionHandle, String statement, long executionTimeoutMs, Configuration executionConfig) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Execute the submitted statement.- Specified by:
executeStatement
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.statement
- the SQL to execute.executionTimeoutMs
- the execution timeout. Please use non-positive value to forbid the timeout mechanism.executionConfig
- execution config for the statement.- Returns:
- handle to identify the operation.
- Throws:
SqlGatewayException
-
fetchResults
public ResultSet fetchResults(SessionHandle sessionHandle, OperationHandle operationHandle, long token, int maxRows) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Fetch the results from the operation. When maxRows is Integer.MAX_VALUE, it means to fetch all available data.- Specified by:
fetchResults
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.token
- token to identify results.maxRows
- max number of rows to fetch.- Returns:
- Returns the results.
- Throws:
SqlGatewayException
-
fetchResults
public ResultSet fetchResults(SessionHandle sessionHandle, OperationHandle operationHandle, FetchOrientation orientation, int maxRows)
Description copied from interface:SqlGatewayService
Fetch the results from the operation. When maxRows is Integer.MAX_VALUE, it means to fetch all available data. It promises to return at least one rows if the results is not end-of-stream.- Specified by:
fetchResults
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.operationHandle
- handle to identify the operation.orientation
- orientation to fetch the results.maxRows
- max number of rows to fetch.- Returns:
- Returns the results.
-
getCurrentCatalog
public String getCurrentCatalog(SessionHandle sessionHandle)
Description copied from interface:SqlGatewayService
Return current catalog name.- Specified by:
getCurrentCatalog
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.- Returns:
- name of the current catalog.
-
listCatalogs
public Set<String> listCatalogs(SessionHandle sessionHandle) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Return all available catalogs in the current session.- Specified by:
listCatalogs
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.- Returns:
- names of the registered catalogs.
- Throws:
SqlGatewayException
-
listDatabases
public Set<String> listDatabases(SessionHandle sessionHandle, String catalogName)
Description copied from interface:SqlGatewayService
Return all available schemas in the given catalog.- Specified by:
listDatabases
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.catalogName
- name string of the given catalog.- Returns:
- names of the registered schemas.
-
listTables
public Set<TableInfo> listTables(SessionHandle sessionHandle, String catalogName, String databaseName, Set<CatalogBaseTable.TableKind> tableKinds)
Description copied from interface:SqlGatewayService
Return all available tables/views in the given catalog and database.- Specified by:
listTables
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.catalogName
- name of the given catalog.databaseName
- name of the given database.tableKinds
- used to specify the type of return values.- Returns:
- table info of the registered tables/views.
-
getTable
public ResolvedCatalogBaseTable<?> getTable(SessionHandle sessionHandle, ObjectIdentifier tableIdentifier) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Return table of the given fully qualified name.- Specified by:
getTable
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.tableIdentifier
- fully qualified name of the table.- Returns:
- information of the table.
- Throws:
SqlGatewayException
-
refreshMaterializedTable
public OperationHandle refreshMaterializedTable(SessionHandle sessionHandle, String materializedTableIdentifier, boolean isPeriodic, @Nullable String scheduleTime, Map<String,String> dynamicOptions, Map<String,String> staticPartitions, Map<String,String> executionConfig)
Description copied from interface:SqlGatewayService
Trigger a refresh operation of specific materialized table.- Specified by:
refreshMaterializedTable
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.materializedTableIdentifier
- A fully qualified materialized table identifier: 'catalogName.databaseName.objectName', used for locating the materialized table in catalog.isPeriodic
- Represents whether the workflow is refreshed periodically or one-time-only.scheduleTime
- The time point at which the scheduler triggers this refresh operation.staticPartitions
- The specific partitions for one-time-only refresh workflow.executionConfig
- The flink job config.- Returns:
- handle to identify the operation.
-
listUserDefinedFunctions
public Set<FunctionInfo> listUserDefinedFunctions(SessionHandle sessionHandle, String catalogName, String databaseName) throws SqlGatewayException
Description copied from interface:SqlGatewayService
List all user defined functions.- Specified by:
listUserDefinedFunctions
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.catalogName
- name string of the given catalog.databaseName
- name string of the given database.- Returns:
- user defined functions info.
- Throws:
SqlGatewayException
-
listSystemFunctions
public Set<FunctionInfo> listSystemFunctions(SessionHandle sessionHandle)
Description copied from interface:SqlGatewayService
List all available system functions.- Specified by:
listSystemFunctions
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.- Returns:
- system functions info.
-
getFunctionDefinition
public FunctionDefinition getFunctionDefinition(SessionHandle sessionHandle, UnresolvedIdentifier functionIdentifier) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Get the specific definition of the function. If the input identifier only contains the function name, it is resolved with the order of the temporary system function, system function, temporary function and catalog function.- Specified by:
getFunctionDefinition
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.functionIdentifier
- identifier of the function.- Returns:
- the definition of the function.
- Throws:
SqlGatewayException
-
getGatewayInfo
public GatewayInfo getGatewayInfo()
Description copied from interface:SqlGatewayService
Get the info about theSqlGatewayService
.- Specified by:
getGatewayInfo
in interfaceSqlGatewayService
- Returns:
- Returns gateway info.
-
completeStatement
public List<String> completeStatement(SessionHandle sessionHandle, String statement, int position) throws SqlGatewayException
Description copied from interface:SqlGatewayService
Returns a list of completion hints for the given statement at the given position.- Specified by:
completeStatement
in interfaceSqlGatewayService
- Parameters:
sessionHandle
- handle to identify the session.statement
- sql statement to be completed.position
- position of where need completion hints.- Returns:
- completion hints.
- Throws:
SqlGatewayException
-
getSession
@VisibleForTesting public Session getSession(SessionHandle sessionHandle)
-
-