gpt4 book ai didi

java - 动态模块 : how to filer all items which do not have a certain attribute?

转载 作者:搜寻专家 更新时间:2023-11-01 02:08:43 24 4
gpt4 key购买 nike

我有一个用户表,其主哈希键为 userId。每个用户可能/可能没有名为“environment”的字符串属性。我想获得所有具有“environment”=“xyz”或没有“environment”属性的用户。

以下代码将过滤那些环境=xyz 的用户,但是我如何过滤那些根本没有环境的项目? Dynamo API 不允许过滤空字符串。

    AmazonDynamoDBClient client = DbClientManager.getDynamoDbClient();

ArrayList<AttributeValue> avList = new ArrayList<AttributeValue>();
avList.add(new AttributeValue().withS("xyz"));

Condition scanFilterCondition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ.toString())
.withAttributeValueList(avList);
Map<String, Condition> conditions = new HashMap<>();
conditions.put("environment", scanFilterCondition);

ScanRequest scanRequest = new ScanRequest()
.withTableName("users")
.withAttributesToGet(
"userId",
"environment");
.withScanFilter(conditions);

ScanResult result = client.scan(scanRequest);

现在我只是放弃了扫描过滤器,我在客户端进行过滤。有没有办法在服务器端做到这一点?

谢谢,阿里扎

最佳答案

希望我还没有太晚。我找到了可以在查询中使用的有用函数。我没有检查 ScanRequest 但 QueryRequest 很有魅力。

QueryRequest queryRequest = new QueryRequest()
.withTableName("YouTableName")
queryRequest.setFilterExpression(" attribute_not_exists(yourAttributeName) ")
queryRequest.setExpressionAttributeValues(expressionAttributeValues)
queryRequest.setExclusiveStartKey(ifYouHave)
queryRequest.setSelect('ALL_ATTRIBUTES')
queryRequest.setExpressionAttributeNames(youNames)

attribute_not_exists(yourAttributeName) 适用于“:aws-sdk:1.11.11”你也可以使用 attribute_exists(yourAttributeName)

关于java - 动态模块 : how to filer all items which do not have a certain attribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23995387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com