問題描述
有沒有辦法在亞馬遜的 AWS SDK for Java 中使用單個查詢來查詢多個哈希鍵?
Is there a way to query multiple hash keys using a single query in Amazon's AWS SDK for Java?
這是我的問題;我有一個項目狀態的數據庫表.哈希鍵是項目的狀態(即:新建、分配、處理或完成).范圍鍵是一組項目 ID.目前,我有一個查詢設置來簡單地查找列為已分配"狀態(哈希)的所有項目和另一個查詢設置來查找處理"狀態.有沒有辦法使用單個查詢來執行此操作,而不是為我需要查找的每個狀態發送多個查詢?代碼如下:
Here's my issue; I have a DB table for project statuses. The Hash Key is the status of a project (ie: new, assigned, processing, or complete). The range key is a set of project IDs. Currently, I've got a query setup to simply find all the projects listed as a status(hash) of "assigned" and another query set to look for a status of "processing". Is there a way to do this using a single query rather than sending multiple queries for each status I need to find? Code below:
DynamoDBMapper mapper = new DynamoDBMapper(new AmazonDynamoDBClient(credentials));
PStatus assignedStatus = new PStatus();
assignedStatus.setStatus("assigned");
PStatus processStatus = new PStatus();
processStatus.setStatus("processing");
DynamoDBQueryExpression<PStatus> queryAssigned = new DynamoDBQueryExpression<PStatus>().withHashKeyValues(assignedStatus);
DynamoDBQueryExpression<PStatus> queryProcessing = new DynamoDBQueryExpression<PStatus>().withHashKeyValues(processStatus);
List<PStatus> assigned = mapper.query(PStatus.class, queryAssigned);
List<PStatus> process = mapper.query(PStatus.class, queryProcessing);
所以基本上,我想知道是否可以消除 queryAssigned
和 assigned
變量并同時處理 assignedStatus
和 processStatus
通過相同的查詢 process
來查找不是新的或不完整的項目.
So basically, I'd like to know if it's possible to eliminate the queryAssigned
and assigned
variables and handle both assignedStatus
and processStatus
via the same query, process
, to find projects that are not new or complete.
推薦答案
不,截至目前,無法在同一個請求中發送多個查詢.如果您擔心延遲,您可以在不同的線程中同時發出多個請求.如果 Dynamo 提供它,這將需要與雙重查詢"相同數量的網絡帶寬(假設您制作 2?? 個,而不是數百個).
No, as of today there is no way to send multiple queries in the same request. If you're concerned about latency, you could make multiple requests simultaneously in different threads. This would require the same amount of network bandwidth as a "dual query" would if Dynamo offered it (assuming you're making 2, not hundreds).
這篇關于有沒有辦法在 DynamoDB 中查詢多個哈希鍵?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!