Created
November 19, 2015 08:35
-
-
Save fuxingloh/4105feda2e7b3aca5a44 to your computer and use it in GitHub Desktop.
DynamoDB count total rows that match key and filter expression also fixes the reserved word issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table table = dynamoDB.getTable(UserActivity.Table.TableName); | |
Map<String, Object> valueMap = new HashMap<>(); | |
valueMap.put(":user_id", getUserId()); | |
valueMap.put(":state", UserActivity.STATE_ACTIVE); | |
valueMap.put(":type", type); | |
QuerySpec spec = new QuerySpec() | |
.withNameMap(new NameMap() | |
.with("#s", "State").with("#t", "Type")) | |
.withKeyConditionExpression("UserId = :user_id") | |
.withFilterExpression("#s = :state and #t = :type") | |
.withValueMap(valueMap); | |
spec.withSelect(Select.COUNT); | |
ItemCollection<QueryOutcome> items = table.query(spec); | |
for (Item item : items) { | |
Logger.of(getClass()).info(item.toJSONPretty()); | |
} | |
return items.getTotalCount(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment