我有更新要求,用户将几个字段更新为新值,而很少将其更改为空。需要将其更新到DynamoDB。以下代码可以正常工作,但是如果该值以“”(空)开头,则为字段decision
设置null。在AWS控制台中类似decision Null : true
的内容。
是否有更好的方法删除列或将其设置为空而不是将其设置为null?请帮忙。
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("GUID", "guidHashed", "VENDOR", "vendorValue");
NameMap nameMap = new NameMap();
ValueMap valueMap = new ValueMap();
StringBuilder queryString = new StringBuilder();
queryString.append("set");
if (decision != null && decision.isEmpty()) { // condition if the field is empty ""
nameMap.with("#decision_name", "decision");
valueMap.withNull(":decision_value");
queryString.append("#decision_name = :decision_value,");
}
if (StringUtils.isNotEmpty(decision)) { // condition if field is not empty
nameMap.with("#decision_name", "decision");
valueMap.with(":decision_value", decision);
queryString.append("#decision_name = :decision_value,");
}
//i have many fields
updateItemSpec.withNameMap(nameMap);
updateItemSpec.withValueMap(valueMap);
updateItemSpec.withUpdateExpression(requestParams);
Table table = dynamoDB.getTable("INFO_TABLE");
table.updateItem(updateItemSpec);
我尝试将withAttributeUpdates与Action Delete一起使用,但DynamoDb认为Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributeUpdates} Expression parameters