Narayan
Narayan

Reputation: 6241

Dynamodb: Placeholders for Attribute Names and Values

i read the following link that explains to use placeholders by means of expression attribute name

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ExpressionPlaceholders.html#ExpressionAttributeValues

My json document is stored as follows:

{"user_json": {"profile.title":"abc"} }"

my java code is as follows

        Map<String, String> expressionAttributeNames = new HashMap<String, String>();
        expressionAttributeNames.put("#u1", "user_json.profile.title");

        String projectionExpression = "user_id, #u1";
        QuerySpec spec = new QuerySpec()
            .withProjectionExpression(projectionExpression)
            .withKeyConditionExpression("user_id = :v_id")
            .withNameMap(expressionAttributeNames)
            .withValueMap(new ValueMap()
                .withString(":v_id", userId))
            .withConsistentRead(true);

        ItemCollection<QueryOutcome> items = table.query(spec);
        Iterator<Item> iterator = items.iterator();
        String jsonPretty="";
        while (iterator.hasNext()) {
            jsonPretty = iterator.next().toJSON();
            System.out.println(jsonPretty);
        } 

Problem: not able to retrieve Document path which has a dot in it.

can someone please point out the problem? thanks

Upvotes: 4

Views: 4283

Answers (1)

xtx
xtx

Reputation: 4456

Try doing like this:

Map<String, String> expressionAttributeNames = new HashMap<String, String>();
expressionAttributeNames.put("#u1_1", "user_json");
expressionAttributeNames.put("#u1_2", "profile.title");

String projectionExpression = "user_id, #u1_1.#u1_2";

Upvotes: 5

Related Questions