Search in sources :

Example 1 with SqlExecutionException

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

the class SessionContext method set.

/**
 * Set properties. It will rebuild a new {@link ExecutionContext}
 */
public void set(String key, String value) {
    Configuration originConfiguration = sessionConfiguration.clone();
    sessionConfiguration.setString(key, value);
    try {
        // Renew the ExecutionContext.
        // Book keep all the session states of current ExecutionContext then
        // re-register them into the new one.
        ExecutionContext newContext = new ExecutionContext(executionContext);
        // update the reference
        this.executionContext = newContext;
    } catch (Exception e) {
        // get error and reset the key with old value
        resetSessionConfigurationToDefault(originConfiguration);
        throw new SqlExecutionException(String.format("Failed to set key %s with value %s.", key, value), e);
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Configuration(org.apache.flink.configuration.Configuration) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Example 2 with SqlExecutionException

use of org.apache.flink.table.client.gateway.SqlExecutionException 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 3 with SqlExecutionException

use of org.apache.flink.table.client.gateway.SqlExecutionException 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)

Example 4 with SqlExecutionException

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

the class CliTableauResultView method printStreamingResults.

private void printStreamingResults(AtomicInteger receivedRowCount) {
    TableauStyle style = PrintStyle.tableauWithTypeInferredColumnWidths(resultDescriptor.getResultSchema(), resultDescriptor.getRowDataStringConverter(), resultDescriptor.maxColumnWidth(), false, true);
    // print filed names
    style.printBorderLine(terminal.writer());
    style.printColumnNamesTableauRow(terminal.writer());
    style.printBorderLine(terminal.writer());
    terminal.flush();
    while (true) {
        final TypedResult<List<RowData>> result = sqlExecutor.retrieveResultChanges(sessionId, resultDescriptor.getResultId());
        switch(result.getType()) {
            case EMPTY:
                try {
                    // prevent busy loop
                    Thread.sleep(1);
                } catch (InterruptedException e) {
                    // get ctrl+c from terminal and fallback
                    return;
                }
                break;
            case EOS:
                if (receivedRowCount.get() > 0) {
                    style.printBorderLine(terminal.writer());
                }
                String rowTerm = getRowTerm(receivedRowCount);
                terminal.writer().println("Received a total of " + receivedRowCount.get() + " " + rowTerm);
                terminal.flush();
                return;
            case PAYLOAD:
                List<RowData> changes = result.getPayload();
                for (RowData change : changes) {
                    style.printTableauRow(style.rowFieldsToString(change), terminal.writer());
                    receivedRowCount.incrementAndGet();
                }
                break;
            default:
                throw new SqlExecutionException("Unknown result type: " + result.getType());
        }
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) RowData(org.apache.flink.table.data.RowData) ArrayList(java.util.ArrayList) List(java.util.List) TableauStyle(org.apache.flink.table.utils.print.TableauStyle)

Example 5 with SqlExecutionException

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

the class CliTableauResultView method displayResults.

public void displayResults() throws SqlExecutionException {
    final AtomicInteger receivedRowCount = new AtomicInteger(0);
    Future<?> resultFuture = displayResultExecutorService.submit(() -> {
        if (resultDescriptor.isStreamingMode()) {
            printStreamingResults(receivedRowCount);
        } else {
            printBatchResults(receivedRowCount);
        }
    });
    // capture CTRL-C
    terminal.handle(Terminal.Signal.INT, signal -> {
        resultFuture.cancel(true);
    });
    boolean cleanUpQuery = true;
    try {
        resultFuture.get();
        // job finished successfully
        cleanUpQuery = false;
    } catch (CancellationException e) {
        terminal.writer().println("Query terminated, received a total of " + receivedRowCount.get() + " " + getRowTerm(receivedRowCount));
        terminal.flush();
    } catch (ExecutionException e) {
        if (e.getCause() instanceof SqlExecutionException) {
            throw (SqlExecutionException) e.getCause();
        }
        throw new SqlExecutionException("unknown exception", e.getCause());
    } catch (InterruptedException e) {
        throw new SqlExecutionException("Query interrupted", e);
    } finally {
        checkAndCleanUpQuery(cleanUpQuery);
    }
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CancellationException(java.util.concurrent.CancellationException) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)19 Configuration (org.apache.flink.configuration.Configuration)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Test (org.junit.Test)4 MalformedURLException (java.net.MalformedURLException)3 TableEnvironmentInternal (org.apache.flink.table.api.internal.TableEnvironmentInternal)3 ResultDescriptor (org.apache.flink.table.client.gateway.ResultDescriptor)3 ExecutionContext (org.apache.flink.table.client.gateway.context.ExecutionContext)3 IOException (java.io.IOException)2 SqlClientException (org.apache.flink.table.client.SqlClientException)2 RowData (org.apache.flink.table.data.RowData)2 ModifyOperation (org.apache.flink.table.operations.ModifyOperation)2 Operation (org.apache.flink.table.operations.Operation)2 QueryOperation (org.apache.flink.table.operations.QueryOperation)2 File (java.io.File)1 IOError (java.io.IOError)1 URISyntaxException (java.net.URISyntaxException)1 LinkedList (java.util.LinkedList)1