fix: DynamoDB DescribeTable returns Projection.NonKeyAttributes (#300)

* support nonkeyattributes
* attempt integration tests
* fix tests
This commit is contained in:
bkindersleytrulioo authored and GitHub committed 2026-04-08 23:05:52 -05:00
1 parent 7af3600bca
commit 552e71e76f
4 files changed
+99 -10

No files matched your search

@@ -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));
}
}
@@ -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();
@@ -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; }