Java Code Examples for com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression#addFilterCondition()

The following examples show how to use com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression#addFilterCondition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
@Test(enabled = false)
public void testParallelScanPerformance() throws Exception{
    DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withLimit(SCAN_LIMIT);
    scanExpression.addFilterCondition("value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    scanExpression.addFilterCondition("extraData", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));

    long startTime = System.currentTimeMillis();
    PaginatedScanList<SimpleClass> scanList = util.scan(SimpleClass.class, scanExpression);
    scanList.loadAllResults();
    long fullTableScanTime = System.currentTimeMillis() - startTime;
    startTime = System.currentTimeMillis();
    PaginatedParallelScanList<SimpleClass> parallelScanList = util.parallelScan(SimpleClass.class, scanExpression, PARALLEL_SCAN_SEGMENTS);
    parallelScanList.loadAllResults();
    long parallelScanTime = System.currentTimeMillis() - startTime;
    assertTrue(scanList.size() == parallelScanList.size());
    assertTrue(fullTableScanTime > parallelScanTime);
    System.out.println("fullTableScanTime : " + fullTableScanTime + "(ms), parallelScanTime : " + parallelScanTime + "(ms).");
}
 
Example 2
Source File: MapperLoadingStrategyConfigITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
private static PaginatedList<RangeKeyTestClass> getTestPaginatedScanList(PaginationLoadingStrategy paginationLoadingStrategy) {
    DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig);
    
    // Construct the scan expression with the exact same conditions
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("key", 
            new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(
                    new AttributeValue().withN(Long.toString(hashKey))));
    scanExpression.addFilterCondition("rangeKey", 
            new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(
                    new AttributeValue().withN("1.0")));
    scanExpression.setLimit(PAGE_SIZE);
    
    return mapper.scan(RangeKeyTestClass.class, scanExpression, new DynamoDBMapperConfig(paginationLoadingStrategy));
}
 
Example 3
Source File: MapperLoadingStrategyConfigITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 6 votes vote down vote up
private static PaginatedList<RangeKeyTestClass> getTestPaginatedParallelScanList(PaginationLoadingStrategy paginationLoadingStrategy) {
    DynamoDBMapperConfig mapperConfig = new DynamoDBMapperConfig(ConsistentReads.CONSISTENT);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamo, mapperConfig);
    
    // Construct the scan expression with the exact same conditions
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("key", 
            new Condition().withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(
                    new AttributeValue().withN(Long.toString(hashKey))));
    scanExpression.addFilterCondition("rangeKey", 
            new Condition().withComparisonOperator(ComparisonOperator.GT).withAttributeValueList(
                    new AttributeValue().withN("1.0")));
    scanExpression.setLimit(PAGE_SIZE);
    
    return mapper.parallelScan(RangeKeyTestClass.class, scanExpression, PARALLEL_SEGMENT, new DynamoDBMapperConfig(paginationLoadingStrategy));
}
 
Example 4
Source File: DynamoDBEntityWithHashKeyOnlyCriteria.java    From spring-data-dynamodb with Apache License 2.0 6 votes vote down vote up
public DynamoDBScanExpression buildScanExpression() {

		if (sort != null) {
			throw new UnsupportedOperationException("Sort not supported for scan expressions");
		}

		DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
		if (isHashKeySpecified()) {
			scanExpression.addFilterCondition(
					getHashKeyAttributeName(),
					createSingleValueCondition(getHashKeyPropertyName(), ComparisonOperator.EQ, getHashKeyAttributeValue(),
							getHashKeyAttributeValue().getClass(), true));
		}

		for (Map.Entry<String, List<Condition>> conditionEntry : attributeConditions.entrySet()) {
			for (Condition condition : conditionEntry.getValue()) {
				scanExpression.addFilterCondition(conditionEntry.getKey(), condition);
			}
		}
		return scanExpression;
	}
 
Example 5
Source File: DynamoDBEntityWithHashAndRangeKeyCriteria.java    From spring-data-dynamodb with Apache License 2.0 6 votes vote down vote up
public DynamoDBScanExpression buildScanExpression() {

		if (sort != null) {
			throw new UnsupportedOperationException("Sort not supported for scan expressions");
		}
		DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
		if (isHashKeySpecified()) {
			scanExpression.addFilterCondition(
					getHashKeyAttributeName(),
					createSingleValueCondition(getHashKeyPropertyName(), ComparisonOperator.EQ, getHashKeyAttributeValue(),
							getHashKeyAttributeValue().getClass(), true));
		}
		if (isRangeKeySpecified()) {
			scanExpression.addFilterCondition(
					getRangeKeyAttributeName(),
					createSingleValueCondition(getRangeKeyPropertyName(), ComparisonOperator.EQ, getRangeKeyAttributeValue(),
							getRangeKeyAttributeValue().getClass(), true));
		}
		for (Map.Entry<String, List<Condition>> conditionEntry : attributeConditions.entrySet()) {
			for (Condition condition : conditionEntry.getValue()) {
				scanExpression.addFilterCondition(conditionEntry.getKey(), condition);
			}
		}
		return scanExpression;
	}
 
Example 6
Source File: ObjectPersistenceQueryScanExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
private static void FindBooksPricedLessThanSpecifiedValue(
        DynamoDBMapper mapper,
        String value) throws Exception {
 
    System.out.println("FindBooksPricedLessThanSpecifiedValue: Scan ProductCatalog.");
            
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("Price", 
            new Condition()
               .withComparisonOperator(ComparisonOperator.LT)
               .withAttributeValueList(new AttributeValue().withN(value)));
    scanExpression.addFilterCondition("ProductCategory", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("Book")));
    List<Book> scanResult = mapper.scan(Book.class, scanExpression);
    
    for (Book book : scanResult) {
        System.out.println(book);
    }
}
 
Example 7
Source File: ObjectPersistenceQueryScanExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
private static void FindBicyclesOfSpecificTypeWithMultipleThreads(
        DynamoDBMapper mapper, 
        int numberOfThreads,
        String bicycleType) throws Exception {
 
    System.out.println("FindBicyclesOfSpecificTypeWithMultipleThreads: Scan ProductCatalog With Multiple Threads.");
            
    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
    scanExpression.addFilterCondition("ProductCategory", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS("Bicycle")));
    scanExpression.addFilterCondition("BicycleType", 
            new Condition()
                .withComparisonOperator(ComparisonOperator.EQ)
                .withAttributeValueList(new AttributeValue().withS(bicycleType)));
    List<Bicycle> scanResult = mapper.parallelScan(Bicycle.class, scanExpression, numberOfThreads);
    for (Bicycle bicycle : scanResult) {
        System.out.println(bicycle);
    }
}
 
Example 8
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testScan() throws Exception {
    DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withLimit(SCAN_LIMIT);
    scanExpression.addFilterCondition("value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    scanExpression.addFilterCondition("extraData", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    List<SimpleClass> list = util.scan(SimpleClass.class, scanExpression);

    int count = 0;
    Iterator<SimpleClass> iterator = list.iterator();
    while (iterator.hasNext()) {
        count++;
        SimpleClass next = iterator.next();
        assertNotNull(next.getExtraData());
        assertNotNull(next.getValue());
    }

    int totalCount = util.count(SimpleClass.class, scanExpression);

    assertNotNull(list.get(totalCount / 2));
    assertTrue(totalCount == count);
    assertTrue(totalCount == list.size());

    assertTrue(list.contains(list.get(list.size() / 2)));
    assertTrue(count == list.toArray().length);
}
 
Example 9
Source File: ScanITCase.java    From aws-dynamodb-encryption-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelScan() throws Exception {
    DynamoDBMapper util = TestDynamoDBMapperFactory.createDynamoDBMapper(dynamo);

    DynamoDBScanExpression scanExpression = new DynamoDBScanExpression().withLimit(SCAN_LIMIT);
    scanExpression.addFilterCondition("value", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));
    scanExpression.addFilterCondition("extraData", new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL.toString()));

    PaginatedParallelScanList<SimpleClass> parallelScanList = util.parallelScan(SimpleClass.class, scanExpression, PARALLEL_SCAN_SEGMENTS);
    int count = 0;
    Iterator<SimpleClass> iterator = parallelScanList.iterator();
    HashMap<String, Boolean> allDataAppearance = new HashMap<String, Boolean>();
    for (int i=0;i<500;i++) {
        allDataAppearance.put("" + i, false);
    }
    while (iterator.hasNext()) {
        count++;
        SimpleClass next = iterator.next();
        assertNotNull(next.getExtraData());
        assertNotNull(next.getValue());
        allDataAppearance.put(next.getId(), true);
    }
    assertFalse(allDataAppearance.values().contains(false));

    int totalCount = util.count(SimpleClass.class, scanExpression);

    assertNotNull(parallelScanList.get(totalCount / 2));
    assertTrue(totalCount == count);
    assertTrue(totalCount == parallelScanList.size());

    assertTrue(parallelScanList.contains(parallelScanList.get(parallelScanList.size() / 2)));
    assertTrue(count == parallelScanList.toArray().length);

}