mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 10:38:00 -05:00
fix: DynamoDB DescribeTable returns Projection.NonKeyAttributes (#300)
* support nonkeyattributes * attempt integration tests * fix tests
This commit is contained in:
1 parent
7af3600bca
commit
552e71e76f
4 files changed
+99
-10
No files matched your search
+8
-1
@@ -239,10 +239,17 @@ public class CloudFormationResourceProvisioner {
|
||||
}
|
||||
String projectionType = "ALL";
|
||||
JsonNode projection = gsiNode.get("Projection");
|
||||
List<String> nonKeyAttributes = new ArrayList<>();
|
||||
if (projection != null && projection.has("ProjectionType")) {
|
||||
projectionType = engine.resolve(projection.get("ProjectionType"));
|
||||
JsonNode nonKeyAttrArray = projection.path("NonKeyAttributes");
|
||||
if (!nonKeyAttrArray.isMissingNode() && nonKeyAttrArray.isArray()){
|
||||
for (JsonNode nonKeyAttr : nonKeyAttrArray){
|
||||
nonKeyAttributes.add(nonKeyAttr.asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
gsis.add(new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType));
|
||||
gsis.add(new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType, nonKeyAttributes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-2
@@ -95,7 +95,14 @@ public class DynamoDbJsonHandler {
|
||||
ks.path("AttributeName").asText(),
|
||||
ks.path("KeyType").asText())));
|
||||
String projectionType = gsiNode.path("Projection").path("ProjectionType").asText("ALL");
|
||||
GlobalSecondaryIndex gsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType);
|
||||
JsonNode nonKeyAttrArray = gsiNode.path("Projection").path("NonKeyAttributes");
|
||||
List<String> nonKeyAttributes = new ArrayList<>();
|
||||
if (!nonKeyAttrArray.isMissingNode() && nonKeyAttrArray.isArray()){
|
||||
for (JsonNode nonKeyAttr : nonKeyAttrArray){
|
||||
nonKeyAttributes.add(nonKeyAttr.asText());
|
||||
}
|
||||
}
|
||||
GlobalSecondaryIndex gsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType, nonKeyAttributes);
|
||||
JsonNode gsiPt = gsiNode.path("ProvisionedThroughput");
|
||||
if (!gsiPt.isMissingNode()) {
|
||||
gsi.getProvisionedThroughput().setReadCapacityUnits(gsiPt.path("ReadCapacityUnits").asLong(0));
|
||||
@@ -416,7 +423,14 @@ public class DynamoDbJsonHandler {
|
||||
ks.path("AttributeName").asText(),
|
||||
ks.path("KeyType").asText())));
|
||||
String projectionType = createNode.path("Projection").path("ProjectionType").asText("ALL");
|
||||
GlobalSecondaryIndex newGsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType);
|
||||
JsonNode nonKeyAttrArray = createNode.path("Projection").path("NonKeyAttributes");
|
||||
List<String> nonKeyAttributes = new ArrayList<>();
|
||||
if (!nonKeyAttrArray.isMissingNode() && nonKeyAttrArray.isArray()){
|
||||
for (JsonNode nonKeyAttr : nonKeyAttrArray){
|
||||
nonKeyAttributes.add(nonKeyAttr.asText());
|
||||
}
|
||||
}
|
||||
GlobalSecondaryIndex newGsi = new GlobalSecondaryIndex(indexName, gsiKeySchema, null, projectionType, nonKeyAttributes);
|
||||
JsonNode newGsiPt = createNode.path("ProvisionedThroughput");
|
||||
if (!newGsiPt.isMissingNode()) {
|
||||
newGsi.getProvisionedThroughput().setReadCapacityUnits(newGsiPt.path("ReadCapacityUnits").asLong(0));
|
||||
@@ -665,6 +679,13 @@ public class DynamoDbJsonHandler {
|
||||
ObjectNode projection = objectMapper.createObjectNode();
|
||||
projection.put("ProjectionType",
|
||||
gsi.getProjectionType() != null ? gsi.getProjectionType() : "ALL");
|
||||
if ("INCLUDE".equals(gsi.getProjectionType())){
|
||||
ArrayNode nonKeyAttributes = objectMapper.createArrayNode();
|
||||
for (var attr : gsi.getNonKeyAttributes()){
|
||||
nonKeyAttributes.add(attr);
|
||||
}
|
||||
projection.put("NonKeyAttributes", nonKeyAttributes);
|
||||
}
|
||||
gsiNode.set("Projection", projection);
|
||||
|
||||
ObjectNode gsiPt = objectMapper.createObjectNode();
|
||||
|
||||
+13
-1
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@@ -16,17 +17,25 @@ public class GlobalSecondaryIndex {
|
||||
private ProvisionedThroughput provisionedThroughput;
|
||||
private long itemCount;
|
||||
private long indexSizeBytes;
|
||||
private List<String> nonKeyAttributes;
|
||||
|
||||
public GlobalSecondaryIndex() {
|
||||
this.provisionedThroughput = new ProvisionedThroughput(0, 0);
|
||||
this.nonKeyAttributes = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public GlobalSecondaryIndex(String indexName, List<KeySchemaElement> keySchema,
|
||||
String indexArn, String projectionType) {
|
||||
String indexArn, String projectionType, List<String> nonKeyAttributes) {
|
||||
this.indexName = indexName;
|
||||
this.keySchema = keySchema;
|
||||
this.indexArn = indexArn;
|
||||
this.projectionType = projectionType != null ? projectionType : "ALL";
|
||||
if ("INCLUDE".equals(this.projectionType) && nonKeyAttributes != null){
|
||||
this.nonKeyAttributes = nonKeyAttributes;
|
||||
}
|
||||
else {
|
||||
this.nonKeyAttributes = new ArrayList<String>();
|
||||
}
|
||||
this.provisionedThroughput = new ProvisionedThroughput(0, 0);
|
||||
}
|
||||
|
||||
@@ -42,6 +51,9 @@ public class GlobalSecondaryIndex {
|
||||
public String getProjectionType() { return projectionType; }
|
||||
public void setProjectionType(String projectionType) { this.projectionType = projectionType; }
|
||||
|
||||
public List<String> getNonKeyAttributes() { return nonKeyAttributes; }
|
||||
public void setNonKeyAttributes(List<String> nonKeyAttributes) { this.nonKeyAttributes = nonKeyAttributes; }
|
||||
|
||||
public ProvisionedThroughput getProvisionedThroughput() { return provisionedThroughput; }
|
||||
public void setProvisionedThroughput(ProvisionedThroughput provisionedThroughput) { this.provisionedThroughput = provisionedThroughput; }
|
||||
|
||||
|
||||
+55
-6
@@ -602,6 +602,7 @@ class DynamoDbIntegrationTest {
|
||||
.body("Table.GlobalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("Table.GlobalSecondaryIndexes[0].IndexName", equalTo("TestGsi"))
|
||||
.body("Table.GlobalSecondaryIndexes[0].IndexStatus", equalTo("ACTIVE"))
|
||||
.body("Table.GlobalSecondaryIndexes[0].Projection.ProjectionType", equalTo("ALL"))
|
||||
.body("Table.GlobalSecondaryIndexes[0].IndexArn", containsString("/index/TestGsi"))
|
||||
.body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput", notNullValue())
|
||||
.body("Table.GlobalSecondaryIndexes[0].ProvisionedThroughput.ReadCapacityUnits", equalTo(0))
|
||||
@@ -649,9 +650,51 @@ class DynamoDbIntegrationTest {
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndex' }.IndexStatus", equalTo("ACTIVE"))
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndex' }.Projection.ProjectionType", equalTo("KEYS_ONLY"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void updateTableAddGsiWithIncludeProjection() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "GsiTestTable",
|
||||
"AttributeDefinitions": [
|
||||
{"AttributeName": "pk", "AttributeType": "S"},
|
||||
{"AttributeName": "gsiPk", "AttributeType": "S"},
|
||||
{"AttributeName": "gsiSk", "AttributeType": "S"},
|
||||
{"AttributeName": "owner", "AttributeType": "S"}
|
||||
],
|
||||
"GlobalSecondaryIndexUpdates": [
|
||||
{
|
||||
"Create": {
|
||||
"IndexName": "OwnerIndexProj",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "owner", "KeyType": "HASH"},
|
||||
{"AttributeName": "pk", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "INCLUDE", "NonKeyAttributes":["TestAttr"]}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.GlobalSecondaryIndexes.size()", equalTo(3))
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndexProj' }.IndexStatus", equalTo("ACTIVE"))
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndexProj' }.Projection.ProjectionType", equalTo("INCLUDE"))
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndexProj' }.Projection.NonKeyAttributes.size()", equalTo(1))
|
||||
.body("TableDescription.GlobalSecondaryIndexes.find { it.IndexName == 'OwnerIndexProj' }.Projection.NonKeyAttributes[0]", equalTo("TestAttr"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
void updateTableDeleteGsi() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
@@ -672,12 +715,13 @@ class DynamoDbIntegrationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.GlobalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("TableDescription.GlobalSecondaryIndexes[0].IndexName", equalTo("OwnerIndex"));
|
||||
.body("TableDescription.GlobalSecondaryIndexes.size()", equalTo(2))
|
||||
.body("TableDescription.GlobalSecondaryIndexes[0].IndexName", equalTo("OwnerIndex"))
|
||||
.body("TableDescription.GlobalSecondaryIndexes[1].IndexName", equalTo("OwnerIndexProj"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(24)
|
||||
@Order(25)
|
||||
void updateTableDeleteAllGsis() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.UpdateTable")
|
||||
@@ -690,6 +734,11 @@ class DynamoDbIntegrationTest {
|
||||
"Delete": {
|
||||
"IndexName": "OwnerIndex"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Delete": {
|
||||
"IndexName": "OwnerIndexProj"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -702,7 +751,7 @@ class DynamoDbIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(25)
|
||||
@Order(26)
|
||||
void describeTableAfterAllGsisDeletion() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
@@ -720,7 +769,7 @@ class DynamoDbIntegrationTest {
|
||||
// --- Cleanup ---
|
||||
|
||||
@Test
|
||||
@Order(26)
|
||||
@Order(27)
|
||||
void deleteTable() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
@@ -749,7 +798,7 @@ class DynamoDbIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(27)
|
||||
@Order(28)
|
||||
void updateItemListAppend() {
|
||||
// Create a table for this test
|
||||
given()
|
||||
|
||||
Reference in new issue
Block a user