I have one partition key value and a list of corresponding sort key values for a dynamoDB table, and I'm trying to use batchWriteItem in java to delete them. But it is not working
TableWriteItems deleteItems = new TableWriteItems("tableName");
keyList = new ArrayList();
for (String sortKey: sortKeys) {
keyList.add(partitionKey)
keyList.add(sortKey)
}
deleteItems.withHashAndRangeKeysToDelete(partKeyField,sortKeyField,keyList)
Source for doing it this way. But I get the following error:
number of hash and range key values must be the same
I also tried to add the withHashAndRangeKeysToDelete iteratively to the TableWriteItems object directly, but that didn't work either. So how do I perform this batch delete operation?
Edit: Based on @luk2302 suggestion, I used this solution to pass the list of hash key and sort keys collected above as a varargs parameter. I am getting the following error:
java.lang.UnsupportedOperationException: value type: class [Ljava.lang.String;
My code for reference:
deleteItems.withHashAndRangeKeysToDelete(partKeyField,sortKeyField, hashRangeList.toArray(new String[0]))
Edit2: I mistakenly added an additional param in my code which caused the error. Issue is resolved now so closing the question