Skip to content

Commit

Permalink
Remove usage of /v1/info for JDBC driver
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jun 18, 2021
1 parent 6b453ea commit 9950ff3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public Connection connect(String url, Properties info)

OkHttpClient.Builder builder = httpClient.newBuilder();
uri.setupClient(builder);
QueryExecutor executor = new QueryExecutor(builder.build());

return new TrinoConnection(uri, executor);
return new TrinoConnection(uri, builder.build());
}

@Override
Expand Down
65 changes: 0 additions & 65 deletions client/trino-jdbc/src/main/java/io/trino/jdbc/QueryExecutor.java

This file was deleted.

26 changes: 6 additions & 20 deletions client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import io.airlift.units.Duration;
import io.trino.client.ClientSelectedRole;
import io.trino.client.ClientSession;
import io.trino.client.ServerInfo;
import io.trino.client.StatementClient;
import okhttp3.OkHttpClient;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -63,6 +63,7 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Maps.fromProperties;
import static io.trino.client.StatementClientFactory.newStatementClient;
import static io.trino.jdbc.ClientInfoProperty.APPLICATION_NAME;
import static io.trino.jdbc.ClientInfoProperty.CLIENT_INFO;
import static io.trino.jdbc.ClientInfoProperty.CLIENT_TAGS;
Expand All @@ -88,7 +89,6 @@ public class TrinoConnection
private final AtomicReference<ZoneId> timeZoneId = new AtomicReference<>();
private final AtomicReference<Locale> locale = new AtomicReference<>();
private final AtomicReference<Integer> networkTimeoutMillis = new AtomicReference<>(Ints.saturatedCast(MINUTES.toMillis(2)));
private final AtomicReference<ServerInfo> serverInfo = new AtomicReference<>();
private final AtomicLong nextStatementId = new AtomicLong(1);

private final URI jdbcUri;
Expand All @@ -105,10 +105,10 @@ public class TrinoConnection
private final Map<String, String> preparedStatements = new ConcurrentHashMap<>();
private final Map<String, ClientSelectedRole> roles = new ConcurrentHashMap<>();
private final AtomicReference<String> transactionId = new AtomicReference<>();
private final QueryExecutor queryExecutor;
private final OkHttpClient httpClient;
private final Set<TrinoStatement> statements = newSetFromMap(new ConcurrentHashMap<>());

TrinoConnection(TrinoDriverUri uri, QueryExecutor queryExecutor)
TrinoConnection(TrinoDriverUri uri, OkHttpClient httpClient)
throws SQLException
{
requireNonNull(uri, "uri is null");
Expand All @@ -123,7 +123,7 @@ public class TrinoConnection
this.extraCredentials = uri.getExtraCredentials();
this.compressionDisabled = uri.isCompressionDisabled();
this.assumeLiteralNamesInMetadataCallsForNonConformingClients = uri.isAssumeLiteralNamesInMetadataCallsForNonConformingClients();
this.queryExecutor = requireNonNull(queryExecutor, "queryExecutor is null");
this.httpClient = requireNonNull(httpClient, "httpClient is null");
uri.getClientInfo().ifPresent(tags -> clientInfo.put(CLIENT_INFO, tags));
uri.getClientTags().ifPresent(tags -> clientInfo.put(CLIENT_TAGS, tags));
uri.getTraceToken().ifPresent(tags -> clientInfo.put(TRACE_TOKEN, tags));
Expand Down Expand Up @@ -697,20 +697,6 @@ Map<String, String> getSessionProperties()
return ImmutableMap.copyOf(sessionProperties);
}

ServerInfo getServerInfo()
throws SQLException
{
if (serverInfo.get() == null) {
try {
serverInfo.set(queryExecutor.getServerInfo(httpUri));
}
catch (RuntimeException e) {
throw new SQLException("Error fetching version from server", e);
}
}
return serverInfo.get();
}

boolean shouldStartTransaction()
{
return !autoCommit.get() && (transactionId.get() == null);
Expand Down Expand Up @@ -761,7 +747,7 @@ StatementClient startQuery(String sql, Map<String, String> sessionPropertiesOver
timeout,
compressionDisabled);

return queryExecutor.startQuery(session, sql);
return newStatementClient(httpClient, session, sql);
}

void updateSession(StatementClient client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public String getDatabaseProductName()
public String getDatabaseProductVersion()
throws SQLException
{
return connection.getServerInfo().getNodeVersion().getVersion();
try (ResultSet rs = select("SELECT version()")) {
rs.next();
return rs.getString(1);
}
}

@Override
Expand Down

This file was deleted.

0 comments on commit 9950ff3

Please sign in to comment.