Alternator icon indicating copy to clipboard operation
Alternator copied to clipboard

Query does not return range key attribute value

Open irakitin opened this issue 11 years ago • 3 comments

I have a table with the following attribute definitions {hash:"id", S; range: "timestamp", S}. When I query all elements withAttributeToGet("id", "timestamp"), I'm returned only items with "id" field, but not "timestamp".

irakitin avatar Sep 17 '13 12:09 irakitin

Can you confirm that the exact same code works as intended with DynamoDB? Can you past all the code related to your problem?

On Tue, Sep 17, 2013 at 10:13 PM, Ilya Rakitin [email protected]:

I have a table with the following attribute definitions {hash:"id", S; range: "timestamp", S}. When I query all elements withAttributeToGet("id", "timestamp"), I'm returned only items with "id" field, but not "timestamp".

— Reply to this email directly or view it on GitHubhttps://github.com/mboudreau/Alternator/issues/78 .

"If at first you don't succeed, use a bigger hammer." - Unofficial motto of the Royal Electrical and Mechanical Engineers

mboudreau avatar Sep 17 '13 12:09 mboudreau

Table is created with the following code:

    try {
        dynamoDbService.getTableInfo(tableName);
    } catch (ResourceNotFoundException rnfe) {
        try {
            Future<TableDescription> table = dynamoDbService.createTable(tableName,
                    new AttributeDefinition().withAttributeName("id").withAttributeType(ScalarAttributeType.S),
                    new AttributeDefinition().withAttributeName("timestamp").withAttributeType(ScalarAttributeType.S),
                    rcu, wcu);
            table.get();
            return true;
        } catch (ExecutionException | InterruptedException e1) {
            throw Throwables.propagate(e1);
        }
    }

I query items with the following code:

                    Condition idCondition = new Condition()
                            .withComparisonOperator(ComparisonOperator.EQ)
                            .withAttributeValueList(new AttributeValue().withS(id));
                    Map<String, Condition> condition = new HashMap<>();
                    condition.put("id", idCondition);
                    QueryRequest queryRequest = new QueryRequest()
                            .withTableName(entityTable.getName())
                            .withAttributesToGet("id", "timestamp")
                            .withScanIndexForward(false)
                            .withKeyConditions(condition);
                    if (!lastQueryKey.isEmpty()) {
                        queryRequest = queryRequest.withExclusiveStartKey(lastQueryKey);
                    }
                    QueryResult queryResult = client.query(queryRequest);
                    lastQueryKey = queryResult.getLastEvaluatedKey();
                    List<Map<String, AttributeValue>> entityItems = queryResult.getItems();

After that entityItems contain items only with "id" field. I confirm this works in DynamoDB, I used to run it before, and when I switched to Alternator, I encountered the misbehavior.

irakitin avatar Sep 17 '13 12:09 irakitin

Interesting, there should of been a test for this. Don't think I'll be able to get to it soon. Best bet is to start on it yourself.

On Tue, Sep 17, 2013 at 10:33 PM, Ilya Rakitin [email protected]:

Table is created with the following code:

try {
    dynamoDbService.getTableInfo(tableName);
} catch (ResourceNotFoundException rnfe) {
    try {
        Future<TableDescription> table = dynamoDbService.createTable(tableName,
                new AttributeDefinition().withAttributeName("id").withAttributeType(ScalarAttributeType.S),
                new AttributeDefinition().withAttributeName("timestamp").withAttributeType(ScalarAttributeType.S),
                rcu, wcu);
        table.get();
        return true;
    } catch (ExecutionException | InterruptedException e1) {
        throw Throwables.propagate(e1);
    }
}

I query items with the following code:

                Condition idCondition = new Condition()
                        .withComparisonOperator(ComparisonOperator.EQ)
                        .withAttributeValueList(new AttributeValue().withS(id));
                Map<String, Condition> condition = new HashMap<>();
                condition.put("id", idCondition);
                QueryRequest queryRequest = new QueryRequest()
                        .withTableName(entityTable.getName())
                        .withAttributesToGet("id", "timestamp")
                        .withScanIndexForward(false)
                        .withKeyConditions(condition);
                if (!lastQueryKey.isEmpty()) {
                    queryRequest = queryRequest.withExclusiveStartKey(lastQueryKey);
                }
                QueryResult queryResult = client.query(queryRequest);
                lastQueryKey = queryResult.getLastEvaluatedKey();
                List<Map<String, AttributeValue>> entityItems = queryResult.getItems();

After that entityItems contain items only with "id" field. I confirm this works in DynamoDB, I used to run it before, and when I switched to Alternator, I encountered the misbehavior.

— Reply to this email directly or view it on GitHubhttps://github.com/mboudreau/Alternator/issues/78#issuecomment-24584225 .

"If at first you don't succeed, use a bigger hammer." - Unofficial motto of the Royal Electrical and Mechanical Engineers

mboudreau avatar Sep 17 '13 12:09 mboudreau