Search in sources :

Example 11 with SqlExecutionException

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));
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Configuration(org.apache.flink.configuration.Configuration) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) Test(org.junit.Test)

Example 12 with SqlExecutionException

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));
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Configuration(org.apache.flink.configuration.Configuration) ResultDescriptor(org.apache.flink.table.client.gateway.ResultDescriptor) TypedResult(org.apache.flink.table.client.gateway.TypedResult) Test(org.junit.Test)

Example 13 with SqlExecutionException

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;
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) EndOfFileException(org.jline.reader.EndOfFileException) IOError(java.io.IOError) SqlClientException(org.apache.flink.table.client.SqlClientException) ModifyOperation(org.apache.flink.table.operations.ModifyOperation) AlterOperation(org.apache.flink.table.operations.ddl.AlterOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) DropOperation(org.apache.flink.table.operations.ddl.DropOperation) ShowCreateViewOperation(org.apache.flink.table.operations.ShowCreateViewOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) HelpOperation(org.apache.flink.table.operations.command.HelpOperation) QuitOperation(org.apache.flink.table.operations.command.QuitOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) CreateOperation(org.apache.flink.table.operations.ddl.CreateOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ClearOperation(org.apache.flink.table.operations.command.ClearOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) ShowCreateTableOperation(org.apache.flink.table.operations.ShowCreateTableOperation) UseOperation(org.apache.flink.table.operations.UseOperation) UserInterruptException(org.jline.reader.UserInterruptException)

Example 14 with SqlExecutionException

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;
}
Also used : Executor(org.apache.flink.table.client.gateway.Executor) FlinkException(org.apache.flink.util.FlinkException) CliFrontendParser(org.apache.flink.client.cli.CliFrontendParser) Logger(org.slf4j.Logger) CliArgsException(org.apache.flink.client.cli.CliArgsException) ProgramOptions(org.apache.flink.client.cli.ProgramOptions) URL(java.net.URL) CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) ExecutionConfigAccessor(org.apache.flink.client.cli.ExecutionConfigAccessor) Configuration(org.apache.flink.configuration.Configuration) Options(org.apache.commons.cli.Options) LoggerFactory(org.slf4j.LoggerFactory) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) FileSystem(org.apache.flink.core.fs.FileSystem) PluginUtils(org.apache.flink.core.plugin.PluginUtils) CommandLine(org.apache.commons.cli.CommandLine) CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) Configuration(org.apache.flink.configuration.Configuration) ExecutionConfigAccessor(org.apache.flink.client.cli.ExecutionConfigAccessor) CliArgsException(org.apache.flink.client.cli.CliArgsException) ProgramOptions(org.apache.flink.client.cli.ProgramOptions)

Example 15 with SqlExecutionException

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);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URL(java.net.URL)

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