Search in sources :

Example 21 with QuerySpec

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());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 22 with QuerySpec

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);
    }
}
Also used : ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) AmazonServiceException(com.amazonaws.AmazonServiceException) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) IOException(java.io.IOException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 23 with QuerySpec

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<>();
}
Also used : ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 24 with QuerySpec

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;
}
Also used : BaseOpDispenser(io.nosqlbench.engine.api.activityimpl.BaseOpDispenser) LongFunction(java.util.function.LongFunction) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) Map(java.util.Map) ParsedOp(io.nosqlbench.engine.api.templating.ParsedOp) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Optional(java.util.Optional) Table(com.amazonaws.services.dynamodbv2.document.Table) DDBQueryOp(io.nosqlbench.adapter.dynamodb.optypes.DDBQueryOp) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) DynamoDBOp(io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp) PrimaryKey(com.amazonaws.services.dynamodbv2.document.PrimaryKey) LongFunction(java.util.function.LongFunction) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Map(java.util.Map)

Example 25 with QuerySpec

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);
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) DDBQueryOp(io.nosqlbench.adapter.dynamodb.optypes.DDBQueryOp) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Aggregations

QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)26 Item (com.amazonaws.services.dynamodbv2.document.Item)17 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)17 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)15 Table (com.amazonaws.services.dynamodbv2.document.Table)12 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)6 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)4 Index (com.amazonaws.services.dynamodbv2.document.Index)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)2 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)2 DDBQueryOp (io.nosqlbench.adapter.dynamodb.optypes.DDBQueryOp)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ForwardCursorPagedResourceList (org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList)2 Upload (org.sagebionetworks.bridge.models.upload.Upload)2 Test (org.testng.annotations.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1