Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions generator/.DevConfigs/1b37806c-0428-4c29-af36-ffb0fb271403.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "DynamoDBv2",
"type": "patch",
"changeLogMessages": [
"Fix Key Expression issue with renamable sort keys."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using Amazon.DynamoDBv2.DocumentModel;
using Amazon.DynamoDBv2.Model;
using Amazon.Util;
using Amazon.Util.Internal;
using System;
using System.Collections;
Expand All @@ -24,7 +25,6 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Amazon.Util;
using ThirdParty.RuntimeBackports;
using Expression = System.Linq.Expressions.Expression;

Expand Down Expand Up @@ -1853,7 +1853,7 @@ private Dictionary<string, RangeKeyCondition> TryGetRangeKeys(QueryConditional q
"Only the right-most range key condition may use a non-equality operator. " +
$"Operator '{rangeKeyCondition.Operator}' found on range key attribute '{rangeKeyAttributeName}' at position {i}.");
}
MapRangeKeyConditionExpression(rangeKeyCondition, i, rangeKeyPropertyName, rangeKeyProperty);
MapRangeKeyConditionExpression(rangeKeyCondition, i, rangeKeyProperty);

}

Expand Down Expand Up @@ -1918,14 +1918,13 @@ DocumentModel.Expression MapHashKeyExpression()
return keyExpression1;
}

void MapRangeKeyConditionExpression( RangeKeyCondition rangeKeyCondition, int index,
string rangeKeyPropertyName, PropertyStorage rangeKeyProperty)
void MapRangeKeyConditionExpression(RangeKeyCondition rangeKeyCondition, int index,PropertyStorage rangeKeyProperty)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace issue on this line

{
keyExpression.ExpressionStatement +=
ContextExpressionsUtils.GetRangeKeyConditionExpression(RANGE_KEY_EXPRESSION_ATTRIBUTE_NAME,
rangeKeyCondition.Operator, index);
keyExpression.ExpressionAttributeNames.Add($"{RANGE_KEY_EXPRESSION_ATTRIBUTE_NAME}{index}",
rangeKeyPropertyName);
rangeKeyProperty.AttributeName);
var valuesList = rangeKeyCondition.Values?.ToList();

if (rangeKeyCondition.Operator == QueryOperator.Between)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public class TestGSIEntity
public string GsiRange2 { get; set; }
}

public class TestRenamableAttributeEntity
{
[DynamoDBHashKey("PK")]
public string Id { get; set; }

[DynamoDBRangeKey("SK")]
public string SortKey { get; set; }
}

private Mock<IAmazonDynamoDB> mockClient;
private DynamoDBContext context;

Expand Down Expand Up @@ -254,6 +263,44 @@ public void TestInitialize()
}
};
}

if (req.TableName == "TestRenamableAttributeEntity")
{
return new DescribeTableResponse
{
Table = new TableDescription
{
TableName = "TestRenamableAttributeEntity",
KeySchema = new System.Collections.Generic.List<KeySchemaElement>
{
new KeySchemaElement
{
AttributeName = "PK",
KeyType = KeyType.HASH
},
new KeySchemaElement
{
AttributeName = "SK",
KeyType = KeyType.RANGE
}
},
AttributeDefinitions = new System.Collections.Generic.List<AttributeDefinition>
{
new AttributeDefinition
{
AttributeName = "PK",
AttributeType = ScalarAttributeType.S
},
new AttributeDefinition
{
AttributeName = "SK",
AttributeType = ScalarAttributeType.S
}
}
}
};
}

// Default for TestEntity
return new DescribeTableResponse
{
Expand Down Expand Up @@ -525,6 +572,36 @@ public void ConvertQueryConditional_WithHashKeyAndRangeKey_ReturnsValidSearch()
Assert.AreEqual("test", actualRangeKeyValue.AsString());
}

[TestMethod]
public void ConvertQueryConditional_WithRenamableHashAndRangeAttributes_ReturnsValidSearch()
{
var hashKeys = new Dictionary<string, object>
{
{ "PK", "id-1" }
};

var queryConditional = QueryConditional
.HashKeysEqual(hashKeys)
.AndRangeKeyEqualTo("SK", "sort-1");

var result = context.ConvertQueryConditional<ContextInternalTests.TestRenamableAttributeEntity>(queryConditional, null);

Assert.IsNotNull(result);
Assert.IsNotNull(result.Search);

var actualSearch = result.Search;
Assert.IsNotNull(actualSearch.KeyExpression);
Assert.AreEqual("#hashKey0 = :hashKey0 AND #rangeKey0 = :rangeKey0", actualSearch.KeyExpression.ExpressionStatement);

Assert.IsNotNull(actualSearch.KeyExpression.ExpressionAttributeNames);
Assert.AreEqual("PK", actualSearch.KeyExpression.ExpressionAttributeNames["#hashKey0"]);
Assert.AreEqual("SK", actualSearch.KeyExpression.ExpressionAttributeNames["#rangeKey0"]);

Assert.IsNotNull(actualSearch.KeyExpression.ExpressionAttributeValues);
Assert.AreEqual("id-1", actualSearch.KeyExpression.ExpressionAttributeValues[":hashKey0"].AsString());
Assert.AreEqual("sort-1", actualSearch.KeyExpression.ExpressionAttributeValues[":rangeKey0"].AsString());
}

[TestMethod]
public void ConvertQueryConditional_WithGSIIndexNameAndOrder_ReturnsValidSearch()
{
Expand Down
Loading