HashKeyおよびRangeKeyを使用してグローバルセカンダリインデックスを使用してDynamoDBテーブルをクエリしようとしています。DynamoDBontext.Queryを使用してDynamoDBをクエリします。QueryOperatorを使用してQueryOperatorを使用し、List <ScanCondition>を使用してクエリフィルタを使用します。
QUERY
IndexCustomerId
によってCustomerId
とDateTime
の範囲(from-to)にしたいです。インデックスRangeKeyをDateTime
として設定するオプションはありません。唯一の選択肢は、String
,Number
およびBinary
です。
私はを使用しています。C#オブジェクト永続性モデルAmazon.DynamoDBv2.DataModel .NET Framework v3.5のAPI。
表:
+-------------------+----------+---------------------------+----------------+------------+
| InputFlowCode | Counter | OrderIssueDate | OrderTypeCode | CustomerId |
+-------------------+----------+---------------------------+----------------+------------+
| bac9-35df6ac533fc | 000004 | 2016-07-19T22:00:00.000Z | 220 | 123 |
+-------------------+----------+---------------------------+----------------+------------+
| a3db-9d6f56a5c611 | 000006 | 2016-06-30T22:00:00.000Z | 220 | 456 |
+-------------------+----------+---------------------------+----------------+------------+
| af1c-db5b089c1e32 | 000010 | 2016-07-02T22:00:00.000Z | 220 | 789 |
+-------------------+----------+---------------------------+----------------+------------+
| ... | ... | ... | ... | ... |
+-------------------+----------+---------------------------+----------------+------------+
グローバルセカンダリインデックスの定義:
IndexCustomerId:
- CustomerId (integer),
- OrderIssueDate (DateTime on model, but string on Index definition)
コード:
try
{
DateTime dateFrom = new DateTime(2016, 08, 01);
DateTime dateTo = new DateTime(2016, 08, 15);
List<MyDynamoDBItem> items = new List<MyDynamoDBItem>();
DynamoDBOperationConfig operationConfig = new DynamoDBOperationConfig();
operationConfig.OverrideTableName = "Transactions";
operationConfig.IndexName = "IndexCustomerId";
DynamoDBContext context = new DynamoDBContext(DynamoDBClient);
// 1) Works
items = context.Query<MyDynamoDBItem>(customerId, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList();
// 2) Doesn't work
items = context.Query<MyDynamoDBItem>(customerId, QueryOperator.Between, dateFrom, dateTo, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList();
// 3) Works, but I don't know if it is the right choice...
List<ScanCondition> conditions = new List<ScanCondition>();
conditions.Add(new ScanCondition(PeppolOrdineDynamoDBTableAttributes.OrderIssueDate, ScanOperator.Between, dateFrom, dateTo));
operationConfig.QueryFilter = conditions;
items = context.Query<MyDynamoDBItem>(customerId, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList();
}
catch (Exception)
{
throw;
}
T彼は最初のクエリパラメータなしで動作します。
Between
オペレータと2 DateTime
と2番目のクエリはスローException
:
{"Cannot cast objects of type 'System.Int32' to type 'System.String'."}
第三クエリ一覧で、ScanOperator
があまりにも作品QueryFilterを使用していますが、私はしないでくださいQueryOperator
との違いを知っていて、適切な選択であれば、ではなくQUERY
にしたいと思っています。