tags:

views:

165

answers:

1

Hello,

I don't know something like this is possible or not with simpledb. I am trying to use following type of simpledb data structure.

  1. Each item has multiple name/value pairs (name here is attribute-name) e.g.

    item1
    serial_num -> value
    item2
    serial_num -> value

  2. such number of items are there in a domain and there are multiple such domains.

I want to query something like:

select * from domain where attribute-name = 'serial number'

to get all the items related to one serial number across multiple items and domains; is this possible?

My second question is regarding using combination of fields as item names.
e.g
in above mentioned structure,

Foo_datetime
            serial -> value

Foo1_datetime
            serial -> value

And I would then query items between certain datetime range and for perticular Foo or Foo1? something like

 select * from domain where itemname = 'Foo' and itemname > datetime and itemname < datetime.
+2  A: 

For your first question, the query you suggest will work just as you expect, whether you "select *" or "select serial_num", it works either way. The SimpleDB query language is similar to SQL. There is no way to get a single query to apply to multiple domains though. Each query is specific to a single domain. To issue cross-domain queries you must issue a query to each domain. This multiplies your query volume however the queries can be sent all at once without waiting, so it does not multiply the time you wait for responses.

To answer the second question, the item names can indeed be used to store data and query it. In this case you need to use the function "itemName()" within your query. A rewrite to fix your final example looks like this:

select * from domain where itemName() between 'Foodatetime1' and 'Foodatetime2'

Where datetime 1 and 2 are replaced with actual values.

Mocky
Thanks Mocky! that worked !Will the look-ups on item name will be faster than look-ups on attribute name?
Sujit
fetching an item using the item name and a call to GetAttributes is usually the fastest way if you already know the item name. In the context of a Select operation, the speed of using either itemName() or an attribute name in the where clause is comparable and will depend on your data.
Mocky
thanks Mocky for your fast replies. One last question related to my original second question. Can I query something like, select * from domain where itemName() between '*datetime1' and '*datetime2' --where '*' is like regular expression wildcard character meaning anything?
Sujit
Yes you can, but instead of BETWEEN you have to use LIKE and the wildcard character is % . However, BETWEEN can still be useful in the case where you put datetime first in the composite value, since comparisons are left to right, you can omit the trailing wildcardSELECT * FROM domain WHERE itemName() BETWEEN 'datetime1' AND 'datetime2'
Mocky