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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
import static io.trino.client.uri.LoggingLevel.NONE;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;

Expand Down Expand Up @@ -191,9 +190,9 @@ public String getRequiredUser()
return resolveRequired(USER);
}

public String getUser()
public Optional<String> getUser()
{
return resolveWithDefault(USER, getProperty("user.name"));
return resolveOptional(USER);
}

public boolean hasPassword()
Expand Down Expand Up @@ -486,7 +485,7 @@ public ClientSession.Builder toClientSessionBuilder()
{
return ClientSession.builder()
.server(getHttpUri())
.principal(Optional.of(getUser()))
.principal(getUser())
.path(getPath().orElse(ImmutableList.of()))
.clientRequestTimeout(getTimeout())
.user(getSessionUser())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ public void testInvalidUrls()
"Connection property assumeLiteralUnderscoreInMetadataCallsForNonConformingClients cannot be set if assumeLiteralNamesInMetadataCallsForNonConformingClients is enabled");
}

@Test
public void testUser()
{
assertThat(TrinoUri.create("trino://localhost:8080", new Properties()).getUser()).isEmpty();
assertThat(TrinoUri.create("trino://localhost:8080", new Properties()).getProperties().get("user")).isNull();
assertThat(TrinoUri.create("trino://localhost:8080?user=trino", new Properties()).getUser()).hasValue("trino");
assertThat(TrinoUri.create("trino://localhost:8080?user=trino", new Properties()).getProperties().get("user")).isEqualTo("trino");
}

@Test
public void testEmptyUser()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public class TrinoConnection
this.httpUri = uri.getHttpUri();
uri.getSchema().ifPresent(schema::set);
uri.getCatalog().ifPresent(catalog::set);
this.user = Optional.ofNullable(uri.getUser());
this.user = uri.getUser();
this.sessionUser.set(uri.getSessionUser());
this.applicationNamePrefix = uri.getApplicationNamePrefix();
this.source = uri.getSource();
Expand Down