Java Code Examples for software.amazon.awssdk.services.dynamodb.model.ScanResponse#items()
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.ScanResponse#items() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DynamoDBScanItems.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void scanItems( DynamoDbClient ddb,String tableName ) { try { ScanRequest scanRequest = ScanRequest.builder() .tableName(tableName) .build(); ScanResponse response = ddb.scan(scanRequest); for (Map<String, AttributeValue> item : response.items()) { Set<String> keys = item.keySet(); for (String key : keys) { System.out.println ("The key name is "+key +"\n" ); System.out.println("The value is "+item.get(key).s()); } } } catch (DynamoDbException e) { e.printStackTrace(); } // snippet-end:[dynamodb.java2.dynamoDB_scan.main] }
Example 2
Source File: DynamoDBIO.java From beam with Apache License 2.0 | 5 votes |
@Override public List<Map<String, AttributeValue>> apply(@Nullable ScanResponse scanResponse) { if (scanResponse == null) { return Collections.emptyList(); } return scanResponse.items(); }
Example 3
Source File: DynamoDBIOTestHelper.java From beam with Apache License 2.0 | 5 votes |
static List<Map<String, AttributeValue>> generateTestData(String tableName, int numOfItems) { BatchWriteItemRequest batchWriteItemRequest = generateBatchWriteItemRequest(tableName, numOfItems); dynamoDBClient.batchWriteItem(batchWriteItemRequest); ScanResponse scanResult = dynamoDBClient.scan(ScanRequest.builder().tableName(tableName).build()); List<Map<String, AttributeValue>> items = scanResult.items(); Assert.assertEquals(numOfItems, items.size()); return items; }
Example 4
Source File: AWSDynamoUtils.java From para with Apache License 2.0 | 5 votes |
/** * Reads a page from a standard DynamoDB table. * @param <P> type of object * @param appid the app identifier (name) * @param p a {@link Pager} * @return the last row key of the page, or null. */ public static <P extends ParaObject> List<P> readPageFromTable(String appid, Pager p) { Pager pager = (p != null) ? p : new Pager(); ScanRequest.Builder scanRequest = ScanRequest.builder(). tableName(getTableNameForAppid(appid)). limit(pager.getLimit()). returnConsumedCapacity(ReturnConsumedCapacity.TOTAL); if (!StringUtils.isBlank(pager.getLastKey())) { scanRequest.exclusiveStartKey(Collections. singletonMap(Config._KEY, AttributeValue.builder().s(pager.getLastKey()).build())); } ScanResponse result = getClient().scan(scanRequest.build()); String lastKey = null; LinkedList<P> results = new LinkedList<>(); for (Map<String, AttributeValue> item : result.items()) { P obj = fromRow(item); if (obj != null) { lastKey = item.get(Config._KEY).s(); results.add(obj); } } if (result.lastEvaluatedKey() != null && !result.lastEvaluatedKey().isEmpty()) { pager.setLastKey(result.lastEvaluatedKey().get(Config._KEY).s()); } else if (!results.isEmpty()) { // set last key to be equal to the last result - end reached. pager.setLastKey(lastKey); } return results; }
Example 5
Source File: DynamoDBIOTestHelper.java From beam with Apache License 2.0 | 4 votes |
static List<Map<String, AttributeValue>> readDataFromTable(String tableName) { ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build(); ScanResponse scanResponse = dynamoDBClient.scan(scanRequest); return scanResponse.items(); }