use of software.amazon.awssdk.services.dynamodb.model.ScanRequest in project iep by Netflix.
the class PaginationTest method dynamoDB.
@Test
public void dynamoDB() throws Exception {
Map<String, AttributeValue> nextPage = new HashMap<>();
nextPage.put("abc", AttributeValue.builder().build());
Map<String, AttributeValue> donePage = new HashMap<>();
Function<ScanRequest, ScanResponse> f = r -> {
if (r.exclusiveStartKey() != null) {
Assert.assertTrue(r.exclusiveStartKey().containsKey("abc"));
}
return ScanResponse.builder().lastEvaluatedKey((r.exclusiveStartKey() == null) ? nextPage : donePage).build();
};
Publisher<ScanResponse> publisher = Pagination.createPublisher(ScanRequest.builder().build(), f);
Iterable<ScanResponse> iter = Flowable.fromPublisher(publisher).blockingIterable();
int count = 0;
for (ScanResponse r : iter) {
++count;
}
Assert.assertEquals(2, count);
}
use of software.amazon.awssdk.services.dynamodb.model.ScanRequest in project syndesis-qe by syndesisio.
the class DynamoDbUtils method getNrOfRecordsPresentInTable.
public int getNrOfRecordsPresentInTable() {
ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build();
ScanResponse result = dynamoDb.scan(scanRequest);
return result.items().size();
}
use of software.amazon.awssdk.services.dynamodb.model.ScanRequest in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBScanItems method scanItems.
// snippet-start:[dynamodb.java2.dynamoDB_scan.main]
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();
System.exit(1);
}
}
use of software.amazon.awssdk.services.dynamodb.model.ScanRequest in project cas by apereo.
the class DynamoDbTableUtils method getRecordsByKeys.
/**
* Gets records by keys.
*
* @param <T> the type parameter
* @param dynamoDbClient the dynamo db client
* @param tableName the table name
* @param queries the queries
* @param itemMapper the item mapper
* @return the records by keys
*/
public static <T> Stream<T> getRecordsByKeys(final DynamoDbClient dynamoDbClient, final String tableName, final List<DynamoDbQueryBuilder> queries, final Function<Map<String, AttributeValue>, T> itemMapper) {
try {
val scanFilter = queries.stream().map(query -> {
val cond = Condition.builder().comparisonOperator(query.getOperator()).attributeValueList(query.getAttributeValue()).build();
return Pair.of(query.getKey(), cond);
}).collect(Collectors.toMap(Pair::getKey, Pair::getValue));
val scanRequest = ScanRequest.builder().tableName(tableName).scanFilter(scanFilter).build();
LOGGER.debug("Submitting request [{}] to get record with keys [{}]", scanRequest, queries);
val items = dynamoDbClient.scan(scanRequest).items();
return items.stream().map(itemMapper);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
return Stream.empty();
}
use of software.amazon.awssdk.services.dynamodb.model.ScanRequest in project syndesis-qe by syndesisio.
the class DynamoDbUtils method purgeTable.
public void purgeTable() {
ScanRequest scanRequest = ScanRequest.builder().tableName(tableName).build();
ScanResponse result = dynamoDb.scan(scanRequest);
for (Map<String, AttributeValue> item : result.items()) {
dynamoDb.deleteItem(DeleteItemRequest.builder().tableName(tableName).key(item).build());
}
}
Aggregations