Search in sources :

Example 1 with DynamicResult

use of org.apache.flink.table.client.gateway.local.result.DynamicResult in project flink by apache.

the class LocalExecutor method executeQuery.

@Override
public ResultDescriptor executeQuery(String sessionId, QueryOperation query) throws SqlExecutionException {
    final TableResultInternal tableResult = executeOperation(sessionId, query);
    final SessionContext context = getSessionContext(sessionId);
    final ReadableConfig config = context.getReadableConfig();
    final DynamicResult result = resultStore.createResult(config, tableResult);
    checkArgument(tableResult.getJobClient().isPresent());
    String jobId = tableResult.getJobClient().get().getJobID().toString();
    // store the result under the JobID
    resultStore.storeResult(jobId, result);
    return new ResultDescriptor(jobId, tableResult.getResolvedSchema(), result.isMaterialized(), config, tableResult.getRowDataToStringConverter());
}
Also used : ReadableConfig(org.apache.flink.configuration.ReadableConfig) SessionContext(org.apache.flink.table.client.gateway.context.SessionContext) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) DynamicResult(org.apache.flink.table.client.gateway.local.result.DynamicResult) TableResultInternal(org.apache.flink.table.api.internal.TableResultInternal)

Example 2 with DynamicResult

use of org.apache.flink.table.client.gateway.local.result.DynamicResult in project flink by apache.

the class LocalExecutor method cancelQuery.

@Override
public void cancelQuery(String sessionId, String resultId) throws SqlExecutionException {
    final DynamicResult result = resultStore.getResult(resultId);
    if (result == null) {
        throw new SqlExecutionException("Could not find a result with result identifier '" + resultId + "'.");
    }
    // stop retrieval and remove the result
    LOG.info("Cancelling job {} and result retrieval.", resultId);
    try {
        // this operator will also stop flink job
        result.close();
    } catch (Exception e) {
        throw new SqlExecutionException("Could not cancel the query execution", e);
    }
    resultStore.removeResult(resultId);
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) DynamicResult(org.apache.flink.table.client.gateway.local.result.DynamicResult) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Aggregations

DynamicResult (org.apache.flink.table.client.gateway.local.result.DynamicResult)2 ReadableConfig (org.apache.flink.configuration.ReadableConfig)1 TableResultInternal (org.apache.flink.table.api.internal.TableResultInternal)1 ResultDescriptor (org.apache.flink.table.client.gateway.ResultDescriptor)1 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)1 SessionContext (org.apache.flink.table.client.gateway.context.SessionContext)1