Вопрос

I am trying to to set a value for all items in a domain that do not already have a certain value and have an additional flag set.

Basically for all my items,

SET ValueA to 100 if ValueB is 0

But I am confused about how to achieve this. So far ive been setting the value for individual items by just using a PutRequest like this:

ArrayList<ReplaceableAttribute> newAttributes = new ArrayList<ReplaceableAttribute>();
newAttributes.add(new ReplaceableAttribute("ValueA",Integer.toString(100), true));
PutAttributesRequest newRequest = new PutAttributesRequest();
newRequest.setDomainName(usersDomain);
newRequest.setItemName(userID);
newRequest.setAttributes(newAttributes);
sdb.putAttributes(newRequest);

This works for an individual item and requires me to first get the item name (userID). Does this means that I have to "list" all of my items and do this 1 by 1? I suppose that since I have around 19000+ items I would also have to use the token to get the next set after the 2000 limit right?

Isn't there a more efficient way? This might not be so heavy right now but I expect to eventually have over 100k items.

PD: I am using the AWS Java SDK for Eclipse.

Это было полезно?

Решение

If you are talking about how you can do it grammatically by writing your own code then Yes. First you have to know all item name i.e in your case UserID and then you need to set a value one by one. You can use BatchPUTAttribute in this case. Using Batch PUT you can update 25 items in one request. You can do 5 to 20 BatchPutAttribute requests in parallel threads. Know more to tune the performance.

If you need to do it somehow in tricky way then you can use SDBExplorer. Please Remember it will set 100 for all items because SDBExplorer does not support conditional PUT. If you would like to set it anyway then Follow these steps-

  1. Download SDBExplorer zip version form download page.
  2. Extract it and run the executable.
  3. Download 30 days trial license.
  4. Once license has been downloaded main UI will open.
  5. Provide valid Access Key and Secret keys and click on "GO" button.
  6. You will see list of domains in Left side tree.
  7. Right click on the domain in which you would like to set value for all item.
  8. Choose "Export to CSV" option.
  9. Export the content of domain into CSV. http://www.sdbexplorer.com/documentation/simpledb--how-to-export-domain-in-csv-using-sdbexplorer.html
  10. Go to path where your domain has exported.
  11. Open CSV file.
  12. Your first column is item name.
  13. Delete all columns other then item Name and column "ValueA".
  14. Set 100 for all item name under "ValueA" column.
  15. Save the CSV.
  16. Go to the SDBExplorer main UI.
  17. Select the same domain.
  18. Click on "Import" option from tool bar.
  19. A panel will open.
  20. Now Import the data into the Domain. http://www.sdbexplorer.com/documentation/simpledb--how-to-upload-csv-file-data-and-specifying-column-as-amazon-simple-db-item-name.html
  21. Once import is done, explore the domain and you will find the value 100 set to all items for column ValueA.

Please try the steps first on any dummy domain.

What exactly I am trying to suggest you?

To know all item name in your domain, I am suggesting you to export all content of your domain into CSV file at local file system. Once you get all item name in CSV, keep only one column "ValueA". Set "100" for all the items in CSV file and upload/import the content back into domain.

Discloser: I am one of the developer of SDBExplorer.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top