Search in sources :

Example 1 with SqlClientException

use of org.apache.flink.table.client.SqlClientException in project flink by apache.

the class CliOptionsParser method parseGatewayModeClient.

public static CliOptions parseGatewayModeClient(String[] args) {
    try {
        DefaultParser parser = new DefaultParser();
        CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true);
        return new CliOptions(line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()), checkSessionId(line), null, null, checkUrls(line, CliOptionsParser.OPTION_JAR), checkUrls(line, CliOptionsParser.OPTION_LIBRARY), line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt()), line.getOptionValue(CliOptionsParser.OPTION_HISTORY.getOpt()), getPythonConfiguration(line));
    } catch (ParseException e) {
        throw new SqlClientException(e.getMessage());
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) SqlClientException(org.apache.flink.table.client.SqlClientException) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 2 with SqlClientException

use of org.apache.flink.table.client.SqlClientException in project flink by apache.

the class CliOptionsParser method getPythonConfiguration.

private static Configuration getPythonConfiguration(CommandLine line) {
    try {
        Class<?> clazz = Class.forName("org.apache.flink.python.util.PythonDependencyUtils", true, Thread.currentThread().getContextClassLoader());
        Method parsePythonDependencyConfiguration = clazz.getMethod("parsePythonDependencyConfiguration", CommandLine.class);
        return (Configuration) parsePythonDependencyConfiguration.invoke(null, line);
    } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw new SqlClientException("Failed to parse the Python command line options.", e);
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SqlClientException(org.apache.flink.table.client.SqlClientException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with SqlClientException

use of org.apache.flink.table.client.SqlClientException in project flink by apache.

the class LocalContextUtils method discoverDependencies.

// --------------------------------------------------------------------------------------------
private static List<URL> discoverDependencies(List<URL> jars, List<URL> libraries) {
    final List<URL> dependencies = new ArrayList<>();
    try {
        // find jar files
        for (URL url : jars) {
            JarUtils.checkJarFile(url);
            dependencies.add(url);
        }
        // find jar files in library directories
        for (URL libUrl : libraries) {
            final File dir = new File(libUrl.toURI());
            if (!dir.isDirectory()) {
                throw new SqlClientException("Directory expected: " + dir);
            } else if (!dir.canRead()) {
                throw new SqlClientException("Directory cannot be read: " + dir);
            }
            final File[] files = dir.listFiles();
            if (files == null) {
                throw new SqlClientException("Directory cannot be read: " + dir);
            }
            for (File f : files) {
                // only consider jars
                if (f.isFile() && f.getAbsolutePath().toLowerCase().endsWith(".jar")) {
                    final URL url = f.toURI().toURL();
                    JarUtils.checkJarFile(url);
                    dependencies.add(url);
                }
            }
        }
    } catch (Exception e) {
        throw new SqlClientException("Could not load all required JAR files.", e);
    }
    // add python dependencies by default
    try {
        URL location = Class.forName("org.apache.flink.python.PythonFunctionRunner", false, Thread.currentThread().getContextClassLoader()).getProtectionDomain().getCodeSource().getLocation();
        if (Paths.get(location.toURI()).toFile().isFile()) {
            dependencies.add(location);
        }
    } catch (URISyntaxException | ClassNotFoundException e) {
        // dependencies
        throw new SqlExecutionException("Don't find python dependencies. Please add the flink-python jar via `--jar` command option manually.", e);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Using the following dependencies: {}", dependencies);
    }
    return dependencies;
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) SqlClientException(org.apache.flink.table.client.SqlClientException) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URL(java.net.URL) SqlClientException(org.apache.flink.table.client.SqlClientException) URISyntaxException(java.net.URISyntaxException) SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException)

Example 4 with SqlClientException

use of org.apache.flink.table.client.SqlClientException 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 5 with SqlClientException

use of org.apache.flink.table.client.SqlClientException in project flink by apache.

the class CliOptionsParser method checkFilePath.

public static void checkFilePath(String filePath) {
    Path path = new Path(filePath);
    String scheme = path.toUri().getScheme();
    if (scheme != null && !scheme.equals("file")) {
        throw new SqlClientException("SQL Client only supports to load files in local.");
    }
}
Also used : Path(org.apache.flink.core.fs.Path) SqlClientException(org.apache.flink.table.client.SqlClientException)

Aggregations

SqlClientException (org.apache.flink.table.client.SqlClientException)7 CommandLine (org.apache.commons.cli.CommandLine)3 DefaultParser (org.apache.commons.cli.DefaultParser)3 ParseException (org.apache.commons.cli.ParseException)3 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)2 File (java.io.File)1 IOError (java.io.IOError)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Configuration (org.apache.flink.configuration.Configuration)1 Path (org.apache.flink.core.fs.Path)1 BeginStatementSetOperation (org.apache.flink.table.operations.BeginStatementSetOperation)1 EndStatementSetOperation (org.apache.flink.table.operations.EndStatementSetOperation)1 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)1 LoadModuleOperation (org.apache.flink.table.operations.LoadModuleOperation)1 ModifyOperation (org.apache.flink.table.operations.ModifyOperation)1 Operation (org.apache.flink.table.operations.Operation)1