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);
}
}
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);
}
}
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);
}
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());
}
}
}
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);
}
}
Aggregations