use of org.apache.flink.table.client.gateway.local.LocalExecutor 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.local.LocalExecutor 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