List of usage examples for com.amazonaws.services.dynamodbv2.model ScanRequest setAttributesToGet
public void setAttributesToGet(java.util.Collection<String> attributesToGet)
This is a legacy parameter.
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 ww w . j av a 2s . c o 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 ww . java 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.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 w w . ja va 2 s .c o m 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);//from ww w. j a va 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())); }
From source file:org.apache.metamodel.dynamodb.DynamoDbDataContext.java
License:Apache License
@Override protected DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { final List<String> attributeNames = columns.stream().map(col -> col.getName()).collect(Collectors.toList()); final ScanRequest scanRequest = new ScanRequest(table.getName()); scanRequest.setAttributesToGet(attributeNames); if (maxRows > 0) { scanRequest.setLimit(maxRows);// ww w.j a v a2 s . c o m } final ScanResult result = _dynamoDb.scan(scanRequest); return new DynamoDbDataSet(columns, result); }