Search in sources :

Example 1 with LocalExecutor

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);
    }
}
Also used : LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor) Executor(org.apache.flink.table.client.gateway.Executor) Configuration(org.apache.flink.configuration.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) Terminal(org.jline.terminal.Terminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) DumbTerminal(org.jline.terminal.impl.DumbTerminal) LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor)

Example 2 with LocalExecutor

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.");
    }
}
Also used : Executor(org.apache.flink.table.client.gateway.Executor) LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) LocalExecutor(org.apache.flink.table.client.gateway.local.LocalExecutor)

Aggregations

Executor (org.apache.flink.table.client.gateway.Executor)2 DefaultContext (org.apache.flink.table.client.gateway.context.DefaultContext)2 LocalExecutor (org.apache.flink.table.client.gateway.local.LocalExecutor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 DefaultCLI (org.apache.flink.client.cli.DefaultCLI)1 Configuration (org.apache.flink.configuration.Configuration)1 Terminal (org.jline.terminal.Terminal)1 DumbTerminal (org.jline.terminal.impl.DumbTerminal)1