当前位置: 首页>>代码示例>>Java>>正文


Java ScanSpec类代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.document.spec.ScanSpec的典型用法代码示例。如果您正苦于以下问题:Java ScanSpec类的具体用法?Java ScanSpec怎么用?Java ScanSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScanSpec类属于com.amazonaws.services.dynamodbv2.document.spec包,在下文中一共展示了ScanSpec类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
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());
        }
    }
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:23,代码来源:MoviesScan.java

示例2: getAll

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
@Override
public List<T> getAll() {
    //ToDo: implement batching to counter large tables and Dynamo request limits
    return StreamSupport.stream(table.scan(new ScanSpec()).spliterator(), true)
            .map(i -> converter.fromDynamo(i.asMap()))
            .collect(Collectors.toList());
}
 
开发者ID:BackendButters,项目名称:AwsCommons,代码行数:8,代码来源:AbstractDynamoTable.java

示例3: scan

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
private ScanOutcome scan(ScanSpec scanSpec, PageIterator pageIterator) {
    if ( null == _convertMarker ) {
        throw new IllegalStateException("Index must first be initialized with ConvertMarker");
    }
    if ( pageIterator.getPageSize() <= 0 ) {
        return new ScanOutcome(new ScanResult());
    }
    ItemCollection<ScanOutcome> itemCollection =
        maybeBackoff(true, () -> _scan.scan(withMarker(scanSpec, pageIterator)));

    if ( null != itemCollection ) {
        Iterator<Page<Item, ScanOutcome>> iterator = itemCollection.pages().iterator();
        if ( iterator.hasNext() ) {
            ScanOutcome outcome = maybeBackoff(true, () -> iterator.next().getLowLevelResult());
            ScanResult result = outcome.getScanResult();
            Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
            if ( null != lastKey && ! lastKey.isEmpty() ) {
                pageIterator.setMarker(toMarker(lastKey, false));
            } else {
                pageIterator.setMarker(null);
            }
            return outcome;
        }
    }
    pageIterator.setMarker(null);
    return new ScanOutcome(new ScanResult());
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:28,代码来源:DdbIndex.java

示例4: withMarker

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
private ScanSpec withMarker(ScanSpec spec, PageIterator pageIterator) {
    if ( ! pageIterator.isForward() ) {
        throw new IllegalArgumentException("Backward scans are not supported");
    }
    if ( null != pageIterator.getMarker() ) {
        spec.withExclusiveStartKey(fromMarker(null, pageIterator.getMarker()));
    }
    int pageSize = pageIterator.getPageSize();
    if ( pageSize != Integer.MAX_VALUE ) {
        spec.withMaxPageSize(pageSize);
    }
    return spec;
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:14,代码来源:DdbIndex.java

示例5: run

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:32,代码来源:DocumentAPIParallelScan.java

示例6: scanItems

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
@Override
public List<T> scanItems(PageIterator pageIterator) {
    return toList(scan(new ScanSpec(), pageIterator));
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:5,代码来源:DdbIndex.java

示例7: countItems

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
@Override
public int countItems(PageIterator pageIterator) {
    return toCount(scan(new ScanSpec().withSelect(Select.COUNT), pageIterator));
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:5,代码来源:DdbIndex.java

示例8: handleRequest

import com.amazonaws.services.dynamodbv2.document.spec.ScanSpec; //导入依赖的package包/类
@Override
  public Object handleRequest(SegmentScannerInput input, Context context) {
      context.getLogger().log("Input: " + input.toJson() + "\n");
      context.getLogger().log("Start scanning segment " + input.getSegment() + "\n");

      DynamoDB dynamodb = new DynamoDB(Regions.US_WEST_2);

      // update tracking table in DynamoDB stating that we're in progress
dynamodb.getTable(FUNCTION_TRACKER_TABLE_NAME).putItem(
		new Item().withPrimaryKey(SEGMENT, input.getSegment())
		.withString(STATUS, STATUS_IN_PROGRESS));

      ScanSpec scanSpec = new ScanSpec()
              .withMaxPageSize(MAX_PAGE_SIZE)
              .withSegment(input.getSegment())
              .withTotalSegments(input.getTotalSegments())
              .withConsistentRead(true)
              .withMaxResultSize(MAX_RESULT_SIZE)
              .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);

      // if resuming an in-progress segment, specify the start key here
if (input.getStartScore() != null) {
      	scanSpec.withExclusiveStartKey(SCORE_ID, input.getStartScore());
      }

      RateLimiter rateLimiter = RateLimiter.create(input.getMaxConsumedCapacity());

      Map<String, AttributeValue> lastEvaluatedKey = null;
      Table scoresTable = dynamodb.getTable(SCORE_TABLE_NAME);

for (Page<Item, ScanOutcome> scanResultPage : scoresTable.scan(scanSpec).pages()) {
          // process items
          for (Item item : scanResultPage) {
              DataTransformer.HIGH_SCORES_BY_DATE_TRANSFORMER.transform(item, dynamodb);
          }

          /*
	 * After reading each page, we acquire the consumed capacity from
	 * the RateLimiter.
	 *
	 * For more information on using RateLimiter with DynamoDB scans,
	 * see "Rate Limited Scans in Amazon DynamoDB"
	 * on the AWS Java Development Blog:
	 * https://java.awsblog.com/post/Tx3VAYQIZ3Q0ZVW
	 */
          ScanResult scanResult = scanResultPage.getLowLevelResult().getScanResult();
          lastEvaluatedKey = scanResult.getLastEvaluatedKey();
          double consumedCapacity = scanResult.getConsumedCapacity().getCapacityUnits();
          rateLimiter.acquire((int)Math.round(consumedCapacity));

	// forego processing additional pages if we're running out of time
	if (context.getRemainingTimeInMillis() < REMAINING_TIME_CUTOFF) {
  			break;
  		}
      }

if (lastEvaluatedKey != null && !lastEvaluatedKey.isEmpty()) {
	Entry<String, AttributeValue> entry = lastEvaluatedKey.entrySet()
			.iterator().next();
	String lastScoreId = entry.getValue().getS();

	dynamodb.getTable(FUNCTION_TRACKER_TABLE_NAME).putItem(
			new Item()
					.withPrimaryKey(SEGMENT, input.getSegment())
					.withString(STATUS, STATUS_INCOMPLETE)
					.withString(LAST_SCORE_ID, lastScoreId));
	return false;
}

      // update tracking table in DynamoDB stating that we're done
dynamodb.getTable(FUNCTION_TRACKER_TABLE_NAME).putItem(
		new Item().withPrimaryKey(SEGMENT, input.getSegment())
		.withString(STATUS, STATUS_DONE));

      context.getLogger().log("Finish scanning segment " + input.getSegment() + "\n");
      return true;
  }
 
开发者ID:aws-samples,项目名称:reinvent2015-practicaldynamodb,代码行数:78,代码来源:SegmentScannerFunctionHandler.java


注:本文中的com.amazonaws.services.dynamodbv2.document.spec.ScanSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。