use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_withLsiAndGsi.
@Test
public void generateRequest_withLsiAndGsi() {
Projection projection1 = Projection.builder().projectionType(ProjectionType.ALL).build();
Projection projection2 = Projection.builder().projectionType(ProjectionType.KEYS_ONLY).build();
Projection projection3 = Projection.builder().projectionType(ProjectionType.INCLUDE).nonKeyAttributes("key1", "key2").build();
ProvisionedThroughput provisionedThroughput1 = ProvisionedThroughput.builder().readCapacityUnits(1L).writeCapacityUnits(2L).build();
ProvisionedThroughput provisionedThroughput2 = ProvisionedThroughput.builder().readCapacityUnits(3L).writeCapacityUnits(4L).build();
List<EnhancedGlobalSecondaryIndex> globalSecondaryIndexList = Arrays.asList(EnhancedGlobalSecondaryIndex.builder().indexName("gsi_1").projection(projection1).provisionedThroughput(provisionedThroughput1).build(), EnhancedGlobalSecondaryIndex.builder().indexName("gsi_2").projection(projection2).provisionedThroughput(provisionedThroughput2).build());
CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(globalSecondaryIndexList).localSecondaryIndices(Collections.singletonList(EnhancedLocalSecondaryIndex.create("lsi_1", projection3))).build());
CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null);
assertThat(request.tableName(), is(TABLE_NAME));
assertThat(request.keySchema(), containsInAnyOrder(KeySchemaElement.builder().attributeName("id").keyType(HASH).build(), KeySchemaElement.builder().attributeName("sort").keyType(RANGE).build()));
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex expectedGsi1 = software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex.builder().indexName("gsi_1").keySchema(KeySchemaElement.builder().attributeName("gsi_id").keyType(HASH).build(), KeySchemaElement.builder().attributeName("gsi_sort").keyType(RANGE).build()).projection(projection1).provisionedThroughput(provisionedThroughput1).build();
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex expectedGsi2 = software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex.builder().indexName("gsi_2").keySchema(KeySchemaElement.builder().attributeName("gsi_id").keyType(HASH).build()).projection(projection2).provisionedThroughput(provisionedThroughput2).build();
assertThat(request.globalSecondaryIndexes(), containsInAnyOrder(matchesGsi(expectedGsi1), matchesGsi(expectedGsi2)));
software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex expectedLsi = software.amazon.awssdk.services.dynamodb.model.LocalSecondaryIndex.builder().indexName("lsi_1").keySchema(KeySchemaElement.builder().attributeName("id").keyType(HASH).build(), KeySchemaElement.builder().attributeName("lsi_sort").keyType(RANGE).build()).projection(projection3).build();
assertThat(request.localSecondaryIndexes(), containsInAnyOrder(expectedLsi));
assertThat(request.attributeDefinitions(), containsInAnyOrder(AttributeDefinition.builder().attributeName("id").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("sort").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("lsi_sort").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("gsi_id").attributeType(ScalarAttributeType.S).build(), AttributeDefinition.builder().attributeName("gsi_sort").attributeType(ScalarAttributeType.S).build()));
}
use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_validLsiAsGsiReference.
@Test
public void generateRequest_validLsiAsGsiReference() {
List<EnhancedGlobalSecondaryIndex> validLsiList = Collections.singletonList(EnhancedGlobalSecondaryIndex.builder().indexName("lsi_1").projection(p -> p.projectionType(ProjectionType.ALL)).provisionedThroughput(p -> p.readCapacityUnits(1L).writeCapacityUnits(1L)).build());
CreateTableOperation<FakeItemWithIndices> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(validLsiList).build());
CreateTableRequest request = operation.generateRequest(FakeItemWithIndices.getTableSchema(), PRIMARY_CONTEXT, null);
assertThat(request.globalSecondaryIndexes().size(), is(1));
software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndex globalSecondaryIndex = request.globalSecondaryIndexes().get(0);
assertThat(globalSecondaryIndex.indexName(), is("lsi_1"));
}
use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex in project aws-sdk-java-v2 by aws.
the class CreateTableOperationTest method generateRequest_invalidGsi.
@Test(expected = IllegalArgumentException.class)
public void generateRequest_invalidGsi() {
ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder().readCapacityUnits(1L).writeCapacityUnits(1L).build();
List<EnhancedGlobalSecondaryIndex> invalidGsiList = Collections.singletonList(EnhancedGlobalSecondaryIndex.builder().indexName("invalid").projection(p -> p.projectionType(ProjectionType.ALL)).provisionedThroughput(provisionedThroughput).build());
CreateTableOperation<FakeItem> operation = CreateTableOperation.create(CreateTableEnhancedRequest.builder().globalSecondaryIndices(invalidGsiList).build());
operation.generateRequest(FakeItem.getTableSchema(), PRIMARY_CONTEXT, null);
}
use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex in project serve by pytorch.
the class DDBSnapshotSerializerTest method createTable.
private void createTable() {
ProvisionedThroughput provThroughput = ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build();
Projection projectAll = Projection.builder().projectionType(ProjectionType.ALL).build();
EnhancedGlobalSecondaryIndex gsi = EnhancedGlobalSecondaryIndex.builder().indexName("createdOnMonth-index").projection(projectAll).provisionedThroughput(provThroughput).build();
CreateTableEnhancedRequest createTableReq = CreateTableEnhancedRequest.builder().globalSecondaryIndices(Arrays.asList(gsi)).build();
snapshotTable.createTable(createTableReq);
}
use of software.amazon.awssdk.enhanced.dynamodb.model.EnhancedGlobalSecondaryIndex in project micronaut-aws-sdk by agorapulse.
the class DefaultDynamoDbService method createTable.
@Override
public void createTable() {
Map<String, ProjectionType> types = getProjectionTypes();
TableMetadata tableMetadata = table.tableSchema().tableMetadata();
table.createTable(b -> {
List<EnhancedLocalSecondaryIndex> localSecondaryIndices = new ArrayList<>();
List<EnhancedGlobalSecondaryIndex> globalSecondaryIndices = new ArrayList<>();
tableMetadata.indices().forEach(i -> {
if (TableMetadata.primaryIndexName().equals(i.name())) {
return;
}
ProjectionType type = types.getOrDefault(i.name(), ProjectionType.KEYS_ONLY);
if (tableMetadata.primaryPartitionKey().equals(tableMetadata.indexPartitionKey(i.name()))) {
localSecondaryIndices.add(EnhancedLocalSecondaryIndex.create(i.name(), Projection.builder().projectionType(type).build()));
} else {
globalSecondaryIndices.add(EnhancedGlobalSecondaryIndex.builder().indexName(i.name()).projection(Projection.builder().projectionType(type).build()).build());
}
});
if (!localSecondaryIndices.isEmpty()) {
b.localSecondaryIndices(localSecondaryIndices);
}
if (!globalSecondaryIndices.isEmpty()) {
b.globalSecondaryIndices(globalSecondaryIndices);
}
});
}
Aggregations