# Suitability of Graph Database Technology for the Analysis of Spatio-Temporal Data
## Appendix A Queries  
### Yelp: [PERSON]'s Restaurant Recommendation  
#### a.1.1 SQL  
Listing A1: A SQL query that returns \"recommending users\" of [PERSON] (a user in the dataset). These are users who have reviewed restaurants that [PERSON] has also been to with a rating above 3 stars. ```
SELECTDISTINCTOtherReviews.user_id FROMusers JOINreviewKateReviews ONusers.id=KateReviews.user_id ANDusers.id=\"qUL3 CRRRFivedMvaq6 CrIA\" ANDKateReviews.stars>3 JOINbusinessKateBus ONKateReviews.business_id=KateBus.id JOINreviewOtherReviews ONOtherReviews.user_id1=KateReviews.user_id ANDOtherReviews.business_id=KateReviews.business_id JOINbus_2_catBus2 Cat ONOtherReviews.business_id=Bus2 Cat.business_id JOINcategoryCategories ONBus2 Cat.category_id=Categories.id ANDCategories.name=\"Restaurants\"
```  
Listing A2: A SQL query that returns the star rating, text and business ID for restaurants a user has reviewed above 3 stars. ```
SELECTreview.stars,review.text,review.business_id FROMreview JOINbusiness ONreview.business_id=business.id ANDreview.user_id=\"...\" ANDST_DWithin(location,ST_MakePoint(-80.79,35.15)::geography,5000) ANDreview.stars>3 ORDERBYreview.dateDESC LIMIT10
```  
Listing A3: A Gremlin query that returns \"recommending users\" of [PERSON] (a user in the dataset). These are users who have reviewed restaurants that [PERSON] has also been to with a rating above 3 stars. ```
g.V().has(\"User\",\"user_id\",\"qUL3 CRRRFivedNvaq06 rIA\").as(\"kate\").outE(\"REVIEWS\").has(\"stars\",gt(3)).inV().in(\"REVIEWS\").where(neq(\"kate\")).as(\"users\").out(\"REVIEWS\").out(\"IN_CATEGORY\").has(\"name\",\"Restaurants\").select(\"users\").dedup().values(\"user_id\").fold()
```  
Listing A4: A Gremlin query that returns the star rating, text and business ID for restaurants a user has reviewed above 3 stars. ```
g.V().has(\"User\",\"user_id\",\"...\").outE(\"REVIEWS\").has(\"stars\",gt(3)).order().by(\"date\",desc).as(\"stars\",\"text\").inV().has(\"location\", geoWithin(Geoshape.circle(35.15,-80.79, 5))) .as(\"business_id\") .select(\"stars\").limit(10) .select(\"stars\", \"text\", \"business_id\") .by(\"stars\").by(\"text\").by(\"business_id\")

## Appendix A.1.3 GSQL

Listing A5: A GSQL query that returns \"recommending users\" of [PERSON] (a user in the dataset). These are users who have reviewed restaurants that [PERSON] has also been to with a rating above 3 stars. CREATE QUERY getSimilarUsersBasedOnRestaurants(VERTEX<User> p) FOR GRAPH MyGraph {  SetAccum<STRING> @@userIds;  categories = { Category. * };  businesses = { Business. * };  PSet = { p };  Restaurants =  SELECT b  FROM businesses:b-(In_Category)->Category:c  WHERE c.id == \"Restaurants\";  PRatedBusinesses =  SELECT b  FROM PSet-(Reviews)->Business:b  WHERE r.STARS > 3;  PRatedRestaurants = PRatedBusinesses INTERSECT Restaurants;  PeopleRatedSameBusinesses =  SELECT tgt  FROM PRatedRestaurants:m-(reverse_Reviews:r)->User:tgt  WHERE tgt!= p AND r.STARS > 3  ACCUM @userIds += tgt.id;  PRINT @userIds; }

Listing A6: A GSQL query that returns the star rating, text and business ID for restaurants a user has reviewed above 3 stars. CREATE QUERY getRecentGoodReviewsNearUser(Vertex<User> p) FOR GRAPH MyGraph {  TYPEDEF tuple<DATETIME reviewDate, STRING businessId, INT stars, STRING text> restAndReview;  DOUBLE lat = 35.15;  DOUBLE lon = -80.79;  INT distRm = 5;  HeapAccum<restAndReview(10, reviewDate DESO @busAndReviews;  ListAccum<restAndReview @finalReviews;  businesses = { Business. * };  users = { User.