日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dynamodb容器使用_使用DynamoDBMapper扫描DynamoDB项目

發(fā)布時(shí)間:2023/12/3 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 dynamodb容器使用_使用DynamoDBMapper扫描DynamoDB项目 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

dynamodb容器使用

之前,我們介紹了如何使用DynamoDBMapper或底層Java api查詢DynamoDB數(shù)據(jù)庫。

除了發(fā)出查詢之外,DynamoDB還提供掃描功能。
掃描的目的是獲取您在DynamoDB表上可能擁有的所有項(xiàng)目。
因此,掃描不需要任何基于我們的分區(qū)鍵或您的全局/本地二級索引的規(guī)則。 掃描提供的功能是基于已獲取的項(xiàng)目進(jìn)行過濾,并從已獲取的項(xiàng)目中返回特定屬性。

下面的代碼段通過過濾具有較低日期的項(xiàng)目來對“登錄名”表進(jìn)行掃描。

public List<Login> scanLogins(Long date) {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(date.toString()));DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression().withFilterExpression("#timestamp < :from").withExpressionAttributeNames(attributeNames).withExpressionAttributeValues(attributeValues);List<Login> logins = dynamoDBMapper.scan(Login.class, dynamoDBScanExpression);return logins;}

DynamoDBMapper的另一個重要功能是并行掃描。 并行掃描將掃描任務(wù)劃分為多個工作程序,每個邏輯段一個。 工作人員并行處理數(shù)據(jù)并返回結(jié)果。
通常,掃描請求的性能在很大程度上取決于DynamoDB表中存儲的項(xiàng)目數(shù)。 因此,并行掃描可能會解除掃描請求的某些性能問題,因?yàn)槟仨毺幚泶罅繑?shù)據(jù)。

public List<Login> scanLogins(Long date,Integer workers) {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(date.toString()));DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression().withFilterExpression("#timestamp < :from").withExpressionAttributeNames(attributeNames).withExpressionAttributeValues(attributeValues);List<Login> logins = dynamoDBMapper.parallelScan(Login.class, dynamoDBScanExpression,workers);return logins;}

在對我們的應(yīng)用程序使用掃描之前,我們必須考慮到掃描會獲取所有表項(xiàng)。 因此,它在費(fèi)用和性能上都有很高的成本。 此外,它可能會消耗您的配置容量。
通常,最好堅(jiān)持查詢并避免掃描。

您可以在github上找到帶有單元測試的完整源代碼。

翻譯自: https://www.javacodegeeks.com/2016/10/scan-dynamodb-items-dynamodbmapper.html

dynamodb容器使用

總結(jié)

以上是生活随笔為你收集整理的dynamodb容器使用_使用DynamoDBMapper扫描DynamoDB项目的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。