Skip to content
Open
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 @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.NotThreadSafe;
Expand All @@ -47,6 +48,8 @@ public final class StaticTableMetadata implements TableMetadata {
private final Map<String, Object> customMetadata;
private final Map<String, IndexMetadata> indexByNameMap;
private final Map<String, KeyAttributeMetadata> keyAttributes;
private final ConcurrentHashMap<String, List<String>> partitionKeyCache = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, List<String>> sortKeyCache = new ConcurrentHashMap<>();

private StaticTableMetadata(Builder builder) {
this.customMetadata = Collections.unmodifiableMap(builder.customMetadata);
Expand Down Expand Up @@ -84,6 +87,10 @@ public <T> Optional<T> customMetadataObject(String key, Class<? extends T> objec

@Override
public List<String> indexPartitionKeys(String indexName) {
return partitionKeyCache.computeIfAbsent(indexName, this::computePartitionKeys);
}

private List<String> computePartitionKeys(String indexName) {
IndexMetadata index = getIndex(indexName);

List<KeyAttributeMetadata> partitionKeys = index.partitionKeys();
Expand All @@ -98,21 +105,25 @@ public List<String> indexPartitionKeys(String indexName) {
+ "Index name: " + indexName);
}

return partitionKeys.stream()
return Collections.unmodifiableList(partitionKeys.stream()
.filter(Objects::nonNull)
.map(KeyAttributeMetadata::name)
.collect(Collectors.toList());
.collect(Collectors.toList()));
}

@Override
public List<String> indexSortKeys(String indexName) {
return sortKeyCache.computeIfAbsent(indexName, this::computeSortKeys);
}

private List<String> computeSortKeys(String indexName) {
IndexMetadata index = getIndex(indexName);

List<KeyAttributeMetadata> sortKeys = index.sortKeys();
return sortKeys.stream()
.filter(Objects::nonNull)
.map(KeyAttributeMetadata::name)
.collect(Collectors.toList());
return Collections.unmodifiableList(sortKeys.stream()
.filter(Objects::nonNull)
.map(KeyAttributeMetadata::name)
.collect(Collectors.toList()));
}

@Override
Expand Down