-
Notifications
You must be signed in to change notification settings - Fork 864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot query DynamoDB table with partition key only using QueryAsync #1898
Comments
Reproducible using the following code: using Amazon;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.DataModel;
using Amazon.DynamoDBv2.DocumentModel;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace DynamoDBQuery_Issue1898
{
class Program
{
static void Main(string[] args)
{
RegionEndpoint regionEndpoint = RegionEndpoint.USEast1;
AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient(regionEndpoint);
DynamoDBContext dynamoDBContext = new DynamoDBContext(amazonDynamoDBClient);
List<Price> prices = ExecuteQueryAsync(dynamoDBContext, "121").Result;
//List<Price> prices = ExecuteFromQueryAsync(dynamoDBContext, "121").Result;
foreach (var price in prices) Console.WriteLine(price);
}
private static async Task<List<Price>> ExecuteQueryAsync(DynamoDBContext dynamoDBContext, string id)
{
var query = dynamoDBContext.QueryAsync<Price>(id);
var prices = new List<Price>();
do
{
List<Price> nextSet = await query.GetNextSetAsync();
prices.AddRange(nextSet);
} while (!query.IsDone);
return prices;
}
private static async Task<List<Price>> ExecuteFromQueryAsync(DynamoDBContext dynamoDBContext, string id)
{
var query = new QueryOperationConfig()
{
KeyExpression = new Expression()
{
ExpressionStatement = "id = :id",
ExpressionAttributeValues = new Dictionary<string, DynamoDBEntry>()
{
{":id", id }
}
}
};
var fromQueryResult = dynamoDBContext.FromQueryAsync<Price>(query);
var prices = new List<Price>();
do
{
List<Price> nextSet = await fromQueryResult.GetNextSetAsync();
prices.AddRange(nextSet);
} while (!fromQueryResult.IsDone);
return prices;
}
}
[DynamoDBTable("prices")]
public class Price
{
[DynamoDBHashKey("id")]
public String Id { get; set; }
[DynamoDBProperty("symbol")]
public string Symbol { get; set; }
[DynamoDBProperty("expdate")]
public long ExpDate { get; set; }
public override string ToString()
{
return $"[Price] Id: {Id}, Symbol: {Symbol}, ExpDate: {ExpDate}";
}
}
} |
According to the docs this is expected behavior and not a bug.
|
And is it possible to query/load a table without pass the sort key? Because I tried in many ways and always return some error. Like
|
Closing this issue as it is not a bug, but rather an expected behavior as previously discussed in the comment. |
Comments on closed issues are hard for our team to see. |
Description
I'm trying to query a DynamoDB table using the .NET SDK. I'm using
DynamoDBContext.QueryAsync<>
.The data model looks like this:
Note that there isn't a sort key defined as the table does not have one.
When trying to query the table like this, I'm getting an
InvalidOperationException
q = db.QueryAsync<Price>("ID");
System.InvalidOperationException: 'Must have one range key or a GSI index defined for the table prices'
Trying to query the table using
FromQueryAsync
will work:I expect
QueryAsync
to work the same asFromQueryAsync
.Reproduction Steps
See above
Logs
StackTrace
Environment
Resolution
I hope this is a real bug and not a misuse by me.
This is a 🐛 bug-report
The text was updated successfully, but these errors were encountered: