0
votes
BatchGetResultPageIterable batchResults = dynamoDbEnhancedClient
    .batchGetItem(BatchGetItemEnhancedRequest.builder()
    .readBatches(ReadBatch.builder(Analysis.class).mappedTableResource(analysisTable)
        .addGetItem(GetItemEnhancedRequest.builder()
        .key(Key.builder().partitionValue(projectId).build()).build())
    .build())
.build());
batchResults.forEach(page -> page.resultsForTable(analysisTable)
                .forEach(item -> System.out.println(item.getFileId())));

I used the above one.. but i am facing the issue software.amazon.awssdk.services.dynamodb.model.DynamoDbException: The provided key element does not match the schema (Service: DynamoDb, Status Code: 400, Request ID: 36V6D9GAGEUA817ODOGV52PF6VVV4KQNAO5AEMVJF66Q9ASUAAJG)

AnalysisTable
=================
PartitionKey    Sort Key   Name
A===============>1.txt=====>ABC              
A===============>2.txt=====>DEF
A===============>3.txt=====>GHI
A===============>4.txt=====>JKL
class Analysis {
    private String projectId;
    private String sampleId;
    private String sampleName;
    private String description;
    //setter & getters
}
2
Can you post the schema of the table you're trying to query plus more of the code you're using? The error suggests you're not querying the table correctly. - Andre.IDK
Sorry about that, i have added the schema. - Bishwajit

2 Answers

0
votes

Since you have partition and sort keys, I think you are missing the .sortValue() in your Key.builder()

It needs to be Key.builder().partitionValue(projectId).sortValue(your-sort-key).build()

0
votes

If you want everything under a certain partition key, this how you can do it:

 List<DTO> DTOs = pageToList(mappedTable.query(
    QueryEnhancedRequest
        .builder()
        .queryConditional(
            QueryConditional.keyEqualTo(
                Key.builder().partitionValue(projectId).build()
            )
        )
        .build()

  private List<DTO> pageToList(SdkIterable<Page<DTO>> iterable) {
    List<DTO> rVal = new ArrayList<>();
    iterable.forEach(item -> rVal.addAll(item.items()));
    return rVal;
  }

Note that this assumes you are using the latest enhanced dependency: