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


Java QueryResult.getLastEvaluatedKey方法代码示例

本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.QueryResult.getLastEvaluatedKey方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResult.getLastEvaluatedKey方法的具体用法?Java QueryResult.getLastEvaluatedKey怎么用?Java QueryResult.getLastEvaluatedKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.dynamodbv2.model.QueryResult的用法示例。


在下文中一共展示了QueryResult.getLastEvaluatedKey方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: query

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private QueryOutcome query(Object hk, QuerySpec querySpec, PageIterator pageIterator) {
    if ( null == _convertMarker ) {
        throw new IllegalStateException("Index must first be initialized with ConvertMarker");
    }
    if ( pageIterator.getPageSize() <= 0 ) {
        return new QueryOutcome(new QueryResult());
    }
    ItemCollection<QueryOutcome> itemCollection =
        maybeBackoff(true, () ->
                     _query.query(withMarker(querySpec.withHashKey(_hkName, hk), pageIterator, hk)));

    if ( null != itemCollection ) {
        Iterator<Page<Item, QueryOutcome>> iterator = itemCollection.pages().iterator();
        if ( iterator.hasNext() ) {
            QueryOutcome outcome = maybeBackoff(true, () -> iterator.next().getLowLevelResult());
            QueryResult result = outcome.getQueryResult();
            if ( null != pageIterator.getMarker() && null != result.getItems() && result.getItems().size() > 0 ) {
                pageIterator.setPrevMarker(toMarker(result.getItems().get(0), true));
            } else {
                pageIterator.setPrevMarker(null);
            }
            Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
            if ( null != lastKey && ! lastKey.isEmpty() ) {
                pageIterator.setMarker(toMarker(lastKey, true));
            } else {
                pageIterator.setMarker(null);
            }
            return outcome;
        }
    }
    pageIterator.setPrevMarker(null);
    pageIterator.setMarker(null);
    return new QueryOutcome(new QueryResult());
}
 
开发者ID:Distelli,项目名称:java-persistence,代码行数:35,代码来源:DdbIndex.java

示例2: next

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
@Override
public QueryResultWrapper next() throws BackendException {
    final Query backoff = new ExponentialBackoff.Query(request, delegate, permitsToConsume);
    final QueryResult result = backoff.runWithBackoff();
    final ConsumedCapacity consumedCapacity = result.getConsumedCapacity();
    if (null != consumedCapacity) {
        permitsToConsume = Math.max((int) (consumedCapacity.getCapacityUnits() - 1.0), 1);
        totalCapacityUnits += consumedCapacity.getCapacityUnits();
    }

    if (result.getLastEvaluatedKey() != null && !result.getLastEvaluatedKey().isEmpty()) {
        request.setExclusiveStartKey(result.getLastEvaluatedKey());
    } else {
        markComplete();
    }
    // a update returned count
    returnedCount += result.getCount();

    // b update scanned count
    scannedCount += result.getScannedCount();
    // c add scanned finalItemList
    finalItemList.addAll(result.getItems());
    return new QueryResultWrapper(titanKey, result);
}
 
开发者ID:awslabs,项目名称:dynamodb-janusgraph-storage-backend,代码行数:25,代码来源:QueryWorker.java

示例3: queryUntilDone

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public static List<Map<String, AttributeValue>> queryUntilDone(
		AmazonDynamoDB dynamoClient, QueryRequest qr, int backoffMillis)
		throws Exception {
	List<Map<String, AttributeValue>> output = new ArrayList<>();

	Map<String, AttributeValue> lastKeyEvaluated = null;
	do {
		int queryAttempts = 0;
		QueryResult result = null;

		do {
			try {
				result = dynamoClient.query(qr).withLastEvaluatedKey(
						lastKeyEvaluated);

				output.addAll(result.getItems());
			} catch (ProvisionedThroughputExceededException e) {
				LOG.warn(String
						.format("Provisioned Throughput Exceeded - Retry Attempt %s",
								queryAttempts));

				Thread.sleep(2 ^ queryAttempts * backoffMillis);

				queryAttempts++;
			}
		} while (queryAttempts < 10 && result == null);

		if (result == null) {
			throw new Exception(String.format(
					"Unable to execute Query after %s attempts",
					queryAttempts));
		}

		lastKeyEvaluated = result.getLastEvaluatedKey();
	} while (lastKeyEvaluated != null);

	return output;
}
 
开发者ID:awslabs,项目名称:amazon-kinesis-aggregators,代码行数:39,代码来源:DynamoUtils.java

示例4: findRepliesForAThreadSpecifyOptionalLimit

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesForAThreadSpecifyOptionalLimit(String forumName, String threadSubject) {
    
    Map<String, AttributeValue> lastEvaluatedKey = null;
    do {
        QueryRequest queryRequest = new QueryRequest()
                .withTableName(tableName)
                .withKeyConditions(makeReplyKeyConditions(forumName, threadSubject))
                .withLimit(1)
                .withExclusiveStartKey(lastEvaluatedKey);

        QueryResult result = client.query(queryRequest);
        for (Map<String, AttributeValue> item : result.getItems()) {
            printItem(item);
        }
        lastEvaluatedKey = result.getLastEvaluatedKey();
    } while (lastEvaluatedKey != null);        
}
 
开发者ID:awslabs,项目名称:aws-dynamodb-examples,代码行数:18,代码来源:LowLevelQuery.java

示例5: fetchPage

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
@Override
protected PageResults<Map<String, AttributeValue>> fetchPage(RequestLimit lim) {
  // Read from DynamoDB
  RetryResult<QueryResult> retryResult = context.getClient().queryTable(tableName, context
      .getSplit().getFilterPushdown(), lastEvaluatedKey, lim.items, context.getReporter());

  QueryResult result = retryResult.result;
  int retries = retryResult.retries;

  return new PageResults<>(result.getItems(), result.getLastEvaluatedKey(), result
      .getConsumedCapacity().getCapacityUnits(), retries);
}
 
开发者ID:awslabs,项目名称:emr-dynamodb-connector,代码行数:13,代码来源:QueryRecordReadRequest.java

示例6: queryGeohash

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
/**
 * Query Amazon DynamoDB
 * 
 * @param hashKey
 *            Hash key for the query request.
 * 
 * @param range
 *            The range of geohashs to query.
 * 
 * @return The query result.
 */
public List<QueryResult> queryGeohash(QueryRequest queryRequest, long hashKey, GeohashRange range) {
	List<QueryResult> queryResults = new ArrayList<QueryResult>();
	Map<String, AttributeValue> lastEvaluatedKey = null;

	do {
		Map<String, Condition> keyConditions = new HashMap<String, Condition>();

		Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ)
				.withAttributeValueList(new AttributeValue().withN(String.valueOf(hashKey)));
		keyConditions.put(config.getHashKeyAttributeName(), hashKeyCondition);

		AttributeValue minRange = new AttributeValue().withN(Long.toString(range.getRangeMin()));
		AttributeValue maxRange = new AttributeValue().withN(Long.toString(range.getRangeMax()));

		Condition geohashCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN)
				.withAttributeValueList(minRange, maxRange);
		keyConditions.put(config.getGeohashAttributeName(), geohashCondition);

		queryRequest.withTableName(config.getTableName()).withKeyConditions(keyConditions)
				.withIndexName(config.getGeohashIndexName()).withConsistentRead(true)
				.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withExclusiveStartKey(lastEvaluatedKey);

		QueryResult queryResult = config.getDynamoDBClient().query(queryRequest);
		queryResults.add(queryResult);

		lastEvaluatedKey = queryResult.getLastEvaluatedKey();

	} while (lastEvaluatedKey != null);

	return queryResults;
}
 
开发者ID:awslabs,项目名称:dynamodb-geo,代码行数:43,代码来源:DynamoDBManager.java

示例7: query

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private Stream<Entry> query(SecretEventStream.Filter<Entry> filter) {
    QueryRequest queryRequest = new QueryRequest();
    queryRequest.withTableName(tableName);
    queryRequest.withConsistentRead(true);

    if (filter.reverse) {
        queryRequest.setScanIndexForward(false);
    }

    KeyExpressionGenerator keyExpressionGenerator = new KeyExpressionGenerator();

    KeyExpressionGenerator.KeyCondition keyExpression = keyExpressionGenerator.process(filter.parsedKeyCondition.get(), converters);
    Map<String, String> expressionAttributeNames = keyExpression.expressionAttributeNames;
    Map<String, AttributeValue> expressionAttributeValues = keyExpression.expressionAttributeValues;

    if (filter.parsedAttributeCondition.isPresent()) {
        FilterGenerator filterGenerator = new FilterGenerator(expressionAttributeValues.size()+1);
        FilterGenerator.Filter generated = filterGenerator.process(filter.parsedAttributeCondition.get(), converters);

        if(!generated.expressionAttributeNames.isEmpty()) {
            expressionAttributeNames = FilterGenerator.merge(expressionAttributeNames, generated.expressionAttributeNames);
        }

        if (!generated.expressionAttributeValues.isEmpty()) {
            expressionAttributeValues = FilterGenerator.merge(expressionAttributeValues, generated.expressionAttributeValues);
        }

        queryRequest.withFilterExpression(generated.filterExpression);
    }

    queryRequest.withExpressionAttributeNames(expressionAttributeNames);
    queryRequest.withExpressionAttributeValues(expressionAttributeValues);
    queryRequest.withKeyConditionExpression(keyExpression.keyConditionExpression);

    QueryResult result = client.query(queryRequest);

    List<Map<String, AttributeValue>> results = new ArrayList<>();

    results.addAll(result.getItems());

    while (result.getLastEvaluatedKey() != null) {
        queryRequest = queryRequest.withExclusiveStartKey(result.getLastEvaluatedKey());

        result = client.query(queryRequest);

        results.addAll(result.getItems());
    }

    return results.stream().map(this::fromMap);
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:51,代码来源:GenericDynamoDB.java

示例8: stream

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
/**
 * 
 * @param targetClass <code>Map</code> or entity class with getter/setter method.
 * @param queryRequest
 * @return
 */
public <T> Stream<T> stream(final Class<T> targetClass, final QueryRequest queryRequest) {
    final QueryResult queryResult = dynamoDB.query(queryRequest);

    final Iterator<Map<String, AttributeValue>> iterator = new ObjIterator<Map<String, AttributeValue>>() {
        private Iterator<Map<String, AttributeValue>> iter = iterate(queryResult.getItems());
        private Map<String, AttributeValue> lastEvaluatedKey = null;
        private QueryRequest newQueryRequest = null;

        {
            if (N.notNullOrEmpty(queryResult.getLastEvaluatedKey()) && N.isNullOrEmpty(queryRequest.getExclusiveStartKey())) {
                lastEvaluatedKey = queryResult.getLastEvaluatedKey();
                newQueryRequest = queryRequest.clone();
            }
        }

        @Override
        public boolean hasNext() {
            if (iter == null || iter.hasNext() == false) {
                while ((iter == null || iter.hasNext() == false) && N.notNullOrEmpty(lastEvaluatedKey)) {
                    newQueryRequest.setExclusiveStartKey(lastEvaluatedKey);
                    QueryResult newQueryResult = dynamoDB.query(newQueryRequest);
                    lastEvaluatedKey = newQueryResult.getLastEvaluatedKey();
                    iter = iterate(newQueryResult.getItems());
                }
            }

            return iter != null && iter.hasNext();
        }

        @Override
        public Map<String, AttributeValue> next() {
            if (hasNext() == false) {
                throw new NoSuchElementException();
            }

            return iter.next();
        }
    };

    final Type<T> type = N.typeOf(targetClass);

    return Stream.of(iterator).map(new Function<Map<String, AttributeValue>, T>() {
        @Override
        public T apply(Map<String, AttributeValue> t) {
            return toValue(type, targetClass, t);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:55,代码来源:DynamoDBExecutor.java

示例9: findMatching

import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private <T extends Message> List<T> findMatching(T matcher, List<Modifier> modifiers) throws DataStoreException {
  DynamoClassMapping<T> tableInfo = getClassMapping(matcher);

  log.debug("findAll {} {}", matcher.getClass().getSimpleName(), matcher);

  AttributeValue hashKey = tableInfo.buildHashKey(matcher);
  if (hashKey == null) {
    log.warn("No hash-query provided for query, full table scan required: {}", matcher);
    // XXX: throw?
    return scan(matcher, modifiers);
  }

  Map<FieldDescriptor, Object> matcherFields = matcher.getAllFields();
  // TODO: Remove PK fields

  QueryRequest request = new QueryRequest();
  // TODO: Modifier for eventually consistent read?
  request.setConsistentRead(true);
  request.setTableName(tableInfo.getDynamoTableName());

  Map<String, Condition> keyConditions = Maps.newHashMap();
  keyConditions.put(FIELD_HASH_KEY, new Condition().withComparisonOperator(ComparisonOperator.EQ)
      .withAttributeValueList(hashKey));

  tableInfo.addRangeKeyCondition(matcher, keyConditions);

  request.setKeyConditions(keyConditions);

  // int limit = Integer.MAX_VALUE;

  for (Modifier modifier : modifiers) {
    if (modifier instanceof ComparatorModifier) {
      throw new UnsupportedOperationException();
    } else if (modifier instanceof LimitModifier) {
      throw new UnsupportedOperationException();
      // limitModifier = (LimitModifier) modifier;
      // limit = limitModifier.getLimit();
    } else {
      throw new UnsupportedOperationException();
    }
  }

  QueryResult response = dynamoDB.query(request);

  Map<String, AttributeValue> lastEvaluatedKey = response.getLastEvaluatedKey();
  if (lastEvaluatedKey != null) {
    throw new UnsupportedOperationException("Multiple page results not implemented");
  }

  List<T> items = Lists.newArrayList();
  List<Map<String, AttributeValue>> responseItems = response.getItems();
  for (Map<String, AttributeValue> itemData : responseItems) {
    T item = tableInfo.mapFromDb(itemData);
    if (!DataStore.matches(matcherFields, matcher)) {
      continue;
    }
    items.add(item);
  }

  return items;
}
 
开发者ID:justinsb,项目名称:cloudata,代码行数:62,代码来源:DynamodbDataStore.java


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