dynamodb java_使用Java扫描DynamoDB项目
生活随笔
收集整理的這篇文章主要介紹了
dynamodb java_使用Java扫描DynamoDB项目
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
dynamodb java
在之前的文章中,我們介紹了如何查詢DynamoDB數據庫
查詢DynamoDB第1部分
查詢DynamoDB第2部分 。
除了發出查詢之外,DynamoDB還提供掃描功能。 掃描所做的是獲取您在DynamoDB表上可能擁有的所有項目。 因此,掃描不需要任何基于我們的分區鍵或您的全局/本地二級索引的規則。 掃描提供的功能是基于已獲取的項目進行過濾,并從已獲取的項目中返回特定屬性。
下面的代碼段通過添加過濾并僅選擇電子郵件字段來對“登錄名”表進行掃描。
public List<String> scanLogins(Date date) {List<String> emails = new ArrayList<>();Map<String, String> attributeNames = new HashMap<String, String >();attributeNames.put("#timestamp", "timestamp");Map<String, AttributeValue> attributeValues = new HashMap<String, AttributeValue>();attributeValues.put(":from", new AttributeValue().withN(Long.toString(date.getTime())));ScanRequest scanRequest = new ScanRequest().withTableName(TABLE_NAME).withFilterExpression("#timestamp < :from").withExpressionAttributeNames(attributeNames).withExpressionAttributeValues(attributeValues).withProjectionExpression("email");Map<String,AttributeValue> lastKey = null;do {ScanResult scanResult = amazonDynamoDB.scan(scanRequest);List<Map<String,AttributeValue>> results = scanResult.getItems();results.forEach(r->emails.add(r.get("email").getS()));lastKey = scanResult.getLastEvaluatedKey();scanRequest.setExclusiveStartKey(lastKey);} while (lastKey!=null);return emails;} 在對應用程序使用掃描之前,我們必須考慮到掃描會獲取所有表項。 因此,它在費用和性能上都有很高的成本。 此外,它可能會消耗您的配置容量。
最好堅持查詢并避免掃描。
您可以在github上找到源代碼。
翻譯自: https://www.javacodegeeks.com/2016/08/scan-dynamodb-items-java.html
dynamodb java
總結
以上是生活随笔為你收集整理的dynamodb java_使用Java扫描DynamoDB项目的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 粉尘传感器设置(粉尘传感器说明书)
- 下一篇: 双电池手机(手机双电池和单电池)