Search in sources :

Example 1 with ExecutionContext

use of org.apache.flink.table.client.gateway.context.ExecutionContext in project flink by apache.

the class LocalExecutor method executeOperation.

@Override
public TableResultInternal executeOperation(String sessionId, Operation operation) throws SqlExecutionException {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironmentInternal tEnv = (TableEnvironmentInternal) context.getTableEnvironment();
    try {
        return context.wrapClassLoader(() -> tEnv.executeInternal(operation));
    } catch (Exception e) {
        throw new SqlExecutionException(MESSAGE_SQL_EXECUTION_ERROR, e);
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Example 2 with ExecutionContext

use of org.apache.flink.table.client.gateway.context.ExecutionContext in project flink by apache.

the class LocalExecutor method completeStatement.

@Override
public List<String> completeStatement(String sessionId, String statement, int position) {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironmentInternal tableEnv = (TableEnvironmentInternal) context.getTableEnvironment();
    try {
        return context.wrapClassLoader(() -> Arrays.asList(tableEnv.getParser().getCompletionHints(statement, position)));
    } catch (Throwable t) {
        // catch everything such that the query does not crash the executor
        if (LOG.isDebugEnabled()) {
            LOG.debug("Could not complete statement at " + position + ":" + statement, t);
        }
        return Collections.emptyList();
    }
}
Also used : ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal)

Example 3 with ExecutionContext

use of org.apache.flink.table.client.gateway.context.ExecutionContext in project flink by apache.

the class LocalExecutor method parseStatement.

@Override
public Operation parseStatement(String sessionId, String statement) throws SqlExecutionException {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironment tableEnv = context.getTableEnvironment();
    Parser parser = ((TableEnvironmentInternal) tableEnv).getParser();
    List<Operation> operations;
    try {
        operations = context.wrapClassLoader(() -> parser.parse(statement));
    } catch (Exception e) {
        throw new SqlExecutionException("Failed to parse statement: " + statement, e);
    }
    if (operations.isEmpty()) {
        throw new SqlExecutionException("Failed to parse statement: " + statement);
    }
    return operations.get(0);
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) TableEnvironment(org.apache.flink.table.api.TableEnvironment) ModifyOperation(org.apache.flink.table.operations.ModifyOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) Operation(org.apache.flink.table.operations.Operation) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Parser(org.apache.flink.table.delegation.Parser)

Example 4 with ExecutionContext

use of org.apache.flink.table.client.gateway.context.ExecutionContext in project flink by apache.

the class LocalExecutor method executeModifyOperations.

@Override
public TableResultInternal executeModifyOperations(String sessionId, List<ModifyOperation> operations) throws SqlExecutionException {
    final ExecutionContext context = getExecutionContext(sessionId);
    final TableEnvironmentInternal tEnv = (TableEnvironmentInternal) context.getTableEnvironment();
    try {
        return context.wrapClassLoader(() -> tEnv.executeInternal(operations));
    } catch (Exception e) {
        throw new SqlExecutionException(MESSAGE_SQL_EXECUTION_ERROR, e);
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionContext(org.apache.flink.table.client.gateway.context.ExecutionContext) TableEnvironmentInternal(org.apache.flink.table.api.internal.TableEnvironmentInternal) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Aggregations

TableEnvironmentInternal (org.apache.flink.table.api.internal.TableEnvironmentInternal)4 ExecutionContext (org.apache.flink.table.client.gateway.context.ExecutionContext)4 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)3 TableEnvironment (org.apache.flink.table.api.TableEnvironment)1 Parser (org.apache.flink.table.delegation.Parser)1 ModifyOperation (org.apache.flink.table.operations.ModifyOperation)1 Operation (org.apache.flink.table.operations.Operation)1 QueryOperation (org.apache.flink.table.operations.QueryOperation)1