I am trying to delete a field called “dog” from all of the items that resides on table animals, or that I use the following code:
Table table= dynamoDB.getTable("animals"); ScanRequest scanRequest = new ScanRequest().withTableName("animals"); ScanResult result = client.scan(scanRequest); for (Map<String, AttributeValue> item : result.getItems()){ table.updateItem(new PrimaryKey("<Primary partition key name>", item.get("<Primary partition key name>"),"<Primary sort key name>", item.get("<Primary sort key name>")), new AttributeUpdate("dog").delete()); }
But I am getting:
Exception in thread "main" java.lang.RuntimeException: value type: class com.amazonaws.services.dynamodbv2.model.AttributeValue . . . Caused by: java.lang.UnsupportedOperationException: value type: class com.amazonaws.services.dynamodbv2.model.AttributeValue
What am I doing wrong here?
by the way, I also tried:
UpdateItemSpec updateItemSpec = new UpdateItemSpec() .withPrimaryKey("<Primary partition key name>", item.get("<Primary partition key name>"),"<Primary sort key name>", item.get("<Primary sort key name>")) .withUpdateExpression("REMOVE dog"); table.updateItem(updateItemSpec);
But got the same exception. (Also tried DELETE instead of REMOVE)
Advertisement
Answer
I found the solution for the issue, I cant believe I missed it…. Remember kids, its mandatory to look at the actual values when debugging!
So instead of using just:
item.get("<property name>")
You need to explicitly ask for a String like so:
item.get("<property name>").getS()