DynamoDB Group Count By
We are trying to search dynamodb and we need to get the number of objects in a group, how can this be done?
I tried this, but when adding the second number it doesn't work:
$search = array(
'TableName' => 'dev_adsite_rating',
'Select' => 'COUNT',
'KeyConditions' => array(
'ad_id' => array(
'ComparisonOperator' => 'EQ',
'AttributeValueList' => array(
array('N' => 1039722, 'N' => 1480)
)
)
)
);
$response = $client->query($search);
The sql version will look something like this:
select ad_id, count(*)
from dev_adsite_rating
where ad_id in(1039722, 1480)
group by ad_id;
So, is there a way to achieve this? I can't find anything on it.
+3
source to share
1 answer
Trying to execute such a query in DynamoDB is a little more difficult than it is in the SQL world. To accomplish something like this, you need to consider several things
- EQ ONLY Hash Key . To fulfill such a request, you need to make two requests (for example, ad_id EQ 1039722 / ad_id EQ 1480).
- Paginate via query . Since dynamodb returns your result in many increments, you will need to paginate your results. More information ...
- Start "Count" . You can take the "Count" property from the response and add it to the current summary as you are paginating the results of both queries. API requests
+1
source to share