use of software.amazon.awssdk.services.dynamodb.model.AttributeValue 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.AttributeValue in project beam by apache.
the class AttributeValueCoderTest method shouldPassForOneListOfByteArray.
@Test
public void shouldPassForOneListOfByteArray() throws IOException {
AttributeValue expected = AttributeValue.builder().bs(ImmutableList.of(SdkBytes.fromByteArray("mylistbyte1".getBytes(StandardCharsets.UTF_8)), SdkBytes.fromByteArray("mylistbyte2".getBytes(StandardCharsets.UTF_8)))).build();
AttributeValueCoder coder = AttributeValueCoder.of();
ByteArrayOutputStream output = new ByteArrayOutputStream();
coder.encode(expected, output);
ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
AttributeValue actual = coder.decode(in);
Assert.assertEquals(expected, actual);
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project beam by apache.
the class AttributeValueCoderTest method shouldPassForNumberType.
@Test
public void shouldPassForNumberType() throws IOException {
AttributeValue expected = AttributeValue.builder().n("123").build();
AttributeValueCoder coder = AttributeValueCoder.of();
ByteArrayOutputStream output = new ByteArrayOutputStream();
coder.encode(expected, output);
ByteArrayInputStream in = new ByteArrayInputStream(output.toByteArray());
AttributeValue actual = coder.decode(in);
Assert.assertEquals(expected, actual);
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class DynamoDBAsyncGetItem method getItem.
// snippet-start:[dynamoasyc.java2.get_item.main]
public static void getItem(DynamoDbAsyncClient client, String tableName, String key, String keyVal) {
HashMap<String, AttributeValue> keyToGet = new HashMap<String, AttributeValue>();
keyToGet.put(key, AttributeValue.builder().s(keyVal).build());
try {
// Create a GetItemRequest instance
GetItemRequest request = GetItemRequest.builder().key(keyToGet).tableName(tableName).build();
// Invoke the DynamoDbAsyncClient object's getItem
java.util.Collection<AttributeValue> returnedItem = client.getItem(request).join().item().values();
// Convert Set to Map
Map<String, AttributeValue> map = returnedItem.stream().collect(Collectors.toMap(AttributeValue::s, s -> s));
Set<String> keys = map.keySet();
for (String sinKey : keys) {
System.out.format("%s: %s\n", sinKey, map.get(sinKey).toString());
}
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
// snippet-end:[dynamoasyc.java2.get_item.main]
}
use of software.amazon.awssdk.services.dynamodb.model.AttributeValue in project aws-doc-sdk-examples by awsdocs.
the class EnhancedQueryRecordsWithSortKey method queryTableSort.
// snippet-start:[dynamodb.java2.mapping.querykey.main]
public static void queryTableSort(DynamoDbEnhancedClient enhancedClient) {
try {
// Create a DynamoDbTable object based on Issues.
DynamoDbTable<Issues> table = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class));
String dateVal = "2013-11-19";
DynamoDbIndex<Issues> secIndex = enhancedClient.table("Issues", TableSchema.fromBean(Issues.class)).index("dueDateIndex");
AttributeValue attVal = AttributeValue.builder().s(dateVal).build();
// Create a QueryConditional object that's used in the query operation.
QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue(attVal).build());
// Get items in the Issues table.
SdkIterable<Page<Issues>> results = secIndex.query(QueryEnhancedRequest.builder().queryConditional(queryConditional).build());
AtomicInteger atomicInteger = new AtomicInteger();
atomicInteger.set(0);
results.forEach(page -> {
Issues issue = (Issues) page.items().get(atomicInteger.get());
System.out.println("The issue title is " + issue.getTitle());
atomicInteger.incrementAndGet();
});
} catch (DynamoDbException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done");
}
Aggregations