Search in sources :

Example 1 with ClientSession

use of io.prestosql.client.ClientSession in project hetu-core by openlookeng.

the class AbstractTestingPrestoClient method toClientSession.

private static ClientSession toClientSession(Session session, URI server, Duration clientRequestTimeout) {
    ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
    properties.putAll(session.getSystemProperties());
    for (Entry<String, Map<String, String>> connectorProperties : session.getUnprocessedCatalogProperties().entrySet()) {
        for (Entry<String, String> entry : connectorProperties.getValue().entrySet()) {
            properties.put(connectorProperties.getKey() + "." + entry.getKey(), entry.getValue());
        }
    }
    ImmutableMap.Builder<String, String> resourceEstimates = ImmutableMap.builder();
    ResourceEstimates estimates = session.getResourceEstimates();
    estimates.getExecutionTime().ifPresent(e -> resourceEstimates.put(EXECUTION_TIME, e.toString()));
    estimates.getCpuTime().ifPresent(e -> resourceEstimates.put(CPU_TIME, e.toString()));
    estimates.getPeakMemory().ifPresent(e -> resourceEstimates.put(PEAK_MEMORY, e.toString()));
    return new ClientSession(server, session.getIdentity().getUser(), session.getSource().orElse(null), session.getTraceToken(), session.getClientTags(), session.getClientInfo().orElse(null), session.getCatalog().orElse(null), session.getSchema().orElse(null), session.getPath().toString(), ZoneId.of(session.getTimeZoneKey().getId()), session.getLocale(), resourceEstimates.build(), properties.build(), session.getPreparedStatements(), session.getIdentity().getRoles().entrySet().stream().collect(toImmutableMap(Entry::getKey, entry -> new ClientSelectedRole(ClientSelectedRole.Type.valueOf(entry.getValue().getType().toString()), entry.getValue().getRole()))), session.getIdentity().getExtraCredentials(), session.getTransactionId().map(Object::toString).orElse(null), clientRequestTimeout);
}
Also used : ResourceEstimates(io.prestosql.spi.session.ResourceEstimates) Entry(java.util.Map.Entry) ClientSelectedRole(io.prestosql.client.ClientSelectedRole) ClientSession(io.prestosql.client.ClientSession) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 2 with ClientSession

use of io.prestosql.client.ClientSession in project hetu-core by openlookeng.

the class TestTableNameCompleter method testAutoCompleteWithoutSchema.

@Test
public void testAutoCompleteWithoutSchema() {
    ClientSession session = new ClientOptions().toClientSession();
    QueryRunner runner = TestQueryRunner.createQueryRunner(session);
    TableNameCompleter completer = new TableNameCompleter(runner);
}
Also used : ClientSession(io.prestosql.client.ClientSession) Test(org.testng.annotations.Test)

Example 3 with ClientSession

use of io.prestosql.client.ClientSession in project hetu-core by openlookeng.

the class TestClientOptions method testServerHostOnly.

@Test
public void testServerHostOnly() {
    ClientOptions options = new ClientOptions();
    options.server = "localhost";
    ClientSession session = options.toClientSession();
    assertEquals(session.getServer().toString(), "http://localhost:80");
}
Also used : ClientSession(io.prestosql.client.ClientSession) Test(org.testng.annotations.Test)

Example 4 with ClientSession

use of io.prestosql.client.ClientSession in project hetu-core by openlookeng.

the class TestClientOptions method testServerHttpUri.

@Test
public void testServerHttpUri() {
    ClientOptions options = new ClientOptions();
    options.server = "http://localhost/foo";
    ClientSession session = options.toClientSession();
    assertEquals(session.getServer().toString(), "http://localhost/foo");
}
Also used : ClientSession(io.prestosql.client.ClientSession) Test(org.testng.annotations.Test)

Example 5 with ClientSession

use of io.prestosql.client.ClientSession in project hetu-core by openlookeng.

the class Console method run.

public boolean run() {
    ClientSession session = clientOptions.toClientSession();
    boolean hasQuery = !isNullOrEmpty(clientOptions.execute);
    boolean isFromFile = !isNullOrEmpty(clientOptions.file);
    initializeLogging(clientOptions.logLevelsFile);
    String query = clientOptions.execute;
    if (hasQuery) {
        query += ";";
    }
    if (isFromFile) {
        if (hasQuery) {
            throw new RuntimeException("both --execute and --file specified");
        }
        try {
            query = asCharSource(new File(clientOptions.file), UTF_8).read();
            hasQuery = true;
        } catch (IOException e) {
            throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage()));
        }
    }
    // abort any running query if the CLI is terminated
    AtomicBoolean exiting = new AtomicBoolean();
    ThreadInterruptor interruptor = new ThreadInterruptor();
    CountDownLatch exited = new CountDownLatch(1);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        exiting.set(true);
        interruptor.interrupt();
        awaitUninterruptibly(exited, EXIT_DELAY.toMillis(), MILLISECONDS);
    }));
    try (QueryRunner queryRunner = new QueryRunner(session, clientOptions.debug, Optional.ofNullable(clientOptions.socksProxy), Optional.ofNullable(clientOptions.httpProxy), Optional.ofNullable(clientOptions.keystorePath), Optional.ofNullable(clientOptions.keystorePassword), Optional.ofNullable(clientOptions.truststorePath), Optional.ofNullable(clientOptions.truststorePassword), Optional.ofNullable(clientOptions.accessToken), Optional.ofNullable(getUser()), clientOptions.password ? Optional.of(getPassword()) : Optional.empty(), Optional.ofNullable(clientOptions.krb5Principal), Optional.ofNullable(clientOptions.krb5ServicePrincipalPattern), Optional.ofNullable(clientOptions.krb5RemoteServiceName), Optional.ofNullable(clientOptions.krb5ConfigPath), Optional.ofNullable(clientOptions.krb5KeytabPath), Optional.ofNullable(clientOptions.krb5CredentialCachePath), !clientOptions.krb5DisableRemoteServiceHostnameCanonicalization)) {
        if (hasQuery) {
            return executeCommand(queryRunner, exiting, query, clientOptions.outputFormat, clientOptions.ignoreErrors, clientOptions.progress);
        }
        runConsole(queryRunner, exiting);
        return true;
    } finally {
        exited.countDown();
        interruptor.close();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientSession(io.prestosql.client.ClientSession) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File)

Aggregations

ClientSession (io.prestosql.client.ClientSession)18 Test (org.testng.annotations.Test)8 HashMap (java.util.HashMap)5 Duration (io.airlift.units.Duration)3 ClientSelectedRole (io.prestosql.client.ClientSelectedRole)3 StatementClient (io.prestosql.client.StatementClient)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 QueryError (io.prestosql.client.QueryError)2 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)2 QueryId (io.prestosql.spi.QueryId)2 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ByteStreams.nullOutputStream (com.google.common.io.ByteStreams.nullOutputStream)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Command (io.airlift.airline.Command)1 HelpOption (io.airlift.airline.HelpOption)1