Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use reserved keyword 'year' in dynamodb query

I tried to fetch the records on behalf of year(reserved keyword) from dynamodb.

But could not get success.

DynamoDBScanExpression queryExpression = new DynamoDBScanExpression();
queryExpression.withFilterExpression("year = :year).withExpressionAttributeValues(valueMap);
result = dynamoDBTemplate.scan(ABC.class, queryExpression);
like image 965
Anoop Kumar Avatar asked Nov 07 '16 09:11

Anoop Kumar


2 Answers

      DynamoDBScanExpression queryExpression = new DynamoDBScanExpression();

      Map<String, AttributeValue> valueMap = new HashMap<>();

     valueMap.put(":year", new AttributeValue().withS(2016));

    queryExpression.withFilterExpression("#y = :year).

   .withExpressionAttributeValues(valueMap);

   Map<String, String> expression = new HashMap<>();

            expression.put("#y", "year");

     queryExpression.withExpressionAttributeNames(expression);

solved my problem.

like image 83
Anoop Kumar Avatar answered Sep 25 '22 15:09

Anoop Kumar


Map<String, String> rwnm = new HashMap();
rwnm.put("#a", "action");

QuerySpec querySpec = new QuerySpec();
querySpec.withFilterExpression("#a > :action");
querySpec.withNameMap(rwnm);
querySpec.withValueMap(new ValueMap().withString(":action", "LightsOn"));
like image 28
Prathap Pandian Murugessan Avatar answered Sep 25 '22 15:09

Prathap Pandian Murugessan