0
votes

I'm using the Amazon AWS DynamoDB for android, however, there's no way for me to set the KeyConditionExpression for a query.

See [http://docs.aws.amazon.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/mobileconnectors/dynamodbv2/dynamodbmapper/DynamoDBQueryExpression.html][1]. The DynamoDBQueryExpression class is missing a withKeyConditionExpression() method.

I'm trying to make a query against dynamodb table but there's no way for me to set the key condition values.

3

3 Answers

1
votes

Unfortunately keyConditionExpression No Longer exist for Java / Android. I wasted a significant amount of time because it still exist for Objective-C / iOS.

And since all AWS docs still refer to it, I thought I was in error. Once I have the new code written and working, I will document the replacement here.

0
votes

The keyConditionExpression is set as follows:

AWSDynamoDBQueryExpression *queryExpression = [AWSDynamoDBQueryExpression new];
queryExpression.keyConditionExpression = @"#bookId = :bookId";
queryExpression.expressionAttributeNames = @{
                                             @"#bookId" : @"bookId",
                                             };
queryExpression.expressionAttributeValues = @{
                                              @":bookId" : self.selectedBookId,
                                              };
0
votes

I encountered the similar problem for my Android Application where .withKeyConditionExpression() method was giving an error. Instead of that, I used:

TestTable object = new TestTable();
object.setHashKeyValue("12345"); //Set the value for HashKey

String queryString = "soverflow";

Condition rangeKeyCondition = new Condition() .withComparisonOperator(ComparisonOperator.BEGINS_WITH.toString()) .withAttributeValueList(new AttributeValue().withS(queryString.toString()));

DynamoDBQueryExpression newQueryExpression = new DynamoDBQueryExpression() .withHashKeyValues(object)
.withRangeKeyCondition("AttributeName", rangeKeyCondition)
.withConsistentRead(false);

PaginatedQueryList result = mapper.query(TestTable.class, newQueryExpression);

The Point is that If you are Querying a table, the HashKey and the RangeKey will be the Partition Keys of the table and If you are Querying an Index, the Hash Key and the Range Key will be the partition keys of the Index.

Make sure to use the Annotations properly in the Table Class and to add Index's ARN to the Policy for authorization.