Source:
public ImmutableList<DeviceData> getBetweenByAbsoluteTimeAggregateBySlotDuration( final Long deviceId, final Long accountId, final DateTime start, final DateTime end, final Integer slotDuration, final Collection<String> targetAttributes) { final Condition selectByDeviceId = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(deviceId))); final Condition selectByTimestamp = new Condition() .withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList( getRangeKey(accountId, start), getRangeKey(accountId, end)); final Map<String, Condition> queryConditions = new HashMap<>(); queryConditions.put(AttributeNames.DEVICE_ID, selectByDeviceId); queryConditions.put(RANGE_KEY_NAME, selectByTimestamp); final List<DeviceData> results = new ArrayList<>(); Map<String, AttributeValue> lastEvaluatedKey = null; do { final QueryRequest queryRequest = new QueryRequest() .withTableName(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributes) .withExclusiveStartKey(lastEvaluatedKey); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); final List<Map<String, AttributeValue>> items = queryResult.getItems(); if (queryResult.getItems() != null) { for (final Map<String, AttributeValue> item : items) { if (!item.keySet().containsAll(targetAttributes)) { LOGGER.warn("Missing field in item {}", item); continue; } results.add(this.attributeMapToDeviceData(item)); } } lastEvaluatedKey = queryResult.getLastEvaluatedKey(); } while (lastEvaluatedKey != null); return ImmutableList.copyOf(results); }

Target:
public ImmutableList<DeviceData> getBetweenByAbsoluteTimeAggregateBySlotDuration( final Long deviceId, final Long accountId, final DateTime start, final DateTime end, final Integer slotDuration, final Collection<String> targetAttributes) { final Condition selectByDeviceId = new Condition() .withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(deviceId))); final Condition selectByTimestamp = new Condition() .withComparisonOperator(ComparisonOperator.BETWEEN.toString()) .withAttributeValueList( getRangeKey(accountId, start), getRangeKey(accountId, end)); final Map<String, Condition> queryConditions = Maps.newHashMap(); queryConditions.put(AttributeNames.DEVICE_ID, selectByDeviceId); queryConditions.put(RANGE_KEY_NAME, selectByTimestamp); final List<DeviceData> results = Lists.newArrayList(); Map<String, AttributeValue> lastEvaluatedKey = null; int numAttempts = 0; do { numAttempts++; final QueryRequest queryRequest = new QueryRequest() .withTableName(this.tableName) .withKeyConditions(queryConditions) .withAttributesToGet(targetAttributes) .withExclusiveStartKey(lastEvaluatedKey); final QueryResult queryResult = this.dynamoDBClient.query(queryRequest); final List<Map<String, AttributeValue>> items = queryResult.getItems(); if (queryResult.getItems() != null) { for (final Map<String, AttributeValue> item : items) { if (!item.keySet().containsAll(targetAttributes)) { LOGGER.warn("Missing field in item {}", item); continue; } results.add(this.attributeMapToDeviceData(item)); } } lastEvaluatedKey = queryResult.getLastEvaluatedKey(); } while ((lastEvaluatedKey != null) && (numAttempts < MAX_QUERY_ATTEMPTS)); if (lastEvaluatedKey != null) { LOGGER.warn("Exceeded attempts while querying. Stopping with last evaluated key: {}", MAX_QUERY_ATTEMPTS, lastEvaluatedKey); } return ImmutableList.copyOf(results); }