我在我的 dynamo DB 表中引入了一个新字段 InActive,现在我想获取之前处于 Activity 状态的记录(假设所有以前的记录都处于 Activity 状态)以及新的 Activity 记录。
我的 dynamo DB 查询表达式应该是什么?
final HashMap<String, AttributeValue> activeExpressionAttrValue = new HashMap<>();
activeExpressionAttrValue.put(":in_active_false", new AttributeValue().withBOOL(false));
activeExpressionAttrValue.put(":in_active_null", new AttributeValue().withNULL(true));
dynamoDBQueryExpression.withHashKeyValues(ddbRecord.builder().primarykey(p).build())
.withFilterExpression(ddbRecord.IN_ACTIVE + " = :in_active_false OR" +
ddbRecord.IN_ACTIVE + " = :in_active_null")
.withExpressionAttributeValues(activeExpressionAttrValue);
这是正确的吗?
最佳答案
... ddbRecord.IN_ACTIVE + " = :in_active OR attribute_not_exists(" + ddbRecord.IN_ACTIVE + ")" ...
DynamoDb 不会执行到 null 的隐式转换。为了使上述查询正常工作,表中的数据必须包含:
{
"some_attribute": {
"S": "some attribute string value"
},
"is_active": {
"NULL":true
}
}
但是,我怀疑表中的旧记录根本不包含“is_active”属性,而不是让它存在并设置为 NULL,因此有效条件是 attribute_not_exists(is_active)
关于java - 如何检查 dynamoDB 过滤器表达式中是否不存在属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61209795/