use of com.amazonaws.services.dynamodbv2.document.spec.QuerySpec in project aws-doc-sdk-examples by awsdocs.
the class DocumentAPIQuery method findRepliesUsingAFilterExpression.
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {
Table table = dynamoDB.getTable(tableName);
String replyId = forumName + "#" + threadSubject;
QuerySpec spec = new QuerySpec().withProjectionExpression("Message, ReplyDateTime, PostedBy").withKeyConditionExpression("Id = :v_id").withFilterExpression("PostedBy = :v_postedby").withValueMap(new ValueMap().withString(":v_id", replyId).withString(":v_postedby", "User B"));
ItemCollection<QueryOutcome> items = table.query(spec);
System.out.println("\nfindRepliesUsingAFilterExpression results:");
Iterator<Item> iterator = items.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next().toJSONPretty());
}
}
use of com.amazonaws.services.dynamodbv2.document.spec.QuerySpec in project jackrabbit-oak by apache.
the class DynamoDBClient method getDocumentsStream.
public Stream<Item> getDocumentsStream(String fileName) throws IOException {
String FILENAME_KEY = ":v_filename";
QuerySpec spec = new QuerySpec().withScanIndexForward(false).withKeyConditionExpression(TABLE_ATTR_FILENAME + " = " + FILENAME_KEY).withValueMap(new ValueMap().withString(FILENAME_KEY, fileName));
try {
ItemCollection<QueryOutcome> outcome = journalTable.query(spec);
return StreamSupport.stream(outcome.spliterator(), false);
} catch (AmazonServiceException e) {
throw new IOException(e);
}
}
use of com.amazonaws.services.dynamodbv2.document.spec.QuerySpec in project athenz by AthenZ.
the class DynamoDBCertRecordStoreConnection method getUnrefreshedCertRecordsByDate.
private List<Item> getUnrefreshedCertRecordsByDate(String provider, long yesterday, String unrefreshedCertDate) {
try {
QuerySpec spec = new QuerySpec().withKeyConditionExpression("currentDate = :v_current_date").withFilterExpression("provider = :v_provider AND attribute_exists(hostName) AND (attribute_not_exists(lastNotifiedTime) OR lastNotifiedTime < :v_last_notified)").withValueMap(new ValueMap().withString(":v_current_date", unrefreshedCertDate).withNumber(":v_last_notified", yesterday).withString(":v_provider", provider));
ItemCollection<QueryOutcome> outcome = itemCollectionRetryDynamoDBCommand.run(() -> currentTimeIndex.query(spec));
List<Item> items = new ArrayList<>();
for (Item item : outcome) {
items.add(item);
}
return items;
} catch (Exception ex) {
LOGGER.error("DynamoDB getUnrefreshedCertRecordsByDate failed for provider: {}, date: {} error: {}", provider, unrefreshedCertDate, ex.getMessage());
}
return new ArrayList<>();
}
use of com.amazonaws.services.dynamodbv2.document.spec.QuerySpec in project nosqlbench by nosqlbench.
the class DDBQueryOpDispenser method resolveQuerySpecFunc.
private LongFunction<QuerySpec> resolveQuerySpecFunc(ParsedOp cmd) {
LongFunction<QuerySpec> func = l -> new QuerySpec();
Optional<LongFunction<String>> projFunc = cmd.getAsOptionalFunction("projection", String.class);
if (projFunc.isPresent()) {
LongFunction<QuerySpec> finalFunc = func;
LongFunction<String> af = projFunc.get();
func = l -> finalFunc.apply(l).withAttributesToGet(af.apply(l));
}
Optional<LongFunction<Boolean>> consistentRead = cmd.getAsOptionalFunction("ConsistentRead", boolean.class);
if (consistentRead.isPresent()) {
LongFunction<QuerySpec> finalFunc = func;
LongFunction<Boolean> consistentReadFunc = consistentRead.get();
func = l -> finalFunc.apply(l).withConsistentRead(consistentReadFunc.apply(l));
}
Optional<LongFunction<Map>> exclStrtKeyFunc = cmd.getAsOptionalFunction("ExclusiveStartKey", Map.class);
if (exclStrtKeyFunc.isPresent()) {
LongFunction<QuerySpec> finalFunc = func;
LongFunction<Map> skf = exclStrtKeyFunc.get();
LongFunction<PrimaryKey> pkf = l -> {
PrimaryKey pk = new PrimaryKey();
skf.apply(l).forEach((k, v) -> pk.addComponent(k.toString(), v.toString()));
return pk;
};
func = l -> finalFunc.apply(l).withExclusiveStartKey(pkf.apply(l));
}
Optional<LongFunction<Integer>> limitFunc = cmd.getAsOptionalFunction("Limit", Integer.class);
if (limitFunc.isPresent()) {
LongFunction<Integer> limitf = limitFunc.get();
LongFunction<QuerySpec> finalFunc = func;
func = l -> finalFunc.apply(l).withMaxResultSize(limitf.apply(l));
}
return func;
}
use of com.amazonaws.services.dynamodbv2.document.spec.QuerySpec in project nosqlbench by nosqlbench.
the class DDBQueryOpDispenser method apply.
@Override
public DDBQueryOp apply(long cycle) {
Table table = tableFunc.apply(cycle);
QuerySpec queryspec = querySpecFunc.apply(cycle);
return new DDBQueryOp(ddb, table, queryspec);
}
Aggregations