Example usage for com.amazonaws.services.dynamodbv2.model ScanRequest setExclusiveStartKey

List of usage examples for com.amazonaws.services.dynamodbv2.model ScanRequest setExclusiveStartKey

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model ScanRequest setExclusiveStartKey.

Prototype


public void setExclusiveStartKey(java.util.Map<String, AttributeValue> exclusiveStartKey) 

Source Link

Document

The primary key of the first item that this operation will evaluate.

Usage

From source file:com.dell.doradus.db.dynamodb.DDBRowIterator.java

License:Apache License

/**
 * Create a row iterator that returns all columns and rows for the given table. A scan
 * request is performed repeatedly until all rows are captured.
 * /*from  w  w  w. j  a v a  2s .  c om*/
 * @param ddbClient Client for accessing DynamoDB API. 
 * @param tableName Name for which to get all rows.
 */
public DDBRowIterator(String tableName) {
    // Use a scan request.
    ScanRequest scanRequest = new ScanRequest(tableName);
    while (true) {
        ScanResult scanResult = DynamoDBService.instance().scan(scanRequest);
        List<Map<String, AttributeValue>> itemList = scanResult.getItems();
        if (itemList.size() == 0) {
            break;
        }
        for (Map<String, AttributeValue> attributeMap : itemList) {
            AttributeValue rowAttr = attributeMap.get(DynamoDBService.ROW_KEY_ATTR_NAME);
            m_rowList.add(new DDBRow(rowAttr.getS(), new DDBColumnIterator(attributeMap)));
        }
        Map<String, AttributeValue> lastEvaluatedKey = scanResult.getLastEvaluatedKey();
        if (lastEvaluatedKey == null) {
            break;
        }
        scanRequest.setExclusiveStartKey(lastEvaluatedKey);
    }
}

From source file:com.dell.doradus.db.dynamodb.DynamoDBService.java

License:Apache License

@Override
public List<String> getRows(String storeName, String continuationToken, int count) {
    String tableName = storeToTableName(storeName);
    ScanRequest scanRequest = new ScanRequest(tableName);
    scanRequest.setAttributesToGet(Arrays.asList(ROW_KEY_ATTR_NAME)); // attributes to get
    if (continuationToken != null) {
        scanRequest.setExclusiveStartKey(makeDDBKey(continuationToken));
    }//from w w w.ja  va 2s. co  m
    List<String> rowKeys = new ArrayList<>();
    while (rowKeys.size() < count) {
        ScanResult scanResult = scan(scanRequest);
        List<Map<String, AttributeValue>> itemList = scanResult.getItems();
        if (itemList.size() == 0) {
            break;
        }
        for (Map<String, AttributeValue> attributeMap : itemList) {
            AttributeValue rowAttr = attributeMap.get(ROW_KEY_ATTR_NAME);
            rowKeys.add(rowAttr.getS());
            if (rowKeys.size() >= count) {
                break;
            }
        }
        Map<String, AttributeValue> lastEvaluatedKey = scanResult.getLastEvaluatedKey();
        if (lastEvaluatedKey == null) {
            break;
        }
        scanRequest.setExclusiveStartKey(lastEvaluatedKey);
    }
    return rowKeys;
}

From source file:com.dell.doradus.db.s3.DynamoDBService2.java

License:Apache License

@Override
public List<String> getRows(String storeName, String continuationToken, int count) {
    Timer t = new Timer();
    ScanRequest scanRequest = new ScanRequest(getTenant().getName());
    scanRequest.setAttributesToGet(Arrays.asList("key")); // attributes to get
    //if (continuationToken != null) {
    //   scanRequest.setExclusiveStartKey(getPrimaryKey(storeName + "_" + continuationToken, "\u007F"));
    //} else {/* w  w w. j  a  v  a  2  s.c  o m*/
    //   scanRequest.setExclusiveStartKey(getPrimaryKey(storeName + "_", "\0"));
    //}

    Set<String> rowKeys = new HashSet<>();
    while (rowKeys.size() < count) {
        ScanResult scanResult = m_client.scan(scanRequest);
        List<Map<String, AttributeValue>> itemList = scanResult.getItems();
        if (itemList.size() == 0)
            break;
        for (Map<String, AttributeValue> attributeMap : itemList) {
            AttributeValue rowAttr = attributeMap.get("key");
            if (!rowAttr.getS().startsWith(storeName))
                continue;
            String name = rowAttr.getS().substring(storeName.length() + 1);
            if (continuationToken != null && continuationToken.compareTo(name) >= 0)
                continue;
            rowKeys.add(name);
        }
        Map<String, AttributeValue> lastEvaluatedKey = scanResult.getLastEvaluatedKey();
        if (lastEvaluatedKey == null)
            break;
        scanRequest.setExclusiveStartKey(getPrimaryKey(lastEvaluatedKey.get("key").getS(), "\u007F"));
    }
    List<String> list = new ArrayList<>(rowKeys);
    Collections.sort(list);
    m_logger.debug("get rows in {} in {}", storeName, t);
    return list;
}

From source file:com.numenta.taurus.service.TaurusClient.java

License:Open Source License

@Override
public List<Metric> getMetrics() throws GrokException, IOException {
    String uid;/*from ww w .j ava2s.c  o  m*/
    String name;
    String server;
    String metricType;
    String metricTypeName;
    String symbol;
    JSONObject parameters;
    ArrayList<Metric> metrics = new ArrayList<>();

    TaurusDataFactory dataFactory = TaurusApplication.getInstance().getDataFactory();

    // Scan all metrics
    ScanRequest request = new ScanRequest().withTableName(METRIC_TABLE).withAttributesToGet("uid", "name",
            "server", "metricType", "metricTypeName", "symbol");
    ScanResult result;
    Map<String, AttributeValue> lastKey;
    try {
        do {
            result = _awsClient.scan(request);
            for (Map<String, AttributeValue> item : result.getItems()) {
                uid = item.get("uid").getS();
                name = item.get("name").getS();
                server = item.get("server").getS();
                metricType = item.get("metricType").getS();
                metricTypeName = item.get("metricTypeName").getS();
                symbol = item.get("symbol").getS();
                // FIXME: TAUR-817: Create taurus specific "metric" table
                parameters = new JSONObject(
                        "{\"metricSpec\":{\"userInfo\": {\"symbol\": \"" + symbol + "\",\"metricType\": \""
                                + metricType + "\",\"metricTypeName\": \"" + metricTypeName + "\"}}}");
                metrics.add(dataFactory.createMetric(uid, name, server, server, 0, parameters));
            }
            // Make sure to get all pages
            lastKey = result.getLastEvaluatedKey();
            request.setExclusiveStartKey(lastKey);
        } while (lastKey != null);
    } catch (JSONException e) {
        throw new GrokException("JSON Parser error", e);
    } catch (AmazonClientException e) {
        // Wraps Amazon's unchecked exception as IOException
        throw new IOException(e);
    }
    return metrics;
}

From source file:com.vitembp.embedded.data.UuidStringStoreDynamoDB.java

License:Open Source License

@Override
public Stream<CaptureDescription> getCaptureLocations() throws IOException {
    List<ScanResult> keys = new ArrayList<>();
    List<String> params = Arrays.asList(new String[] { "LOCATION", "SYSTEM_UUID", "CREATEDTIME", "FREQUENCY" });
    ScanResult res = this.client.scan("CAPTURES", params);
    keys.add(res);//from  w ww. j  a v a2 s .  c om
    Map<String, AttributeValue> lastRes = res.getLastEvaluatedKey();
    while (lastRes != null) {
        ScanRequest sr = new ScanRequest();
        sr.setTableName("CAPTURES");
        sr.setAttributesToGet(params);
        sr.setExclusiveStartKey(lastRes);
        res = this.client.scan(sr);
        keys.add(res);
        lastRes = res.getLastEvaluatedKey();
    }
    // return results as stream of captures
    return res.getItems().stream()
            .map((item) -> new CaptureDescription(UUID.fromString(item.get("LOCATION").getS()),
                    UUID.fromString(item.get("SYSTEM_UUID").getS()),
                    Instant.parse(item.get("CREATEDTIME").getS()),
                    Double.parseDouble(item.get("FREQUENCY").getS())));
}

From source file:com.vitembp.embedded.data.UuidStringStoreDynamoDB.java

License:Open Source License

@Override
public Stream<UUID> getKeys() throws IOException {
    List<ScanResult> keys = new ArrayList<>();
    ScanResult res = this.client.scan("DATA", Arrays.asList(new String[] { "ID" }));
    keys.add(res);//ww  w  .  j a v a 2  s  .co  m
    Map<String, AttributeValue> lastRes = res.getLastEvaluatedKey();
    while (lastRes != null) {
        ScanRequest sr = new ScanRequest();
        sr.setTableName("DATA");
        sr.setAttributesToGet(Arrays.asList(new String[] { "ID" }));
        sr.setExclusiveStartKey(lastRes);
        res = this.client.scan(sr);
        keys.add(res);
        lastRes = res.getLastEvaluatedKey();
    }
    return res.getItems().stream().map((item) -> UUID.fromString(item.get("ID").getS()));
}