1

I have a table in DynamoDB.

Table name  test-vod
Primary partition key   guid (String)
Primary sort key    -

With additional attributes as you can see below.

DB_Columns_1 DB_Columns_2

The goal is to query the table using one of the columns that are not a primary key srcVideo, to accomplish that we created a second local index.

DB_Indexes

And using the low-level API from DynamoDB SDK NuGet package we query with the below code (open to other options instead of low-level API).

var queryRequest = new QueryRequest
            {
                TableName = $"{_environmentName}-vod",
                IndexName = "srcVideo-index",
                ScanIndexForward = true,
                KeyConditionExpression = "srcVideo = :v_srcVideo",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
                {
                    {":v_srcVideo",new AttributeValue {S = inputMediaKey}}
                }
            };

            var response = await _client.QueryAsync(queryRequest, cancellationToken);

            // Does not exist
            var hlsUrl = response.Items
                .SelectMany(p => p)
                .SingleOrDefault(p => p.Key.Equals("hlsUrl"));

I am interested to retrieve 3 attributes (fields) from the response hlsUrl, dashUrl, workflowsStatus but all 3 missing, the response contains a Dictionary with a count of keys 27, these are only 27 out of the 35 available columns.

Attributes_Response

I have tried using ProjectionExpression and other query combinations with no success.

2 Answers 2

3

You don't show the CREATE TABLE you've used...

Sounds like your index wasn't created with the Projection attribute you really want...

Default is , KEYS_ONLY. Sounds like you want ALL or maybe INCLUDE just selected attributes...GlobalSecondaryIndex - Projection

Local secondary indexes work the same way...

Sign up to request clarification or add additional context in comments.

1 Comment

It is interesting but I made it work with the posted answer, even if the key/value is not present in the debugger you can still retrieve it.
0

It is interesting but I made it work with the below code, even if the key/value is not present in the dictionary when inspecting the debugger you can still retrieve it.

var queryRequest = new QueryRequest
            {
                TableName = tableName,
                IndexName = "srcVideo-index",
                ScanIndexForward = true,
                KeyConditionExpression = "srcVideo = :v_srcVideo",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
                {
                    {":v_srcVideo", new AttributeValue {S = inputMediaKey}}
                }
            };

            var response = await _client.QueryAsync(queryRequest, cancellationToken);

            if (response.Items.AnyAndNotNull())
            {
                var dictionary = response.Items.First().ToDictionary(p => p.Key, x => x.Value.S);

                return Result.Ok (new VodDataInfo(
                    dictionary["srcBucket"],
                    dictionary["srcVideo"],
                    dictionary["destBucket"],
                    dictionary.ContainsKey("dashUrl") 
                        ? dictionary["dashUrl"] 
                        : default,
                    dictionary.ContainsKey("hlsUrl") 
                        ? dictionary["hlsUrl"] 
                        : default,
                    dictionary["workflowStatus"]));
            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.