有没有办法查询DynamoDB中的多个哈希键? [英] Is there a way to query multiple hash keys in DynamoDB?

查看:80
本文介绍了有没有办法查询DynamoDB中的多个哈希键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Amazon的Java AWS开发工具包中,是否可以使用一个查询来查询多个哈希键?

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 通过同一查询进程查找不是新的或未完成的项目。

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中的多个哈希键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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