Skip to content
Closed
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 @@ -71,6 +71,7 @@ enum SslVerificationMode
public static final ConnectionProperty<File> KERBEROS_KEYTAB_PATH = new KerberosKeytabPath();
public static final ConnectionProperty<File> KERBEROS_CREDENTIAL_CACHE_PATH = new KerberosCredentialCachePath();
public static final ConnectionProperty<String> ACCESS_TOKEN = new AccessToken();
public static final ConnectionProperty<String> TIMEZONE_ID = new TimeZoneID();
public static final ConnectionProperty<Boolean> EXTERNAL_AUTHENTICATION = new ExternalAuthentication();
public static final ConnectionProperty<Duration> EXTERNAL_AUTHENTICATION_TIMEOUT = new ExternalAuthenticationTimeout();
public static final ConnectionProperty<Map<String, String>> EXTRA_CREDENTIALS = new ExtraCredentials();
Expand Down Expand Up @@ -105,6 +106,7 @@ enum SslVerificationMode
.add(KERBEROS_KEYTAB_PATH)
.add(KERBEROS_CREDENTIAL_CACHE_PATH)
.add(ACCESS_TOKEN)
.add(TIMEZONE_ID)
.add(EXTRA_CREDENTIALS)
.add(CLIENT_INFO)
.add(CLIENT_TAGS)
Expand Down Expand Up @@ -440,6 +442,15 @@ public AccessToken()
}
}

private static class TimeZoneID
extends AbstractConnectionProperty<String>
{
public TimeZoneID()
{
super("TimeZoneID", NOT_REQUIRED, ALLOWED, STRING_CONVERTER);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Timezone" to be consistent with CLI's --timezone

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make it lowercase timezone to be consistent with other properties (all are lowercase except Kerberos and SSL)

}
}

private static class ExternalAuthentication
extends AbstractConnectionProperty<Boolean>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public class TrinoConnection
uri.getTraceToken().ifPresent(tags -> clientInfo.put(TRACE_TOKEN, tags));

roles.putAll(uri.getRoles());
timeZoneId.set(ZoneId.systemDefault());
timeZoneId.set(uri.getTimeZoneID().isPresent() ?
ZoneId.of(uri.getTimeZoneID().get()) : ZoneId.systemDefault());
locale.set(Locale.getDefault());
sessionProperties.putAll(uri.getSessionProperties());
}
Expand Down
17 changes: 17 additions & 0 deletions client/trino-jdbc/src/main/java/io/trino/jdbc/TrinoDriverUri.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,6 +85,7 @@
import static io.trino.jdbc.ConnectionProperties.SslVerificationMode.CA;
import static io.trino.jdbc.ConnectionProperties.SslVerificationMode.FULL;
import static io.trino.jdbc.ConnectionProperties.SslVerificationMode.NONE;
import static io.trino.jdbc.ConnectionProperties.TIMEZONE_ID;
import static io.trino.jdbc.ConnectionProperties.TRACE_TOKEN;
import static io.trino.jdbc.ConnectionProperties.USER;
import static java.lang.String.format;
Expand Down Expand Up @@ -193,6 +195,21 @@ public Properties getProperties()
return properties;
}

public Optional<String> getTimeZoneID()
throws SQLException
{
Optional<String> tzId = TIMEZONE_ID.getValue(properties);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid abbreviations, call it just timezone


if (tzId.isPresent()) {
List<String> ids = Arrays.asList(java.util.TimeZone.getAvailableIDs());
if (ids.contains(tzId.get())) {
return tzId;
}
throw new SQLException("Specified TimeZoneID is not supported");
Comment on lines +204 to +208
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ZoneId for validation and then just return it

if (timezone.isPresent()) {
   try {
     return ZoneId.of(timezone.get());
   }
   catch (DateTimeException | ZoneRulesException e) {
    throw new SQLException("Specified timezone is not supported: " + timezone.get(), e);
  }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we don't need to return Optional at all, since we can return ZoneId.systemDefault() here when parameter is not set.

}
return tzId;
}

public Map<String, String> getExtraCredentials()
throws SQLException
{
Expand Down