如何检查dynamoDB过滤器表达式中是否不存在属性 [英] How to check whether an attribute is not present in dynamoDB filter expression

查看:54
本文介绍了如何检查dynamoDB过滤器表达式中是否不存在属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在dynamo DB表中引入了一个新字段InActive,现在我想获取较早处于活动状态的记录(假设所有先前的记录都处于活动状态)以及新的Active记录.

I am introducing a new field InActive in my dynamo DB table, now I want to fetch the records which were active earlier (assuming all previous records were active) along with new Active records.

我的dynamo数据库查询表达式应该是什么?

What should be my dynamo DB Query expression?

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);

这正确吗?

推荐答案

请参阅- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ConditionExpressions.html

 ... ddbRecord.IN_ACTIVE + " = :in_active OR attribute_not_exists(" + ddbRecord.IN_ACTIVE + ")" ...

DynamoDb不会将隐式转换为null.为了使上面的查询正常工作,表中的数据必须包含:

DynamoDb doesn't perform implicit conversion to null. For above query to work the data in table would have to contain:

 {
     "some_attribute": {
          "S": "some attribute string value"
     },
     "is_active": {
          "NULL":true
     }
 }

但是,我怀疑表中的旧记录仅不包含"is_active"属性,而不是将其存在并设置为NULL,因此有效条件为 attribute_not_exists(is_active)

However, I suspect, that old records in table simply do not contain "is_active" attribute rather than having it present and set to NULL hence valid condition is attribute_not_exists(is_active)

这篇关于如何检查dynamoDB过滤器表达式中是否不存在属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆