-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align behaviour of default table creation between sync and async table
This adds the behaviour introduced in the sync DDB table to the async version as well. See commit ef2aa90 for original code
- Loading branch information
Showing
4 changed files
with
99 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "Amazon DynamoDB Enhanced", | ||
"description": "This bugfix ensures that when using DynamoDbAsyncTable.createTable with no arguments any secondary indices defined in your TableSchema are also created. This behaviour was already present in the synchronous DynamoDbTable", | ||
"contributor": "zakerf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...ain/java/software/amazon/awssdk/enhanced/dynamodb/internal/client/DynamoDbTableUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.enhanced.dynamodb.internal.client; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.enhanced.dynamodb.IndexMetadata; | ||
import software.amazon.awssdk.enhanced.dynamodb.KeyAttributeMetadata; | ||
import software.amazon.awssdk.enhanced.dynamodb.TableMetadata; | ||
import software.amazon.awssdk.enhanced.dynamodb.TableSchema; | ||
import software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex; | ||
import software.amazon.awssdk.enhanced.dynamodb.model.EnhancedLocalSecondaryIndex; | ||
import software.amazon.awssdk.services.dynamodb.model.ProjectionType; | ||
|
||
@SdkInternalApi | ||
public final class DynamoDbTableUtils { | ||
|
||
private DynamoDbTableUtils() { | ||
} | ||
|
||
public static Map<IndexType, List<IndexMetadata>> splitSecondaryIndicesToLocalAndGlobalOnes(TableSchema<?> tableSchema) { | ||
Collection<IndexMetadata> indices = tableSchema.tableMetadata().indices(); | ||
return indices.stream() | ||
.filter(index -> !TableMetadata.primaryIndexName().equals(index.name())) | ||
.collect(Collectors.groupingBy(metadata -> { | ||
String partitionKeyName = metadata.partitionKey().map(KeyAttributeMetadata::name).orElse(null); | ||
if (partitionKeyName == null) { | ||
return IndexType.LSI; | ||
} | ||
return IndexType.GSI; | ||
})); | ||
} | ||
|
||
public static List<EnhancedLocalSecondaryIndex> extractLocalSecondaryIndices(Map<IndexType, List<IndexMetadata>> indicesGroups) { | ||
return indicesGroups.getOrDefault(IndexType.LSI, emptyList()).stream() | ||
.map(DynamoDbTableUtils::mapIndexMetadataToEnhancedLocalSecondaryIndex) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static EnhancedLocalSecondaryIndex mapIndexMetadataToEnhancedLocalSecondaryIndex(IndexMetadata indexMetadata) { | ||
return EnhancedLocalSecondaryIndex.builder() | ||
.indexName(indexMetadata.name()) | ||
.projection(pb -> pb.projectionType(ProjectionType.ALL)) | ||
.build(); | ||
} | ||
|
||
public static List<EnhancedGlobalSecondaryIndex> extractGlobalSecondaryIndices(Map<IndexType, List<IndexMetadata>> indicesGroups) { | ||
return indicesGroups.getOrDefault(IndexType.GSI, emptyList()).stream() | ||
.map(DynamoDbTableUtils::mapIndexMetadataToEnhancedGlobalSecondaryIndex) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static EnhancedGlobalSecondaryIndex mapIndexMetadataToEnhancedGlobalSecondaryIndex(IndexMetadata indexMetadata) { | ||
return EnhancedGlobalSecondaryIndex.builder() | ||
.indexName(indexMetadata.name()) | ||
.projection(pb -> pb.projectionType(ProjectionType.ALL)) | ||
.build(); | ||
} | ||
|
||
} |