Search in sources :

Example 6 with Condition

use of com.amazonaws.services.dynamodbv2.model.Condition in project camel by apache.

the class QueryCommandTest method execute.

@Test
public void execute() {
    Map<String, AttributeValue> startKey = new HashMap<String, AttributeValue>();
    startKey.put("1", new AttributeValue("startKey"));
    List<String> attributeNames = Arrays.asList("attrNameOne", "attrNameTwo");
    exchange.getIn().setHeader(DdbConstants.ATTRIBUTE_NAMES, attributeNames);
    exchange.getIn().setHeader(DdbConstants.CONSISTENT_READ, true);
    exchange.getIn().setHeader(DdbConstants.START_KEY, startKey);
    exchange.getIn().setHeader(DdbConstants.LIMIT, 10);
    exchange.getIn().setHeader(DdbConstants.SCAN_INDEX_FORWARD, true);
    Map<String, Condition> keyConditions = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    keyConditions.put("1", condition);
    exchange.getIn().setHeader(DdbConstants.KEY_CONDITIONS, keyConditions);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    assertEquals(keyConditions, exchange.getIn().getHeader(DdbConstants.KEY_CONDITIONS, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Example 7 with Condition

use of com.amazonaws.services.dynamodbv2.model.Condition in project camel by apache.

the class ScanCommandTest method execute.

@Test
public void execute() {
    Map<String, Condition> scanFilter = new HashMap<String, Condition>();
    Condition condition = new Condition().withComparisonOperator(ComparisonOperator.GT.toString()).withAttributeValueList(new AttributeValue().withN("1985"));
    scanFilter.put("year", condition);
    exchange.getIn().setHeader(DdbConstants.SCAN_FILTER, scanFilter);
    command.execute();
    Map<String, AttributeValue> mapAssert = new HashMap<String, AttributeValue>();
    mapAssert.put("1", new AttributeValue("LAST_KEY"));
    ConsumedCapacity consumed = (ConsumedCapacity) exchange.getIn().getHeader(DdbConstants.CONSUMED_CAPACITY);
    assertEquals(scanFilter, ddbClient.scanRequest.getScanFilter());
    assertEquals(Integer.valueOf(10), exchange.getIn().getHeader(DdbConstants.SCANNED_COUNT, Integer.class));
    assertEquals(Integer.valueOf(1), exchange.getIn().getHeader(DdbConstants.COUNT, Integer.class));
    assertEquals(Double.valueOf(1.0), consumed.getCapacityUnits());
    assertEquals(mapAssert, exchange.getIn().getHeader(DdbConstants.LAST_EVALUATED_KEY, Map.class));
    Map<?, ?> items = (Map<?, ?>) exchange.getIn().getHeader(DdbConstants.ITEMS, List.class).get(0);
    assertEquals(new AttributeValue("attrValue"), items.get("attrName"));
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ConsumedCapacity(com.amazonaws.services.dynamodbv2.model.ConsumedCapacity) Test(org.junit.Test)

Example 8 with Condition

use of com.amazonaws.services.dynamodbv2.model.Condition in project gora by apache.

the class DynamoDBQuery method buildScanExpression.

/**
   * Builds scan query expression using a hash attribute value where to start
   */
public void buildScanExpression() {
    K qKey = getKey();
    if (qKey == null) {
        LOG.warn("No key defined. Trying with startKey.");
        qKey = query.getStartKey();
        if (qKey == null) {
            throw new IllegalStateException("No key has been defined please check");
        }
    }
    ComparisonOperator compOp = getScanCompOp() != null ? getScanCompOp() : DEFAULT_SCAN_OP;
    DynamoDBScanExpression newScanExpression = new DynamoDBScanExpression();
    // hash key condition
    Map<String, AttributeValue> hashAttrVals = buildHashKey(qKey);
    for (Entry<String, AttributeValue> en : hashAttrVals.entrySet()) {
        Condition scanFilterHashCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue());
        newScanExpression.addFilterCondition(en.getKey(), scanFilterHashCondition);
    }
    // range key condition
    Map<String, AttributeValue> rangeAttrVals = buildRangeKey(qKey);
    for (Entry<String, AttributeValue> en : rangeAttrVals.entrySet()) {
        Condition scanFilterRangeCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue());
        newScanExpression.addFilterCondition(en.getKey(), scanFilterRangeCondition);
    }
    dynamoDBExpression = newScanExpression;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ComparisonOperator(com.amazonaws.services.dynamodbv2.model.ComparisonOperator) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)

Example 9 with Condition

use of com.amazonaws.services.dynamodbv2.model.Condition in project gora by apache.

the class DynamoDBQuery method buildRangeExpression.

/**
   * Builds range query expression
   * 
   */
public void buildRangeExpression() {
    DynamoDBScanExpression queryExpression = new DynamoDBScanExpression();
    ComparisonOperator compOp = ComparisonOperator.BETWEEN;
    // hash key range
    Map<String, AttributeValue> hashAttrVals = buildHashKey(query.getStartKey());
    Map<String, AttributeValue> endHashAttrVals = buildHashKey(query.getEndKey());
    for (Entry<String, AttributeValue> en : hashAttrVals.entrySet()) {
        Condition scanFilterHashCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue(), endHashAttrVals.get(en.getKey()));
        queryExpression.addFilterCondition(en.getKey(), scanFilterHashCondition);
    }
    // range key range
    Map<String, AttributeValue> rangeAttrVals = buildRangeKey(query.getStartKey());
    Map<String, AttributeValue> endRangeAttrVals = buildRangeKey(query.getEndKey());
    for (Entry<String, AttributeValue> en : rangeAttrVals.entrySet()) {
        Condition scanFilterRangeCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue(), endRangeAttrVals.get(en.getKey()));
        queryExpression.addFilterCondition(en.getKey(), scanFilterRangeCondition);
    }
    dynamoDBExpression = queryExpression;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ComparisonOperator(com.amazonaws.services.dynamodbv2.model.ComparisonOperator) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)

Aggregations

Condition (com.amazonaws.services.dynamodbv2.model.Condition)6 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)5 DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 ConsumedCapacity (com.amazonaws.services.dynamodbv2.model.ConsumedCapacity)2 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 DescribeStreamRequest (com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)1 DescribeStreamResult (com.amazonaws.services.dynamodbv2.model.DescribeStreamResult)1 GetShardIteratorResult (com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult)1 ListStreamsRequest (com.amazonaws.services.dynamodbv2.model.ListStreamsRequest)1 ListStreamsResult (com.amazonaws.services.dynamodbv2.model.ListStreamsResult)1 Record (com.amazonaws.services.dynamodbv2.model.Record)1 Shard (com.amazonaws.services.dynamodbv2.model.Shard)1 ShardIteratorType (com.amazonaws.services.dynamodbv2.model.ShardIteratorType)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Exchange (org.apache.camel.Exchange)1