George
George

Reputation: 31

DynamoDB Enhanced Client Error: Unable to unmarshall response

I am new to DynamoDB and am trying to write some Java code to do a parallel scan of a table with 3 threads using the enhanced DynamoDB client. I am using the AWS Java SDK v 2.17.85.

My code is throwing the following error in each thread soon after starting: Unable to unmarshall response (null). When I do the scan in a single thread everything works fine. All the examples I see in the documentation seem to be for the old client. I'd appreciate some insight from the experts here. Thanks.

private static class ScanSegmentTask implements Runnable {

        private String tableName;
        private int itemLimit;
        private int totalSegments;
        private int segment;
        
        private long scannedItemCount = 0;

        public ScanSegmentTask(String tableName, int itemLimit, int totalSegments, int seg) {
            this.tableName = tableName;
            this.itemLimit = itemLimit;
            this.totalSegments = totalSegments;
            this.segment = seg;
        }

        @Override
        public void run() {
            System.out.println("Scanning " + tableName + " segment " + segment + " out of " + totalSegments
                + " segments " + itemLimit + " items at a time...");

            DynamoDbTable<TfProdHmiBean> hmiTable = enhancedClient.table(tableName, TableSchema.fromBean(TfProdHmiBean.class));
            try {

                ScanEnhancedRequest spec = ScanEnhancedRequest.builder().limit(itemLimit).segment(segment).totalSegments(totalSegments).build();
                Iterator<TfProdHmiBean> results = hmiTable.scan(spec).items().iterator();
                while (results.hasNext()) {
                    scannedItemCount++;
                    if (scannedItemCount % 1000000 == 0) {
                        System.out.println("Scanned " + scannedItemCount + " items from segment " + segment + " out of " + totalSegments);
                    }
                    results.next();
                }
            }
            catch (Exception e) {
                System.err.println("Error: " + e.getMessage() + " in segment " + segment);
            }
            finally {
                System.out.println("Scanned " + scannedItemCount + " items from segment " + segment + " out of "
                    + totalSegments + " of " + tableName);
            }
        }
        
    }

Upvotes: 1

Views: 1904

Answers (1)

George
George

Reputation: 31

It appears the issue is with the bean class I'm providing to the SDK for mapping.

I changed the call from

DynamoDbTable<TfProdHmiBean> hmiTable = enhancedClient.table(tableName, TableSchema.fromBean(TfProdHmiBean.class));

to

DynamoDbTable<TfProdHmiBean> hmiTable = enhancedClient.table(tableName, TableSchema.fromClas(TfProdHmiBean.class));

and then I annotated the get method for each field with the source field in DynamoDB with @DynamoDbAttribute(value="dynamo field name")

This works. For now this is good enough for my purposes.

Upvotes: 2

Related Questions