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