Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions presto-docs/src/main/sphinx/installation/jdbc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Name Description
``password`` Password to use for LDAP authentication.
``socksProxy`` SOCKS proxy host and port. Example: ``localhost:1080``
``httpProxy`` HTTP proxy host and port. Example: ``localhost:8888``
``protocols`` Comma delineated list of HTTP protocols to use. Example: ``protocols=http11``.
Acceptable values: ``http11,http10,http2``
``applicationNamePrefix`` Prefix to append to any specified ``ApplicationName`` client info
property, which is used to set the source name for the Presto query.
If neither this property nor ``ApplicationName`` are set, the source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import okhttp3.Protocol;

import java.io.File;
import java.sql.DriverPropertyInfo;
Expand Down Expand Up @@ -216,6 +217,41 @@ private QueryInterceptor loadClass(String interceptor)
}
}

protected static final class HttpProtocolConverter
implements Converter<List<Protocol>>
{
public static final HttpProtocolConverter HTTP_PROTOCOL_CONVERTER = new HttpProtocolConverter();
private HttpProtocolConverter() {}

@Override
public List<Protocol> convert(String value)
{
return Splitter.on(',').splitToList(value).stream()
.map(this::loadProtocol)
.distinct()
.collect(toImmutableList());
}

private Protocol loadProtocol(String protocolName)
{
try {
switch (protocolName.toLowerCase(ENGLISH)) {
case "http11":
return Protocol.HTTP_1_1;
case "http10":
return Protocol.HTTP_1_0;
case "http2":
return Protocol.HTTP_2;
default:
return Protocol.get(protocolName);
}
}
catch (Exception e) {
throw new IllegalArgumentException(format("Could not load OkhttpProtocol from %s", protocolName), e);
}
}
}

protected interface CheckedPredicate<T>
{
boolean test(T t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort;
import okhttp3.Protocol;

import java.io.File;
import java.util.List;
Expand All @@ -26,6 +27,7 @@
import java.util.function.Predicate;

import static com.facebook.presto.jdbc.AbstractConnectionProperty.ClassListConverter.CLASS_LIST_CONVERTER;
import static com.facebook.presto.jdbc.AbstractConnectionProperty.HttpProtocolConverter.HTTP_PROTOCOL_CONVERTER;
import static com.facebook.presto.jdbc.AbstractConnectionProperty.StringMapConverter.STRING_MAP_CONVERTER;
import static com.facebook.presto.jdbc.AbstractConnectionProperty.checkedPredicate;
import static java.util.Collections.unmodifiableMap;
Expand Down Expand Up @@ -54,6 +56,7 @@ final class ConnectionProperties
public static final ConnectionProperty<String> ACCESS_TOKEN = new AccessToken();
public static final ConnectionProperty<Map<String, String>> EXTRA_CREDENTIALS = new ExtraCredentials();
public static final ConnectionProperty<Map<String, String>> SESSION_PROPERTIES = new SessionProperties();
public static final ConnectionProperty<List<Protocol>> HTTP_PROTOCOLS = new HttpProtocols();
public static final ConnectionProperty<List<QueryInterceptor>> QUERY_INTERCEPTORS = new QueryInterceptors();

private static final Set<ConnectionProperty<?>> ALL_PROPERTIES = ImmutableSet.<ConnectionProperty<?>>builder()
Expand All @@ -77,6 +80,7 @@ final class ConnectionProperties
.add(ACCESS_TOKEN)
.add(EXTRA_CREDENTIALS)
.add(SESSION_PROPERTIES)
.add(HTTP_PROTOCOLS)
.add(QUERY_INTERCEPTORS)
.build();

Expand Down Expand Up @@ -313,6 +317,15 @@ public SessionProperties()
}
}

private static class HttpProtocols
extends AbstractConnectionProperty<List<Protocol>>
{
public HttpProtocols()
{
super("protocols", NOT_REQUIRED, ALLOWED, HTTP_PROTOCOL_CONVERTER);
}
}

private static class QueryInterceptors
extends AbstractConnectionProperty<List<QueryInterceptor>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;

import java.io.File;
import java.net.URI;
Expand All @@ -47,6 +48,7 @@
import static com.facebook.presto.jdbc.ConnectionProperties.APPLICATION_NAME_PREFIX;
import static com.facebook.presto.jdbc.ConnectionProperties.DISABLE_COMPRESSION;
import static com.facebook.presto.jdbc.ConnectionProperties.EXTRA_CREDENTIALS;
import static com.facebook.presto.jdbc.ConnectionProperties.HTTP_PROTOCOLS;
import static com.facebook.presto.jdbc.ConnectionProperties.HTTP_PROXY;
import static com.facebook.presto.jdbc.ConnectionProperties.KERBEROS_CONFIG_PATH;
import static com.facebook.presto.jdbc.ConnectionProperties.KERBEROS_CREDENTIAL_CACHE_PATH;
Expand Down Expand Up @@ -170,6 +172,12 @@ public boolean isCompressionDisabled()
return DISABLE_COMPRESSION.getValue(properties).orElse(false);
}

public Optional<List<Protocol>> getProtocols()
throws SQLException
{
return HTTP_PROTOCOLS.getValue(properties);
}

public void setupClient(OkHttpClient.Builder builder)
throws SQLException
{
Expand All @@ -178,6 +186,9 @@ public void setupClient(OkHttpClient.Builder builder)
setupSocksProxy(builder, SOCKS_PROXY.getValue(properties));
setupHttpProxy(builder, HTTP_PROXY.getValue(properties));

// add user specified protocols to okhttp3 client if specified
getProtocols().ifPresent(builder::protocols);

// TODO: fix Tempto to allow empty passwords
String password = PASSWORD.getValue(properties).orElse("");
if (!password.isEmpty() && !password.equals("***empty***")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ public void testApplicationName()
}
}

@Test
public void testHttpProtocols()
throws SQLException
{
String extra = "protocols=http11";
try (Connection connection = createConnection(extra)) {
assertThat(connection.getCatalog()).isEqualTo("hive");
}

// deduplication
extra = "protocols=http11,http11";
try (Connection connection = createConnection(extra)) {
assertThat(connection.getCatalog()).isEqualTo("hive");
}
}

@Test
public void testExtraCredentials()
throws SQLException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import static com.facebook.presto.jdbc.ConnectionProperties.DISABLE_COMPRESSION;
import static com.facebook.presto.jdbc.ConnectionProperties.EXTRA_CREDENTIALS;
import static com.facebook.presto.jdbc.ConnectionProperties.HTTP_PROTOCOLS;
import static com.facebook.presto.jdbc.ConnectionProperties.HTTP_PROXY;
import static com.facebook.presto.jdbc.ConnectionProperties.QUERY_INTERCEPTORS;
import static com.facebook.presto.jdbc.ConnectionProperties.SESSION_PROPERTIES;
Expand Down Expand Up @@ -265,6 +266,16 @@ public void testUriWithSessionProperties()
assertEquals(properties.getProperty(SESSION_PROPERTIES.getKey()), sessionProperties);
}

@Test
public void testUriWithHttpProtocols()
throws SQLException
{
String protocols = "h2,http/1.1";
PrestoDriverUri parameters = createDriverUri("presto://localhost:8080?protocols=" + protocols);
Properties properties = parameters.getProperties();
assertEquals(properties.getProperty(HTTP_PROTOCOLS.getKey()), protocols);
}

@Test
public void testUriWithQueryInterceptors()
throws SQLException
Expand Down