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);
}
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);
}
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");
}
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");
}
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();
}
}
Aggregations