Search in sources :

Example 6 with ClientSession

use of com.facebook.presto.client.ClientSession in project presto by prestodb.

the class TestClientOptions method testServerHostPort.

@Test
public void testServerHostPort() {
    ClientOptions options = new ClientOptions();
    options.server = "localhost:8888";
    ClientSession session = options.toClientSession();
    assertEquals(session.getServer().toString(), "http://localhost:8888");
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Example 7 with ClientSession

use of com.facebook.presto.client.ClientSession in project presto by prestodb.

the class TestTableNameCompleter method testAutoCompleteWithoutSchema.

@Test
public void testAutoCompleteWithoutSchema() {
    ClientSession session = new ClientOptions().toClientSession();
    QueryRunner runner = QueryRunner.create(session, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), false, null);
    TableNameCompleter completer = new TableNameCompleter(runner);
    assertEquals(completer.complete("SELECT is_infi", 14, ImmutableList.of()), 7);
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Example 8 with ClientSession

use of com.facebook.presto.client.ClientSession in project presto by prestodb.

the class Console method run.

@Override
public void run() {
    ClientSession session = clientOptions.toClientSession();
    KerberosConfig kerberosConfig = clientOptions.toKerberosConfig();
    boolean hasQuery = !Strings.isNullOrEmpty(clientOptions.execute);
    boolean isFromFile = !Strings.isNullOrEmpty(clientOptions.file);
    if (!hasQuery && !isFromFile) {
        AnsiConsole.systemInstall();
    }
    initializeLogging(clientOptions.logLevelsFile);
    String query = clientOptions.execute;
    if (hasQuery) {
        query += ";";
    }
    if (isFromFile) {
        if (hasQuery) {
            throw new RuntimeException("both --execute and --file specified");
        }
        try {
            query = Files.toString(new File(clientOptions.file), UTF_8);
            hasQuery = true;
        } catch (IOException e) {
            throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage()));
        }
    }
    AtomicBoolean exiting = new AtomicBoolean();
    interruptThreadOnExit(Thread.currentThread(), exiting);
    try (QueryRunner queryRunner = QueryRunner.create(session, Optional.ofNullable(clientOptions.socksProxy), Optional.ofNullable(clientOptions.keystorePath), Optional.ofNullable(clientOptions.keystorePassword), Optional.ofNullable(clientOptions.truststorePath), Optional.ofNullable(clientOptions.truststorePassword), Optional.ofNullable(clientOptions.user), clientOptions.password ? Optional.of(getPassword()) : Optional.empty(), Optional.ofNullable(clientOptions.krb5Principal), Optional.ofNullable(clientOptions.krb5RemoteServiceName), clientOptions.authenticationEnabled, kerberosConfig)) {
        if (hasQuery) {
            executeCommand(queryRunner, query, clientOptions.outputFormat);
        } else {
            runConsole(queryRunner, session, exiting);
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClientSession(com.facebook.presto.client.ClientSession) KerberosConfig(io.airlift.http.client.spnego.KerberosConfig) IOException(java.io.IOException) File(java.io.File)

Example 9 with ClientSession

use of com.facebook.presto.client.ClientSession in project presto by prestodb.

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(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Example 10 with ClientSession

use of com.facebook.presto.client.ClientSession in project presto by prestodb.

the class TestClientOptions method testServerHttpsUri.

@Test
public void testServerHttpsUri() {
    ClientOptions options = new ClientOptions();
    options.server = "https://localhost/foo";
    ClientSession session = options.toClientSession();
    assertEquals(session.getServer().toString(), "https://localhost/foo");
}
Also used : ClientSession(com.facebook.presto.client.ClientSession) Test(org.testng.annotations.Test)

Aggregations

ClientSession (com.facebook.presto.client.ClientSession)14 Test (org.testng.annotations.Test)8 Duration (io.airlift.units.Duration)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 QueryError (com.facebook.presto.client.QueryError)1 QueryResults (com.facebook.presto.client.QueryResults)1 StatementClient (com.facebook.presto.client.StatementClient)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 ByteStreams.nullOutputStream (com.google.common.io.ByteStreams.nullOutputStream)1 Command (io.airlift.airline.Command)1 HelpOption (io.airlift.airline.HelpOption)1 SingleCommand.singleCommand (io.airlift.airline.SingleCommand.singleCommand)1 KerberosConfig (io.airlift.http.client.spnego.KerberosConfig)1 Level (io.airlift.log.Level)1 Logging (io.airlift.log.Logging)1 LoggingConfiguration (io.airlift.log.LoggingConfiguration)1