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

Prefer ImmutableMap to Map #6761

Merged
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 @@ -70,7 +70,6 @@
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;

public class InformationSchemaMetadata
implements ConnectorMetadata
Expand Down Expand Up @@ -146,7 +145,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn

return tableMetadata.getColumns().stream()
.map(ColumnMetadata::getName)
.collect(toMap(identity(), InformationSchemaColumnHandle::new));
.collect(toImmutableMap(identity(), InformationSchemaColumnHandle::new));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
import static com.google.cloud.bigquery.TableDefinition.Type.TABLE;
import static com.google.cloud.bigquery.TableDefinition.Type.VIEW;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Objects.requireNonNull;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;

public class BigQueryMetadata
implements ConnectorMetadata
Expand Down Expand Up @@ -165,7 +165,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
{
log.debug("getColumnHandles(session=%s, tableHandle=%s)", session, tableHandle);
List<BigQueryColumnHandle> columnHandles = getTableColumns(((BigQueryTableHandle) tableHandle).getTableId());
return columnHandles.stream().collect(toMap(BigQueryColumnHandle::getName, identity()));
return columnHandles.stream().collect(toImmutableMap(BigQueryColumnHandle::getName, identity()));
}

List<BigQueryColumnHandle> getTableColumns(TableId tableId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.plugin.blackhole.BlackHoleConnector.DISTRIBUTED_ON;
import static io.trino.plugin.blackhole.BlackHoleConnector.FIELD_LENGTH_PROPERTY;
import static io.trino.plugin.blackhole.BlackHoleConnector.PAGES_PER_SPLIT_PROPERTY;
Expand All @@ -65,7 +66,6 @@
import static io.trino.spi.type.BigintType.BIGINT;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;

public class BlackHoleMetadata
Expand Down Expand Up @@ -159,7 +159,7 @@ public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, Conn
{
BlackHoleTableHandle blackHoleTableHandle = (BlackHoleTableHandle) tableHandle;
return blackHoleTableHandle.getColumnHandles().stream()
.collect(toMap(BlackHoleColumnHandle::getName, column -> column));
.collect(toImmutableMap(BlackHoleColumnHandle::getName, column -> column));
ssheikin marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
Expand All @@ -174,7 +174,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
{
return tables.values().stream()
.filter(table -> prefix.matches(table.toSchemaTableName()))
.collect(toMap(BlackHoleTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns()));
.collect(toImmutableMap(BlackHoleTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.spi.StandardErrorCode.ALREADY_EXISTS;
import static io.trino.spi.StandardErrorCode.NOT_FOUND;
import static io.trino.spi.StandardErrorCode.SCHEMA_NOT_EMPTY;
import static io.trino.spi.connector.SampleType.SYSTEM;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toMap;

@ThreadSafe
public class MemoryMetadata
Expand Down Expand Up @@ -174,7 +174,7 @@ public synchronized Map<String, ColumnHandle> getColumnHandles(ConnectorSession
MemoryTableHandle handle = (MemoryTableHandle) tableHandle;
return tables.get(handle.getId())
.getColumns().stream()
.collect(toMap(ColumnInfo::getName, ColumnInfo::getHandle));
ssheikin marked this conversation as resolved.
Show resolved Hide resolved
.collect(toImmutableMap(ColumnInfo::getName, ColumnInfo::getHandle));
}

@Override
Expand All @@ -191,7 +191,7 @@ public synchronized Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(
{
return tables.values().stream()
.filter(table -> prefix.matches(table.getSchemaTableName()))
.collect(toMap(TableInfo::getSchemaTableName, handle -> handle.getMetadata().getColumns()));
.collect(toImmutableMap(TableInfo::getSchemaTableName, handle -> handle.getMetadata().getColumns()));
}

@Override
Expand Down