Skip to content

Commit

Permalink
Prefer ImmutableMap to Map
Browse files Browse the repository at this point in the history
ConnectorMetadata#getColumnHandles,
ConnectorMetadata#listTableColumns
are immutable
  • Loading branch information
ssheikin authored and kokosing committed Feb 2, 2021
1 parent 3499437 commit c498038
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
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));
}

@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));
.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

0 comments on commit c498038

Please sign in to comment.