in Education by
Currently, I'm using Spring boot with DynamoDB and using DynamoDBMapper for all DB operation. Right now it's sorting in ascending order based on sort key(field name id). How can I sort in descending order based on sort key value? Current code : @Override public PageImpl getCustomerOrders(Pageable pageable) { List orders = new ArrayList<>(); Map eav = new HashMap(); DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); List exp = new ArrayList<>(); // filters if (!exp.isEmpty()) scanExpression .withFilterExpression(String.join(" AND ", exp)).withExpressionAttributeValues(eav); PaginatedScanList scan = mapper.scan(Order.class, scanExpression); int start = (int) pageable.getOffset(); int size = scan.size(); int end = (start + pageable.getPageSize()) > size ? size : (start + pageable.getPageSize()); if (start < size) for (Order o : scan.subList(start, end)) { orders.add(o); } return new PageImpl(orders, pageable, size); } After some googling, I found that I need to set ScanIndexForward to be true but still I'm confused that how can I achieve it with DynamoDBMApper? Or should I need to use any low-level class like DynamoDB or AmazonDynamoDb? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Finally, I found the solution myself, Thanks to @ydrall for the hint. As per his comment, ScanIndexForward can only be used with query option so I just updated with query. I had created DynamoDBQueryExpression object and updated the property using setScanIndexForward method ( false ). Full java code : @Override public PageImpl getAllProgramOrder(Pageable pageable, OrderFilter filter) { List orders = new ArrayList<>(); DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression(); queryExpression.setScanIndexForward(false); Map eav = new HashMap(); eav.put(":val1", new AttributeValue().withS(authenticationFacade.getProgramId())); queryExpression.withKeyConditionExpression("hashKey = :val1 ") .withExpressionAttributeValues(eav); PaginatedQueryList scan = mapper.query(Order.class, queryExpression); int start = (int) pageable.getOffset(); int size = scan.size(); int end = (start + pageable.getPageSize()) > size ? size : (start + pageable.getPageSize()); if (start < size) for (Order o : scan.subList(start, end)) { orders.add(o); } return new PageImpl(orders, pageable, size); } Ref : How can I Scan an index in reverse in DynamoDB?

Related questions

0 votes
    I've got a large array of primitive types (double). How do I sort the elements in descending ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    How can I sort an event by id in DESC order? My all events are coming and by default they are ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    How can I sort an event by id in DESC order? My all events are coming and by default they are ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Columns can be arranged in descending order too by using the special ____ operator. (a) asc() (b) desc( ... Operations of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have a Post model that has a likes array that contains the ObjectId of the user that liked the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    HOW DO I SORT THIS BY BIRTHYEAR IN ASCENDING ORDER? I'm distance learning student and have no help. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    Which of the following sort a dataframe by the order of the elements in B? (a) x[rev(order(x$B)), ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    What is the default SORT order for a SQL? (a) Ascending (b) Descending (c) As specified by ... and Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    What would be a nice way to go from {2:3, 1:89, 4:5, 3:0} to {1:89, 2:3, 3:0, 4:5}? ... use the "sorted" operator that returns tuples. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    Based on solute - solvent interactions, arrange the following in order of increasing solubility in n- octane and ... CHM3OH,CHM3CN . Select the correct answer from above options...
asked Jan 5, 2022 in Education by JackTerrance
0 votes
    In ordered indices the file containing the records is sequentially ordered, a ___________ is an index whose ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Indices whose search key specifies an order different from the sequential order of the file are called ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    In ordered indices the file containing the records is sequentially ordered, a ___________ is an index whose ... Indices in section Indexing and Hashing of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I'm using Elasticsearch 6.6 and have an index (1 shard, 1 replica) with the geonames (https:// ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    E Amange these devices in descending onder af stage capacity pendrive DVD CD Hard disk blu ray disc memory stick Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
...