通过ID和范围条件删除行? [英] Delete rows by id and range condition?

查看:96
本文介绍了通过ID和范围条件删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种通过范围条件删除具有相同ID的项目的方法。 Table.DeleteItem的重载似乎都没有范围条件,只有范围。

I've been searching and searching for a way to delete items with the same ID by a range condition. None of the overloads for Table.DeleteItem seem to take a range condition, only a range.

还有其他方法可以删除所有早于一个小时的条目吗?

Is there some other approach to deleting all entries older than an hour?

我不想这样做不必检索所有匹配的哈希键行并通过特定范围键手动删除每一行。

I'd prefer to not not have to retrieve all the matching hashkey rows and manually delete each row by the specific range key.

我主要是使用.NET SDK,但希望获得所有提示。

I'm primarily using the .NET SDK but any hints appreciated.

我看到了一些批处理示例,但是没有什么能涵盖整个范围。

I see some batch write examples, but nothing that takes a whole range.

private static void SingleTableBatchWrite()
{
  Table productCatalog = Table.LoadTable(client, "ProductCatalog");
  var batchWrite = productCatalog.CreateBatchWrite();

  var book1 = new Document();
  book1["Id"] = 902;
  book1["Title"] = "My book1 in batch write using .NET Helper API";
  book1["ISBN"] = "902-11-11-1111";
  book1["Price"] = 10;
  book1["ProductCategory"] = "Book";
  book1["Authors"] = new List<string> { "Author 1", "Author 2", "Author 3" };
  book1["Dimensions"] = "8.5x11x.5";
  batchWrite.AddDocumentToPut(book1);
  // Specify delete item using overload that takes PK. 
  batchWrite.AddKeyToDelete(12345);
  Console.WriteLine("Performing batch write in SingleTableBatchWrite()");
  batchWrite.Execute();
}


推荐答案

该功能不存在

最好的方法是查询适当的项目并手动删除每个检索到的密钥。您可以通过在查询时仅询问哈希和范围键属性来节省带宽,但是请注意,这并不能节省读取容量;返回其属性的子集时,DynamoDB仍将向您收取项目的全部大小。

The best you can do is Query for the appropriate items and manually delete each retrieved key. You can save on the bandwidth by asking for only your hash and range key attributes when querying, but note that this doesn't save on read capacity; DynamoDB will still charge you for the full size of the item when returning a subset of its attributes.

有些人通过每次创建一个单独的表来解决此暂时性问题时间(通常是一天而不是一个小时)。这样,您可以做一些有趣的事情:

Some people have tackled this temporal problem by making a separate table for each time period (more generally a day than an hour). That way you can do some interesting things:


  • 通过删除表免费删除旧数据

  • 将今天的表扩展到比其他表更高

由于DynamoDB的模型,这种数据隔离并没有看起来那么糟糕。需要一个物品吗?您已经具有时间范围键,因此您知道要询问哪个表。需要查询吗?您的范围条件必须基于时间,因此您知道要询问哪些表。

This "data segregation" isn't as bad as it seems due to DynamoDB's model. Need to get an item? You already have the temporal range-key, so you know which table to ask. Need to query? Your Range condition must be time-based, so you know which tables to ask.

这篇关于通过ID和范围条件删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆