protected <T> QueryRequest createQueryRequestFromExpression(Class<T> clazz, DynamoDBQueryExpression<T> xpress, DynamoDBMapperConfig config) { final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); QueryRequest req = new QueryRequest(); req.setConsistentRead(xpress.isConsistentRead()); req.setTableName(getTableName(clazz, xpress.getHashKeyValues(), config)); req.setIndexName(xpress.getIndexName()); req.setKeyConditionExpression(xpress.getKeyConditionExpression()); processKeyConditions(req, xpress, model); req.withScanIndexForward(xpress.isScanIndexForward()) .withLimit(xpress.getLimit()) .withExclusiveStartKey(xpress.getExclusiveStartKey()) .withQueryFilter(xpress.getQueryFilter()) .withConditionalOperator(xpress.getConditionalOperator()) .withSelect(xpress.getSelect()) .withProjectionExpression(xpress.getProjectionExpression()) .withFilterExpression(xpress.getFilterExpression()) .withExpressionAttributeNames(xpress.getExpressionAttributeNames()) .withExpressionAttributeValues(xpress.getExpressionAttributeValues()) .withReturnConsumedCapacity(xpress.getReturnConsumedCapacity()) .withRequestMetricCollector(config.getRequestMetricCollector()) ; return applyUserAgent(req); }
scanRequest.withLimit(Math.toIntExact(limit)); List<Map<String, AttributeValue>> scan = dynamoDBClient.query(scanRequest).getItems();
.withLimit(limit) .withTableName(tableName) .withConsistentRead(isConsistentRead)
private static long getLastId(String tableName, String instanceName, AmazonDynamoDB dynamoClient) { QueryRequest queryRequest = new QueryRequest().withTableName(tableName) .withKeyConditionExpression("instance = :pk") .addExpressionAttributeValuesEntry(":pk", new AttributeValue().withS(instanceName)) .withScanIndexForward(false).withLimit(1); QueryResult result = dynamoClient.query(queryRequest); List<Map<String, AttributeValue>> items = result.getItems(); if (items == null || items.size() == 0) { return 0L; } else { return Long.valueOf(items.get(0).get("id").getN()); } }
@Override public long getMaxVersion(final String materialName) { final List<Map<String, AttributeValue>> items = ddb.query( new QueryRequest() .withTableName(tableName) .withConsistentRead(Boolean.TRUE) .withKeyConditions( Collections.singletonMap( DEFAULT_HASH_KEY, new Condition().withComparisonOperator( ComparisonOperator.EQ).withAttributeValueList( new AttributeValue().withS(materialName)))) .withLimit(1).withScanIndexForward(false) .withAttributesToGet(DEFAULT_RANGE_KEY)).getItems(); if (items.isEmpty()) { return -1L; } else { return Long.parseLong(items.get(0).get(DEFAULT_RANGE_KEY).getN()); } }
@Override public long getMaxVersion(final String materialName) { final List<Map<String, AttributeValue>> items = ddb.query( new QueryRequest() .withTableName(tableName) .withConsistentRead(Boolean.TRUE) .withKeyConditions( Collections.singletonMap( DEFAULT_HASH_KEY, new Condition().withComparisonOperator( ComparisonOperator.EQ).withAttributeValueList( new AttributeValue().withS(materialName)))) .withLimit(1).withScanIndexForward(false) .withAttributesToGet(DEFAULT_RANGE_KEY)).getItems(); if (items.isEmpty()) { return -1L; } else { return Long.parseLong(items.get(0).get(DEFAULT_RANGE_KEY).getN()); } }
public RetryResult<QueryResult> queryTable( String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) { final QueryRequest queryRequest = new QueryRequest() .withTableName(tableName) .withExclusiveStartKey(exclusiveStartKey) .withKeyConditions(dynamoDBQueryFilter.getKeyConditions()) .withLimit(Ints.checkedCast(limit)) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); RetryResult<QueryResult> retryResult = getRetryDriver().runWithRetry( new Callable<QueryResult>() { @Override public QueryResult call() { log.debug("Executing DynamoDB query: " + queryRequest); return dynamoDB.query(queryRequest); } }, reporter, PrintCounter.DynamoDBReadThrottle); return retryResult; }
public RetryResult<QueryResult> queryTable( String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) { final QueryRequest queryRequest = new QueryRequest() .withTableName(tableName) .withExclusiveStartKey(exclusiveStartKey) .withKeyConditions(dynamoDBQueryFilter.getKeyConditions()) .withLimit(Ints.checkedCast(limit)) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); RetryResult<QueryResult> retryResult = getRetryDriver().runWithRetry( new Callable<QueryResult>() { @Override public QueryResult call() { log.debug("Executing DynamoDB query: " + queryRequest); return dynamoDB.query(queryRequest); } }, reporter, PrintCounter.DynamoDBReadThrottle); return retryResult; }
.withScanIndexForward(this.forward) .withSelect(this.select) .withLimit(this.limit); if (this.select.equals(Select.SPECIFIC_ATTRIBUTES.toString())) { request = request.withAttributesToGet(attrs);
.withScanIndexForward(this.forward) .withSelect(this.select) .withLimit(this.limit); if (this.select.equals(Select.SPECIFIC_ATTRIBUTES.toString())) { request = request.withAttributesToGet(attrs);
.withConsistentRead(this.consistent) .withSelect(Select.COUNT) .withLimit(Integer.MAX_VALUE); if (!this.index.isEmpty()) { request = request.withIndexName(this.index);
.withConsistentRead(this.consistent) .withSelect(Select.COUNT) .withLimit(Integer.MAX_VALUE); if (!this.index.isEmpty()) { request = request.withIndexName(this.index);
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); }
@Override public List<DColumn> getColumns(String storeName, String rowKey, String startColumn, String endColumn, int count) { Timer t = new Timer(); String key = storeName + "_" + rowKey; HashMap<String,Condition> keyConditions = new HashMap<String,Condition>(); keyConditions.put("key", new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(key))); if(startColumn != null && endColumn != null) { keyConditions.put("column", new Condition() .withComparisonOperator(ComparisonOperator.BETWEEN) .withAttributeValueList(new AttributeValue().withS(startColumn), new AttributeValue(endColumn))); } else if(startColumn != null) { keyConditions.put("column", new Condition() .withComparisonOperator(ComparisonOperator.GE) .withAttributeValueList(new AttributeValue().withS(startColumn))); } else if(endColumn != null) { keyConditions.put("column", new Condition() .withComparisonOperator(ComparisonOperator.LT) .withAttributeValueList(new AttributeValue().withS(endColumn))); } QueryRequest request = new QueryRequest() .withTableName(getTenant().getName()) .withLimit(Math.min(100, count)) .withKeyConditions(keyConditions); QueryResult result = m_client.query(request); List<DColumn> list = fromItems(result.getItems()); m_logger.debug("get columns range for {} in {}", getTenant().getName(), t); return list; }
public static QueryRequest copyQueryRequest(QueryRequest queryRequest) { QueryRequest copiedQueryRequest = new QueryRequest().withAttributesToGet(queryRequest.getAttributesToGet()) .withConsistentRead(queryRequest.getConsistentRead()) .withExclusiveStartKey(queryRequest.getExclusiveStartKey()).withIndexName(queryRequest.getIndexName()) .withKeyConditions(queryRequest.getKeyConditions()).withLimit(queryRequest.getLimit()) .withReturnConsumedCapacity(queryRequest.getReturnConsumedCapacity()) .withScanIndexForward(queryRequest.getScanIndexForward()).withSelect(queryRequest.getSelect()) .withTableName(queryRequest.getTableName()); return copiedQueryRequest; } }
protected <T> QueryRequest createQueryRequestFromExpression(Class<T> clazz, DynamoDBQueryExpression<T> xpress, DynamoDBMapperConfig config) { final DynamoDBMapperTableModel<T> model = getTableModel(clazz, config); QueryRequest req = new QueryRequest(); req.setConsistentRead(xpress.isConsistentRead()); req.setTableName(getTableName(clazz, xpress.getHashKeyValues(), config)); req.setIndexName(xpress.getIndexName()); req.setKeyConditionExpression(xpress.getKeyConditionExpression()); processKeyConditions(req, xpress, model); req.withScanIndexForward(xpress.isScanIndexForward()) .withLimit(xpress.getLimit()) .withExclusiveStartKey(xpress.getExclusiveStartKey()) .withQueryFilter(xpress.getQueryFilter()) .withConditionalOperator(xpress.getConditionalOperator()) .withSelect(xpress.getSelect()) .withProjectionExpression(xpress.getProjectionExpression()) .withFilterExpression(xpress.getFilterExpression()) .withExpressionAttributeNames(xpress.getExpressionAttributeNames()) .withExpressionAttributeValues(xpress.getExpressionAttributeValues()) .withReturnConsumedCapacity(xpress.getReturnConsumedCapacity()) .withRequestMetricCollector(config.getRequestMetricCollector()) ; return applyUserAgent(req); }