Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB Scan with filter, matching 'is-in-set' conditions

I'm trying to use a Scan operation on a DynamoDB table to match items with given 'tags'. The tags for an item are stored in a single set attribute. E.g.:

machine-1: tags = "windows", "iis", "64bit"
machine-2: tags = "windows", "fs"

Now, I have a support case open with Premium Support, but it's taking some amount of time. What I want to do is match machines where 'tags' contains the entry "windows" and "iis".

I can match a single one by using the CONTAINS mode, and specifying a single AttributeValue with a string value of "windows", for example.

However, CONTAINS does not support sets in a single AttributeValue, or multiple AttributeValues. It gives an error.

So I tried IN (something AWS premium support also suggested): however, whether I use a single AttributeValue (even just looking for "windows" again or multiple ones), I get zero results.

The documentation for IN is pretty poor. The operation is described in 4 uninformative words, in fact: "checks for exact matches".

While I wait for support possibly going on with a few more rounds of Q&A, is anyone reading this familiar with this kind of query with Scan? (If you could, please test what you're saying in your answer first: I think I have tried the obvious ones!)

For ref, Scan documentation: http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_Scan.html

like image 541
Kieren Johnstone Avatar asked Jul 05 '12 07:07

Kieren Johnstone


People also ask

Does DynamoDB support conditional operations?

Yes, like all the other database management systems, DynamoDB also supports all the conditional operators, User can specify a condition that is satisfied for a put, update, or delete operation to work on an item.

How can I improve DynamoDB Scan performance?

For faster response times, design your tables and indexes so that your applications can use Query instead of Scan . (For tables, you can also consider using the GetItem and BatchGetItem APIs.) Alternatively, design your application to use Scan operations in a way that minimizes the impact on your request rate.

Does DynamoDB support set?

DynamoDB supports the Java Set , List , and Map collection types. The following table summarizes how these Java types map to the DynamoDB types. BOOL (Boolean type), 0 or 1. S (string type).


1 Answers

This from AWS premium support:

"Hello.

I got confirmation from Dynamo DB this is currently not supported. CONTAINS against a set can only be performed with a single value. "

Urgh. So now I will create a new attribute for each possible tag, with a 'True' or 'False' in each column, and filter my Scan on that.

like image 136
Kieren Johnstone Avatar answered Oct 14 '22 07:10

Kieren Johnstone