Java Code Examples for com.amazonaws.services.dynamodbv2.document.Table#scan()

The following examples show how to use com.amazonaws.services.dynamodbv2.document.Table#scan() . 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: TryDaxTests.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
void scanTest(String tableName, DynamoDB client, int iterations) {
    long startTime, endTime;
    System.out.println("Scan test - all items in the table");
    Table table = client.getTable(tableName);

    for (int i = 0; i < iterations; i++) {
        startTime = System.nanoTime();
        ItemCollection<ScanOutcome> items = table.scan();
        try {

            Iterator<Item> iter = items.iterator();
            while (iter.hasNext()) {
                iter.next();
            }
        } catch (Exception e) {
            System.err.println("Unable to scan table:");
            e.printStackTrace();
        }
        endTime = System.nanoTime();
        printTime(startTime, endTime, iterations);
    }
}
 
Example 2
Source File: DocumentAPIScan.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void findProductsForPriceLessThanOneHundred() {

        Table table = dynamoDB.getTable(tableName);

        Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
        expressionAttributeValues.put(":pr", 100);

        ItemCollection<ScanOutcome> items = table.scan("Price < :pr", // FilterExpression
            "Id, Title, ProductCategory, Price", // ProjectionExpression
            null, // ExpressionAttributeNames - not used in this example
            expressionAttributeValues);

        System.out.println("Scan of " + tableName + " for items with a price less than 100.");
        Iterator<Item> iterator = items.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toJSONPretty());
        }
    }
 
Example 3
Source File: MoviesScan.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        AmazonDynamoDBClient client = new AmazonDynamoDBClient();
        client.setEndpoint("http://localhost:8000");
        DynamoDB dynamoDB = new DynamoDB(client);
   
        Table table = dynamoDB.getTable("Movies");
        
        ScanSpec scanSpec = new ScanSpec()
            .withProjectionExpression("#yr, title, info.rating")
            .withFilterExpression("#yr between :start_yr and :end_yr")
            .withNameMap(new NameMap().with("#yr",  "year"))
            .withValueMap(new ValueMap().withNumber(":start_yr", 1950).withNumber(":end_yr", 1959));
        
        ItemCollection<ScanOutcome> items = table.scan(scanSpec);
        
        Iterator<Item> iter = items.iterator();
        while (iter.hasNext()) {
            Item item = iter.next();
            System.out.println(item.toString());
        }
    }
 
Example 4
Source File: DocumentAPIScan.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
private static void findProductsForPriceLessThanZero() {
    
    Table table = dynamoDB.getTable(tableName);
       
    Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
    expressionAttributeValues.put(":pr", 100);
    
    ItemCollection<ScanOutcome> items = table.scan(
        "Price < :pr", //FilterExpression
        "Id, Title, ProductCategory, Price", //ProjectionExpression
        null, //ExpressionAttributeNames - not used in this example 
        expressionAttributeValues);
    
    System.out.println("Scan of " + tableName + " for items with a price less than 100.");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }    
}
 
Example 5
Source File: DynamoDBInstalledAppContextStore.java    From smartapp-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<DefaultInstalledAppContext> get() {
    Table table = dynamoDB.getTable(tableName);
    ItemCollection<ScanOutcome> scanItems = table.scan();
    Iterator<Item> iter = scanItems.iterator();
    Iterable<Item> iterable = () -> iter;
    return StreamSupport.stream(iterable.spliterator(), false)
        .map(item -> refreshed(contextFromItem(item)));
}
 
Example 6
Source File: DynamoDBServiceImpl1.java    From Serverless-Programming-Cookbook with MIT License 5 votes vote down vote up
@Override
public final Response scan(final Request request) {
    final Table table = dynamoDB.getTable(request.getTableName());

    final String projectionExpression = request.getPartitionKey() + " , " + request.getSortKey();
    final ScanSpec scanSpec = new ScanSpec()
            .withProjectionExpression(projectionExpression);

    StringBuilder filterExpressionBuilder;
    Map<String, Object> valueMap;
    if (request.getFilterData() != null) {
        filterExpressionBuilder = new StringBuilder();
        valueMap = new HashMap<>();
        processFilterData(request, filterExpressionBuilder, valueMap);
        // Add to ScanSpec.
        scanSpec.withFilterExpression(filterExpressionBuilder.toString());
        scanSpec.withValueMap(valueMap);
    }

    ItemCollection<ScanOutcome> scanItems = table.scan(scanSpec);

    final StringBuilder response = new StringBuilder();
    response.append("PK of items read with scan (V1): ");
    for (Item item : scanItems) {
        response.append(prepareKeyStr(item, request));
    }

    return new Response(response.toString(), null);
}
 
Example 7
Source File: MoviesScan.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2"))
            .build();

        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable("Movies");

        ScanSpec scanSpec = new ScanSpec().withProjectionExpression("#yr, title, info.rating")
            .withFilterExpression("#yr between :start_yr and :end_yr").withNameMap(new NameMap().with("#yr", "year"))
            .withValueMap(new ValueMap().withNumber(":start_yr", 1950).withNumber(":end_yr", 1959));

        try {
            ItemCollection<ScanOutcome> items = table.scan(scanSpec);

            Iterator<Item> iter = items.iterator();
            while (iter.hasNext()) {
                Item item = iter.next();
                System.out.println(item.toString());
            }

        }
        catch (Exception e) {
            System.err.println("Unable to scan the table:");
            System.err.println(e.getMessage());
        }
    }
 
Example 8
Source File: DocumentAPIParallelScan.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    System.out.println("Scanning " + tableName + " segment " + segment + " out of " + totalSegments
        + " segments " + itemLimit + " items at a time...");
    int totalScannedItemCount = 0;

    Table table = dynamoDB.getTable(tableName);

    try {
        ScanSpec spec = new ScanSpec().withMaxResultSize(itemLimit).withTotalSegments(totalSegments)
            .withSegment(segment);

        ItemCollection<ScanOutcome> items = table.scan(spec);
        Iterator<Item> iterator = items.iterator();

        Item currentItem = null;
        while (iterator.hasNext()) {
            totalScannedItemCount++;
            currentItem = iterator.next();
            System.out.println(currentItem.toString());
        }

    }
    catch (Exception e) {
        System.err.println(e.getMessage());
    }
    finally {
        System.out.println("Scanned " + totalScannedItemCount + " items from segment " + segment + " out of "
            + totalSegments + " of " + tableName);
    }
}
 
Example 9
Source File: DocumentAPIParallelScan.java    From aws-dynamodb-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    System.out.println("Scanning " + tableName + " segment " + segment + " out of " + totalSegments + " segments " + itemLimit + " items at a time...");
    int totalScannedItemCount = 0;

    Table table = dynamoDB.getTable(tableName);
    
    try {
        ScanSpec spec = new ScanSpec()
            .withMaxResultSize(itemLimit)
            .withTotalSegments(totalSegments)
            .withSegment(segment);
        
        ItemCollection<ScanOutcome> items = table.scan(spec);
        Iterator<Item> iterator = items.iterator();
          
        Item currentItem = null;
        while (iterator.hasNext()) {
            totalScannedItemCount++;
            currentItem = iterator.next();
            System.out.println(currentItem.toString());
        }    
            
    } catch (Exception e) {
        System.err.println(e.getMessage());
    } finally {
        System.out.println("Scanned " + totalScannedItemCount 
            + " items from segment " + segment + " out of " 
            + totalSegments + " of " + tableName);
    }
}