Search in sources :

Example 1 with DefaultContext

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);
}
Also used : CustomCommandLine(org.apache.flink.client.cli.CustomCommandLine) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) URL(java.net.URL)

Example 2 with DefaultContext

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;
}
Also used : Configuration(org.apache.flink.configuration.Configuration) DefaultCLI(org.apache.flink.client.cli.DefaultCLI) DefaultContext(org.apache.flink.table.client.gateway.context.DefaultContext) URL(java.net.URL)

Example 3 with DefaultContext

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);
    }
}
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 4 with DefaultContext

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

Example 5 with 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.");
    }
}
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

DefaultContext (org.apache.flink.table.client.gateway.context.DefaultContext)5 DefaultCLI (org.apache.flink.client.cli.DefaultCLI)3 Configuration (org.apache.flink.configuration.Configuration)3 URL (java.net.URL)2 Executor (org.apache.flink.table.client.gateway.Executor)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 CustomCommandLine (org.apache.flink.client.cli.CustomCommandLine)1 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)1 Terminal (org.jline.terminal.Terminal)1 DumbTerminal (org.jline.terminal.impl.DumbTerminal)1