Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete rows by id and range condition?

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.

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();
}
like image 984
FlavorScape Avatar asked Mar 01 '13 21:03

FlavorScape


People also ask

How do I delete rows with certain conditions?

Use pandas. DataFrame. drop() method to delete/remove rows with condition(s).

Can you delete rows with conditional formatting?

To do this, select the row that you want to delete and then press the "Ctrl+Shift+F3" keys on your keyboard or right-click on the row and select "Clear Conditional Formatting" from the menu that appears. This will delete the row but keep the conditional formatting so that you can apply it to another row.

How do I delete a row based on criteria in Excel VBA?

Delete Blank Rows with VBA You can also use the EntireRow. Delete method to delete all blank rows. Below is the VBA code that will select blank cells in the selected dataset and delete the entire row. The above code uses the SpecialCells property to select and delete all the cells that are blank.


1 Answers

This functionality doesn't exist in 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:

  • Delete old data "for free" by dropping the table
  • Scale today's table higher than the rest

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.

like image 157
Cory Kendall Avatar answered Oct 10 '22 15:10

Cory Kendall