Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename legacyPreparedStatements to explicitPrepare #19541

Merged
merged 3 commits into from
Oct 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ enum SslVerificationMode
public static final ConnectionProperty<String, String> DNS_RESOLVER_CONTEXT = new ResolverContext();
public static final ConnectionProperty<String, String> HOSTNAME_IN_CERTIFICATE = new HostnameInCertificate();
public static final ConnectionProperty<String, ZoneId> TIMEZONE = new TimeZone();
public static final ConnectionProperty<String, Boolean> LEGACY_PREPARED_STATEMENTS = new LegacyPreparedStatements();
public static final ConnectionProperty<String, Boolean> EXPLICIT_PREPARE = new ExplicitPrepare();

private static final Set<ConnectionProperty<?, ?>> ALL_PROPERTIES = ImmutableSet.<ConnectionProperty<?, ?>>builder()
.add(USER)
Expand Down Expand Up @@ -145,7 +145,7 @@ enum SslVerificationMode
.add(DNS_RESOLVER_CONTEXT)
.add(HOSTNAME_IN_CERTIFICATE)
.add(TIMEZONE)
.add(LEGACY_PREPARED_STATEMENTS)
.add(EXPLICIT_PREPARE)
.build();

private static final Map<String, ConnectionProperty<?, ?>> KEY_LOOKUP = unmodifiableMap(ALL_PROPERTIES.stream()
Expand Down Expand Up @@ -718,12 +718,12 @@ public TimeZone()
}
}

private static class LegacyPreparedStatements
private static class ExplicitPrepare
extends AbstractConnectionProperty<String, Boolean>
{
public LegacyPreparedStatements()
public ExplicitPrepare()
{
super(PropertyName.LEGACY_PREPARED_STATEMENTS, NOT_REQUIRED, ALLOWED, BOOLEAN_CONVERTER);
super(PropertyName.EXPLICIT_PREPARE, NOT_REQUIRED, ALLOWED, BOOLEAN_CONVERTER);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public enum PropertyName
TRACE_TOKEN("traceToken"),
SESSION_PROPERTIES("sessionProperties"),
SOURCE("source"),
LEGACY_PREPARED_STATEMENTS("legacyPreparedStatements"),
EXPLICIT_PREPARE("explicitPrepare"),
DNS_RESOLVER("dnsResolver"),
DNS_RESOLVER_CONTEXT("dnsResolverContext"),
HOSTNAME_IN_CERTIFICATE("hostnameInCertificate"),
Expand Down
24 changes: 12 additions & 12 deletions client/trino-client/src/main/java/io/trino/client/uri/TrinoUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import static io.trino.client.uri.ConnectionProperties.DISABLE_COMPRESSION;
import static io.trino.client.uri.ConnectionProperties.DNS_RESOLVER;
import static io.trino.client.uri.ConnectionProperties.DNS_RESOLVER_CONTEXT;
import static io.trino.client.uri.ConnectionProperties.EXPLICIT_PREPARE;
import static io.trino.client.uri.ConnectionProperties.EXTERNAL_AUTHENTICATION;
import static io.trino.client.uri.ConnectionProperties.EXTERNAL_AUTHENTICATION_REDIRECT_HANDLERS;
import static io.trino.client.uri.ConnectionProperties.EXTERNAL_AUTHENTICATION_TIMEOUT;
Expand All @@ -86,7 +87,6 @@
import static io.trino.client.uri.ConnectionProperties.KERBEROS_REMOTE_SERVICE_NAME;
import static io.trino.client.uri.ConnectionProperties.KERBEROS_SERVICE_PRINCIPAL_PATTERN;
import static io.trino.client.uri.ConnectionProperties.KERBEROS_USE_CANONICAL_HOSTNAME;
import static io.trino.client.uri.ConnectionProperties.LEGACY_PREPARED_STATEMENTS;
import static io.trino.client.uri.ConnectionProperties.PASSWORD;
import static io.trino.client.uri.ConnectionProperties.ROLES;
import static io.trino.client.uri.ConnectionProperties.SESSION_PROPERTIES;
Expand Down Expand Up @@ -168,7 +168,7 @@ public class TrinoUri
private Optional<String> traceToken;
private Optional<Map<String, String>> sessionProperties;
private Optional<String> source;
private Optional<Boolean> legacyPreparedStatements;
private Optional<Boolean> explicitPrepare;

private Optional<String> catalog = Optional.empty();
private Optional<String> schema = Optional.empty();
Expand Down Expand Up @@ -222,7 +222,7 @@ private TrinoUri(
Optional<String> traceToken,
Optional<Map<String, String>> sessionProperties,
Optional<String> source,
Optional<Boolean> legacyPreparedStatements)
Optional<Boolean> explicitPrepare)
throws SQLException
{
this.uri = requireNonNull(uri, "uri is null");
Expand Down Expand Up @@ -275,7 +275,7 @@ private TrinoUri(
this.traceToken = TRACE_TOKEN.getValueOrDefault(urlProperties, traceToken);
this.sessionProperties = SESSION_PROPERTIES.getValueOrDefault(urlProperties, sessionProperties);
this.source = SOURCE.getValueOrDefault(urlProperties, source);
this.legacyPreparedStatements = LEGACY_PREPARED_STATEMENTS.getValueOrDefault(urlProperties, legacyPreparedStatements);
this.explicitPrepare = EXPLICIT_PREPARE.getValueOrDefault(urlProperties, explicitPrepare);

properties = buildProperties();

Expand Down Expand Up @@ -361,7 +361,7 @@ private Properties buildProperties()
clientTags.ifPresent(value -> properties.setProperty(PropertyName.CLIENT_TAGS.toString(), value));
traceToken.ifPresent(value -> properties.setProperty(PropertyName.TRACE_TOKEN.toString(), value));
source.ifPresent(value -> properties.setProperty(PropertyName.SOURCE.toString(), value));
legacyPreparedStatements.ifPresent(value -> properties.setProperty(PropertyName.LEGACY_PREPARED_STATEMENTS.toString(), value.toString()));
explicitPrepare.ifPresent(value -> properties.setProperty(PropertyName.EXPLICIT_PREPARE.toString(), value.toString()));
return properties;
}

Expand Down Expand Up @@ -421,7 +421,7 @@ protected TrinoUri(URI uri, Properties driverProperties)
this.traceToken = TRACE_TOKEN.getValue(properties);
this.sessionProperties = SESSION_PROPERTIES.getValue(properties);
this.source = SOURCE.getValue(properties);
this.legacyPreparedStatements = LEGACY_PREPARED_STATEMENTS.getValue(properties);
this.explicitPrepare = EXPLICIT_PREPARE.getValue(properties);

// enable SSL by default for the trino schema and the standard port
useSecureConnection = ssl.orElse(uri.getScheme().equals("https") || (uri.getScheme().equals("trino") && uri.getPort() == 443));
Expand Down Expand Up @@ -529,9 +529,9 @@ public Optional<String> getSource()
return source;
}

public Optional<Boolean> getLegacyPreparedStatements()
public Optional<Boolean> getExplicitPrepare()
{
return legacyPreparedStatements;
return explicitPrepare;
}

public boolean isCompressionDisabled()
Expand Down Expand Up @@ -938,7 +938,7 @@ public static final class Builder
private String traceToken;
private Map<String, String> sessionProperties;
private String source;
private Boolean legacyPreparedStatements;
private Boolean explicitPrepare;

private Builder() {}

Expand Down Expand Up @@ -1227,9 +1227,9 @@ public Builder setSource(String source)
return this;
}

public Builder setLegacyPreparedStatements(Boolean legacyPreparedStatements)
public Builder setExplicitPrepare(Boolean explicitPrepare)
{
this.legacyPreparedStatements = requireNonNull(legacyPreparedStatements, "legacyPreparedStatements is null");
this.explicitPrepare = requireNonNull(explicitPrepare, "explicitPrepare is null");
return this;
}

Expand Down Expand Up @@ -1282,7 +1282,7 @@ public TrinoUri build()
Optional.ofNullable(traceToken),
Optional.ofNullable(sessionProperties),
Optional.ofNullable(source),
Optional.ofNullable(legacyPreparedStatements));
Optional.ofNullable(explicitPrepare));
}
}
}
12 changes: 12 additions & 0 deletions client/trino-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>junit-extensions</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
Expand Down Expand Up @@ -258,6 +264,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class TrinoConnection
private final AtomicReference<String> transactionId = new AtomicReference<>();
private final Call.Factory httpCallFactory;
private final Set<TrinoStatement> statements = newSetFromMap(new ConcurrentHashMap<>());
private boolean useLegacyPreparedStatements = true;
private boolean useExplicitPrepare = true;

TrinoConnection(TrinoDriverUri uri, Call.Factory httpCallFactory)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ public class TrinoConnection
locale.set(Locale.getDefault());
sessionProperties.putAll(uri.getSessionProperties());

uri.getLegacyPreparedStatements().ifPresent(value -> this.useLegacyPreparedStatements = value);
uri.getExplicitPrepare().ifPresent(value -> this.useExplicitPrepare = value);
}

@Override
Expand Down Expand Up @@ -915,8 +915,8 @@ public void throwIfHeld()
}
}

public Boolean isUseLegacyPreparedStatements()
public boolean useExplicitPrepare()
{
return this.useLegacyPreparedStatements;
return this.useExplicitPrepare;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class TrinoPreparedStatement
super(connection, onClose);
this.statementName = requireNonNull(statementName, "statementName is null");
this.originalSql = requireNonNull(sql, "sql is null");
if (connection().isUseLegacyPreparedStatements()) {
if (connection().useExplicitPrepare()) {
super.execute(format("PREPARE %s FROM %s", statementName, sql));
prepareStatementExecuted = true;
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ private String getLegacySql(String statementName, List<String> values)
private String getExecuteSql(String statementName, List<String> values)
throws SQLException
{
return connection().isUseLegacyPreparedStatements()
return connection().useExplicitPrepare()
? getLegacySql(statementName, values)
: getExecuteImmediateSql(values);
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ private static List<ColumnInfo> getDescribeOutputColumnInfoList(ResultSet result
}

/*
When isUseLegacyPreparedStatements is disabled, the PREPARE statement won't be executed unless needed
When explicitPrepare is disabled, the PREPARE statement won't be executed unless needed
e.g. when getMetadata() or getParameterMetadata() are called.
When needed, just make sure it is executed only once, even if the metadata methods are called many times
*/
Expand Down
Loading
Loading