1

I am having an issue where I am trying to get the data from the DynamoDB directly to my android studio. It works totally fine if I want to query with PK and filter with random column, however, no matter what I do I am unable to use also the sort key. Expression cannot be used as its part of partion key, but it is also not possible to put two primitive types into the query.

I also tried using QueryFilter, however, I am getting has protected access on the code bellow, even if I extend the class.

QueryFilter queryFilter = new QueryFilter();

This is the code which works for query with only Partion Key without Sort Key.

final Expression expression = new Expression();
expression.setExpressionStatement("#t < :time");
//expression.setExpressionStatement("begins_with (#t, :time)");
expression.withExpressionAttibuteValues(":time", new Primitive(timeNow.format(format)));
expression.addExpressionAttributeNames("#t", "time");

Search searchResult = dbTable.query(new Primitive("Location1"), expression);

1 Answer 1

1

After trying for a bit longer I have found a solution with QueryOperationConfig. As someone may find this usefull, I will be posting the solution which worked for me.

    final Expression expression2 = new Expression();
    expression2.setExpressionStatement("#p = :PK AND begins_with(#s, :SK)");
    expression2.withExpressionAttibuteValues(":PK", new Primitive("Location1"));
    expression2.withExpressionAttibuteValues(":SK", new Primitive("2021-04-11 22:08"));
    expression2.addExpressionAttributeNames("#p", "location");
    expression2.addExpressionAttributeNames("#s", "device # MAC # UUID");

    QueryOperationConfig queryOperationConfig = new QueryOperationConfig();
    queryOperationConfig.withKeyExpression(expression2);
    Search searchResult = dbTable.query(queryOperationConfig);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.