Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing Complex queries in Amazon Dynamo DB(Mathematical expressions)

I have switched from mysql to Dynamo DB .In mysql i have used a query for fetching all the users nearer to a particular latitude and longitude.The query is

SELECT *,SQRT( POW( 69.1 * ( latitude - $latitude) , 2 ) + POW( 69.1 * ( $longitude - longitude ) * COS( latitude / 57.3 ) , 2 ) ) AS distance FROM coupon WHERE is_active='Y' HAVING distance<=$radius

is it possible to create a query like in Dynamo DB.I am using PHP as my Backend

like image 299
Warrior Avatar asked May 07 '12 07:05

Warrior


1 Answers

No, Amazon DynamoDB does not offer complex SQL queries like this one out of the box, after all, something has to go when you want to use a NoSQL database ;)

However, given that DynamoDB has been developed specifically for use cases requiring fast and predictable performance with seamless scalability, which usually implies respectively large datasets, it provides integration with Amazon Elastic MapReduce (Amazon EMR) for use cases like yours:

Amazon DynamoDB also integrates with Amazon Elastic MapReduce (Amazon EMR). Amazon EMR allows businesses to perform complex analytics of their large datasets using a hosted pay-as-you-go Hadoop framework on AWS. [...] Businesses can also use Amazon EMR to access data in multiple stores (i.e. Amazon DynamoDB, Amazon RDS, and Amazon S3), do complex analysis over this combined dataset, and store the results of this work in Amazon S3.

You may want to read into Exporting, Importing, Querying, and Joining Tables in Amazon DynamoDB Using Amazon EMR for details, which summarizes Querying live Amazon DynamoDB data using SQL-like statements (HiveQL), amongst other things. While HiveQL provides a bit more than DynamoDB itself, it is still a simple SQL-like query language, and mathematical expressions like yours are not covered.

For these you'd need to dive into Hadoop and MapReduce (as provided by the DynamoDB EMR integration), as it allows you to do pretty much anything what you want with your data (see e.g. How to Create a Job Flow Using a Custom JAR).

like image 196
Steffen Opel Avatar answered Jan 03 '23 14:01

Steffen Opel