use of org.apache.flink.table.client.gateway.context.DefaultContext in project flink by apache.
the class LocalContextUtils method buildDefaultContext.
public static DefaultContext buildDefaultContext(CliOptions options) {
final List<URL> jars;
if (options.getJars() != null) {
jars = options.getJars();
} else {
jars = Collections.emptyList();
}
final List<URL> libDirs;
if (options.getLibraryDirs() != null) {
libDirs = options.getLibraryDirs();
} else {
libDirs = Collections.emptyList();
}
// 1. find the configuration directory
String flinkConfigDir = CliFrontend.getConfigurationDirectoryFromEnv();
// 2. load the global configuration
Configuration configuration = GlobalConfiguration.loadConfiguration(flinkConfigDir);
// 3. load the custom command lines
List<CustomCommandLine> commandLines = CliFrontend.loadCustomCommandLines(configuration, flinkConfigDir);
configuration.addAll(options.getPythonConfiguration());
final List<URL> dependencies = discoverDependencies(jars, libDirs);
return new DefaultContext(dependencies, configuration, commandLines);
}
use of org.apache.flink.table.client.gateway.context.DefaultContext in project flink by apache.
the class DependencyTest method createLocalExecutor.
private LocalExecutor createLocalExecutor() throws Exception {
// create executor with dependencies
final URL dependency = Paths.get("target", TABLE_FACTORY_JAR_FILE).toUri().toURL();
// create default context
DefaultContext defaultContext = new DefaultContext(Collections.singletonList(dependency), new Configuration(), Collections.singletonList(new DefaultCLI()));
LocalExecutor executor = new LocalExecutor(defaultContext);
executor.openSession(SESSION_ID);
for (String line : INIT_SQL) {
executor.executeOperation(SESSION_ID, executor.parseStatement(SESSION_ID, line));
}
return executor;
}
use of org.apache.flink.table.client.gateway.context.DefaultContext in project flink by apache.
the class CliClientITCase method runSqlStatements.
/**
* Returns printed results for each ran SQL statements.
*
* @param statements the SQL statements to run
* @return the printed results on SQL Client
*/
private List<Result> runSqlStatements(List<String> statements) throws IOException {
final String sqlContent = String.join("", statements);
DefaultContext defaultContext = new DefaultContext(Collections.emptyList(), new Configuration(MINI_CLUSTER_RESOURCE.getClientConfiguration()).set(ExecutionConfigOptions.TABLE_EXEC_LEGACY_CAST_BEHAVIOUR, ExecutionConfigOptions.LegacyCastBehaviour.DISABLED), Collections.singletonList(new DefaultCLI()));
final Executor executor = new LocalExecutor(defaultContext);
InputStream inputStream = new ByteArrayInputStream(sqlContent.getBytes());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(256);
String sessionId = executor.openSession("test-session");
try (Terminal terminal = new DumbTerminal(inputStream, outputStream);
CliClient client = new CliClient(() -> terminal, sessionId, executor, historyPath, HideSqlStatement.INSTANCE)) {
client.executeInInteractiveMode();
String output = new String(outputStream.toByteArray());
return normalizeOutput(output);
}
}
use of org.apache.flink.table.client.gateway.context.DefaultContext in project flink by apache.
the class LocalExecutorITCase method createLocalExecutor.
private LocalExecutor createLocalExecutor(List<URL> dependencies, Configuration configuration) {
configuration.addAll(clusterClient.getFlinkConfiguration());
DefaultContext defaultContext = new DefaultContext(dependencies, configuration, Collections.singletonList(new DefaultCLI()));
return new LocalExecutor(defaultContext);
}
use of org.apache.flink.table.client.gateway.context.DefaultContext in project flink by apache.
the class SqlClient method start.
private void start() {
if (isEmbedded) {
// create local executor with default environment
DefaultContext defaultContext = LocalContextUtils.buildDefaultContext(options);
final Executor executor = new LocalExecutor(defaultContext);
executor.start();
// Open an new session
String sessionId = executor.openSession(options.getSessionId());
try {
// add shutdown hook
Runtime.getRuntime().addShutdownHook(new EmbeddedShutdownThread(sessionId, executor));
// do the actual work
openCli(sessionId, executor);
} finally {
executor.closeSession(sessionId);
}
} else {
throw new SqlClientException("Gateway mode is not supported yet.");
}
}
Aggregations