use of org.apache.flink.table.client.gateway.SqlExecutionException in project flink by apache.
the class CliTableauResultViewTest method testFailedBatchResult.
@Test
public void testFailedBatchResult() {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(() -> {
throw new SqlExecutionException("query failed");
}, TypedResult::endOfStream).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
try {
view.displayResults();
Assert.fail("Shouldn't get here");
} catch (SqlExecutionException e) {
Assert.assertEquals("query failed", e.getMessage());
}
view.close();
assertThat(mockExecutor.getNumCancelCalls(), is(1));
}
use of org.apache.flink.table.client.gateway.SqlExecutionException in project flink by apache.
the class CliTableauResultViewTest method testEmptyBatchResult.
@Test
public void testEmptyBatchResult() {
final Configuration testConfig = new Configuration();
testConfig.set(EXECUTION_RESULT_MODE, ResultMode.TABLEAU);
testConfig.set(RUNTIME_MODE, RuntimeExecutionMode.BATCH);
ResultDescriptor resultDescriptor = new ResultDescriptor("", schema, true, testConfig, rowDataToStringConverter);
TestingExecutor mockExecutor = new TestingExecutorBuilder().setResultChangesSupplier(TypedResult::endOfStream).setResultPageSupplier(() -> {
throw new SqlExecutionException("query failed");
}).build();
CliTableauResultView view = new CliTableauResultView(terminal, mockExecutor, "session", resultDescriptor);
view.displayResults();
view.close();
Assert.assertEquals("Empty set" + System.lineSeparator(), terminalOutput.toString());
assertThat(mockExecutor.getNumCancelCalls(), is(0));
}
use of org.apache.flink.table.client.gateway.SqlExecutionException in project flink by apache.
the class CliClient method getAndExecuteStatements.
private boolean getAndExecuteStatements(LineReader lineReader, ExecutionMode mode) {
// begin reading loop
boolean exitOnFailure = !mode.equals(ExecutionMode.INTERACTIVE_EXECUTION);
isRunning = true;
while (isRunning) {
// make some space to previous command
terminal.writer().append("\n");
terminal.flush();
Optional<Operation> parsedOperation = Optional.empty();
try {
// read a statement from terminal and parse it
String line = lineReader.readLine(prompt, null, inputTransformer, null);
if (line.trim().isEmpty()) {
continue;
}
// get the parsed operation.
// if the command is invalid, the exception caught from parser would be thrown.
parsedOperation = parser.getParsedOperation();
Preconditions.checkArgument(line.equals(parser.getCommand()), String.format("This is a bug, please report to the flink community. Statement read[%s] isn't the same as statement parsed[%s]", line, parser.getCommand()));
} catch (SqlExecutionException e) {
// print the detailed information on about the parse errors in the terminal.
printExecutionException(e);
if (exitOnFailure) {
return false;
}
} catch (UserInterruptException e) {
// user cancelled line with Ctrl+C
continue;
} catch (EndOfFileException | IOError e) {
// user cancelled application with Ctrl+D or kill
break;
} catch (Throwable t) {
throw new SqlClientException("Could not read from command line.", t);
}
// no operation available, read next command
if (!parsedOperation.isPresent()) {
continue;
}
// execute the operation
boolean success = executeOperation(parsedOperation.get(), mode);
if (exitOnFailure && !success) {
return false;
}
}
// finish all statements.
return true;
}
use of org.apache.flink.table.client.gateway.SqlExecutionException in project flink by apache.
the class DefaultContext method createExecutionConfig.
private static Configuration createExecutionConfig(CommandLine commandLine, Options commandLineOptions, List<CustomCommandLine> availableCommandLines, List<URL> dependencies) throws FlinkException {
LOG.debug("Available commandline options: {}", commandLineOptions);
List<String> options = Stream.of(commandLine.getOptions()).map(o -> o.getOpt() + "=" + o.getValue()).collect(Collectors.toList());
LOG.debug("Instantiated commandline args: {}, options: {}", commandLine.getArgList(), options);
final CustomCommandLine activeCommandLine = findActiveCommandLine(availableCommandLines, commandLine);
LOG.debug("Available commandlines: {}, active commandline: {}", availableCommandLines, activeCommandLine);
Configuration executionConfig = activeCommandLine.toConfiguration(commandLine);
try {
final ProgramOptions programOptions = ProgramOptions.create(commandLine);
final ExecutionConfigAccessor executionConfigAccessor = ExecutionConfigAccessor.fromProgramOptions(programOptions, dependencies);
executionConfigAccessor.applyToConfiguration(executionConfig);
} catch (CliArgsException e) {
throw new SqlExecutionException("Invalid deployment run options.", e);
}
LOG.info("Executor config: {}", executionConfig);
return executionConfig;
}
use of org.apache.flink.table.client.gateway.SqlExecutionException in project flink by apache.
the class SessionContext method getURLFromPath.
private URL getURLFromPath(String jarPath, String message) {
Path path = new Path(jarPath);
String scheme = path.toUri().getScheme();
if (scheme != null && !scheme.equals("file")) {
throw new SqlExecutionException(message);
}
Path qualifiedPath = path.makeQualified(FileSystem.getLocalFileSystem());
try {
URL jarURL = qualifiedPath.toUri().toURL();
JarUtils.checkJarFile(jarURL);
return jarURL;
} catch (MalformedURLException e) {
throw new SqlExecutionException(String.format("Failed to parse the input jar path: %s", jarPath), e);
} catch (IOException e) {
throw new SqlExecutionException(String.format("Failed to get the jar file with specified path: %s", jarPath), e);
}
}
Aggregations