本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.ScanResult.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java ScanResult.getItems方法的具体用法?Java ScanResult.getItems怎么用?Java ScanResult.getItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.ScanResult
的用法示例。
在下文中一共展示了ScanResult.getItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpTables
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
private void dumpTables() {
for (String table : client.listTables().getTableNames()) {
ScanResult scanResult;
Map<String, AttributeValue> lastKey = null;
do {
scanResult = client.scan(new ScanRequest().withTableName(table).withExclusiveStartKey(lastKey));
lastKey = scanResult.getLastEvaluatedKey();
for (Map<String, AttributeValue> map : scanResult.getItems()) {
for (Map.Entry<String, AttributeValue> item : map.entrySet()) {
System.out.print("item.put(\"");
System.out.print(item.getKey());
System.out.print("\", b642Av(\"");
System.out.print(Base64.encodeAsString(AttributeValueMarshaller.marshall(item.getValue()).array()));
System.out.println("\"));");
}
System.out.print("ddb.putItem(new PutItemRequest(\"");
System.out.print(table);
System.out.println("\", item));");
System.out.println("item.clear();");
System.out.println();
}
} while (lastKey != null);
}
}
示例2: fetchPage
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@Override
protected PageResults<Map<String, AttributeValue>> fetchPage(RequestLimit lim) {
// Read from DynamoDB
RetryResult<ScanResult> retryResult = context.getClient().scanTable(tableName, null, segment,
context.getSplit().getTotalSegments(), lastEvaluatedKey, lim.items, context.getReporter());
ScanResult result = retryResult.result;
int retries = retryResult.retries;
double consumedCapacityUnits = 0.0;
if (result.getConsumedCapacity() != null) {
consumedCapacityUnits = result.getConsumedCapacity().getCapacityUnits();
}
return new PageResults<>(result.getItems(), result.getLastEvaluatedKey(), consumedCapacityUnits,
retries);
}
示例3: listUsers
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* Returns the list of usernames stored in the identity table.
*
* @return list of existing usernames in DynamoDB table
*/
public List<String> listUsers() {
List<String> users = new ArrayList<String>(1000);
ScanResult result = ddb.scan(new ScanRequest().withTableName(USER_TABLE).withLimit(1000));
for (Map<String, AttributeValue> item : result.getItems()) {
String s = "";
for (Entry<String, AttributeValue> entry : item.entrySet()) {
s += " ** " + entry.getKey() + " = " + entry.getValue().getS();
}
users.add(s);
}
return users;
}
开发者ID:awslabs,项目名称:amazon-cognito-developer-authentication-sample,代码行数:23,代码来源:UserAuthentication.java
示例4: listDevices
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* @return the list of device ID (UID) stored in the identity table.
*/
public List<String> listDevices() {
List<String> devices = new ArrayList<String>(1000);
ScanResult result = ddb.scan(new ScanRequest().withTableName(DEVICE_TABLE).withLimit(1000));
for (Map<String, AttributeValue> item : result.getItems()) {
String s = "";
for (Entry<String, AttributeValue> entry : item.entrySet()) {
s += " ** " + entry.getKey() + " = " + entry.getValue().getS();
}
devices.add(s);
}
return devices;
}
开发者ID:awslabs,项目名称:amazon-cognito-developer-authentication-sample,代码行数:21,代码来源:DeviceAuthentication.java
示例5: getDictionaryEntry
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* Generate a list of attribute names found in the Aggregator's dynamo
* table. Assumes that all Items in the Aggregator table are of the same
* structure.
*
* @param dynamoClient
* Dynamo DB Client to use for connection to Dynamo DB.
* @param dynamoTable
* The Dynamo Table for the Aggregator
* @return A list of attribute names from the Dynamo table
* @throws Exception
*/
public static List<String> getDictionaryEntry(
final AmazonDynamoDB dynamoClient, final String dynamoTable)
throws Exception {
// get a list of all columns in the table, with keys first
List<String> columns = new ArrayList<>();
List<KeySchemaElement> keys = dynamoClient.describeTable(dynamoTable)
.getTable().getKeySchema();
for (KeySchemaElement key : keys) {
columns.add(key.getAttributeName());
}
ScanResult scan = dynamoClient.scan(new ScanRequest()
.withTableName(dynamoTable).withSelect(Select.ALL_ATTRIBUTES)
.withLimit(1));
List<Map<String, AttributeValue>> scannedItems = scan.getItems();
for (Map<String, AttributeValue> map : scannedItems) {
for (String s : map.keySet()) {
if (!columns.contains(s))
columns.add(s);
}
}
return columns;
}
示例6: getDictionaryEntry
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* Generate a list of attribute names found in the Aggregator's dynamo
* table. Assumes that all Items in the Aggregator table are of the same
* structure.
*
* @param dynamoClient Dynamo DB Client to use for connection to Dynamo DB.
* @param dynamoTable The Dynamo Table for the Aggregator
* @return A list of attribute names from the Dynamo table
* @throws Exception
*/
protected List<String> getDictionaryEntry() throws Exception {
// get a list of all columns in the table, with keys first
List<String> columns = new ArrayList<>();
List<KeySchemaElement> keys = dynamoClient.describeTable(this.tableName).getTable().getKeySchema();
for (KeySchemaElement key : keys) {
columns.add(key.getAttributeName());
}
ScanResult scan = dynamoClient.scan(new ScanRequest().withTableName(this.tableName).withSelect(
Select.ALL_ATTRIBUTES).withLimit(1));
List<Map<String, AttributeValue>> scannedItems = scan.getItems();
for (Map<String, AttributeValue> map : scannedItems) {
for (String s : map.keySet()) {
if (!columns.contains(s))
columns.add(s);
}
}
return columns;
}
示例7: findProductsForPriceLessThanZero
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
private static void findProductsForPriceLessThanZero() {
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":pr", new AttributeValue().withN("100"));
ScanRequest scanRequest = new ScanRequest()
.withTableName(tableName)
.withFilterExpression("Price < :pr")
.withExpressionAttributeValues(expressionAttributeValues)
.withProjectionExpression("Id, Title, ProductCategory, Price");
ScanResult result = client.scan(scanRequest);
System.out.println("Scan of " + tableName + " for items with a price less than 100.");
for (Map<String, AttributeValue> item : result.getItems()) {
System.out.println("");
printItem(item);
}
}
示例8: handleRequest
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@Override
public String handleRequest(Book request, Context context) {
ScanRequest scanRequest = new ScanRequest().withTableName("Books");
ScanResult result = DynamoDBUtil.getClient().scan(scanRequest);
System.out.println("-- books listing start --");
for (Map<String, AttributeValue> item : result.getItems()){
System.out.println(item);
}
System.out.println("-- books listing end --");
return result.getItems().toString();
}
示例9: call
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@Override
public Void call() {
final ScanResult scanResult = result.getScanResult();
final List<Map<String, AttributeValue>> items = scanResult.getItems();
final Iterator<Map<String, AttributeValue>> it = items.iterator();
boolean interrupted = false;
try {
do {
try {
Map<String, AttributeValue> item = it.next();
DynamoDBEntryWithSize entryWithSize = new DynamoDBEntryWithSize(
item,
ItemSizeCalculator.calculateItemSizeInBytes(item));
queue.put(entryWithSize);
} catch (InterruptedException e) {
interrupted = true;
LOGGER.warn("interrupted when writing item to queue: "
+ e.getMessage());
}
} while (it.hasNext());
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
return null;
}
示例10: run
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@Override
public void run() {
Map<String, AttributeValue> exclusiveStartKey = null;
ScanRequest scanRequest = new ScanRequest().withTableName(tableName).withAttributesToGet(attributesToGet)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withTotalSegments(numOfSegments).withSegment(segmentNum);
boolean scanNumLimitReached = false;
while (!scanNumLimitReached) {
scanRequest.withExclusiveStartKey(exclusiveStartKey);
ScanResult scanResult = dynamoDBClient.scan(scanRequest);
if(!isRunningOnDDBLocal) {
// DDB Local does not support rate limiting
tableReadRateLimiter.adjustRateWithConsumedCapacity(scanResult.getConsumedCapacity());
}
for (Map<String, AttributeValue> item : scanResult.getItems()) {
checkItemViolationAndAddDeleteRequest(item);
itemsScanned.addAndGet(1);
itemScannedByThread += 1;
scanNumLimitReached = isScanNumberLimitReached();
if(scanNumLimitReached) {
break;
}
}
if (deleteViolationAfterFound) {
sendDeleteViolations();
}
PrintHelper.printScanProgress(itemsScanned.get(), itemScannedByThread, violationFoundByThread, violationDeleteByThread);
if (null == (exclusiveStartKey = scanResult.getLastEvaluatedKey())) {
break;
}
}
return;
}
示例11: getItem
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@Override
public List<Map<String, AttributeValue>> getItem(String tableName, Map<String, Condition> conditions) {
ScanRequest scanRequest = new ScanRequest(tableName).withScanFilter(conditions);
ScanResult scanResult = dynamoDBClient.scan(scanRequest);
int count = scanResult.getCount();
if (count == 0) {
return Collections.emptyList();
}
LOG.info("Successful by getting items from " + tableName
+ " based on conditions: " + conditions.toString() + ": " + count + " items");
return scanResult.getItems();
}
示例12: scanTable
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* Returns the the result of the scanned table with the applied filters. The
* filters are connected via the conditionalOperator. It can either be AND
* or OR.
*
* @param tableName
* The table to be scanned.
* @param filters
* A list with Filter objects.
* @param conditionalOperator
* AND | OR - Conditional clauses in DynamoDb can either have AND
* or OR connectors, no mix.
* @return
*/
public static List<Row> scanTable(String tableName, Filter[] filters,
String conditionalOperator) {
Map<String, Condition> scanFilter = new HashMap<>();
for (Filter filter : filters) {
scanFilter.put(
filter.getAttribute().getName(),
new Condition().withComparisonOperator(
filter.getComparisonOperator())
.withAttributeValueList(
new AttributeValue().withS(filter
.getAttribute().getValue())));
}
ScanResult scanResult;
if (filters.length == 1) {
scanResult = DynamoDbHandler.CLIENT.scan(new ScanRequest(tableName)
.withScanFilter(scanFilter));
} else {
scanResult = DynamoDbHandler.CLIENT.scan(new ScanRequest(tableName)
.withConditionalOperator(conditionalOperator)
.withScanFilter(scanFilter));
}
ArrayList<Row> items = new ArrayList<>();
List<Attribute> attributes = null;
for (Map<String, AttributeValue> result : scanResult.getItems()) {
attributes = new ArrayList<>();
for (String key : result.keySet()) {
attributes.add(new Attribute(key, result.get(key).getS()));
}
items.add(new Row(attributes));
}
return items;
}
示例13: readPageFromTable
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
/**
* Reads a page from a standard DynamoDB table.
* @param <P> type of object
* @param appid the app identifier (name)
* @param p a {@link Pager}
* @return the last row key of the page, or null.
*/
public static <P extends ParaObject> List<P> readPageFromTable(String appid, Pager p) {
Pager pager = (p != null) ? p : new Pager();
ScanRequest scanRequest = new ScanRequest().
withTableName(getTableNameForAppid(appid)).
withLimit(pager.getLimit()).
withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
if (!StringUtils.isBlank(pager.getLastKey())) {
scanRequest = scanRequest.withExclusiveStartKey(Collections.
singletonMap(Config._KEY, new AttributeValue(pager.getLastKey())));
}
ScanResult result = getClient().scan(scanRequest);
LinkedList<P> results = new LinkedList<>();
for (Map<String, AttributeValue> item : result.getItems()) {
P obj = fromRow(item);
if (obj != null) {
results.add(obj);
}
}
if (result.getLastEvaluatedKey() != null) {
pager.setLastKey(result.getLastEvaluatedKey().get(Config._KEY).getS());
} else if (!results.isEmpty()) {
// set last key to be equal to the last result - end reached.
pager.setLastKey(results.peekLast().getId());
}
return results;
}
示例14: getRows
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@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));
}
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;
}
示例15: getRows
import com.amazonaws.services.dynamodbv2.model.ScanResult; //导入方法依赖的package包/类
@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 {
// 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;
}