forked from tigergraph/starter_kits
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1a7ce0
commit 0a457f2
Showing
2 changed files
with
42 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
CREATE QUERY all_updates(vertex<Contact> input) FOR GRAPH MyGraph { | ||
CREATE QUERY all_updates(VERTEX<Contact> input) FOR GRAPH MyGraph { | ||
/* | ||
* Given an input Contact, find all of his/her updates. | ||
* Sample input: | ||
* input: Chris-Xi | ||
*/ | ||
|
||
SetAccum<vertex> @@specific_person_set; | ||
SetAccum<VERTEX> @@specific_person_set; | ||
|
||
start = {input}; | ||
|
||
get_updates = SELECT t from start:s-(wasUpdated:e)-ContactOnDate:t | ||
accum @@specific_person_set += s, @@specific_person_set += t; | ||
|
||
print_set = @@specific_person_set; | ||
print print_set; | ||
get_updates = SELECT t | ||
FROM start:s-(wasUpdated:e)-ContactOnDate:t | ||
ACCUM @@specific_person_set += s, @@specific_person_set += t; | ||
|
||
PRINT @@specific_person_set AS print_set; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
CREATE QUERY contact_when(vertex<Contact> contact, datetime time) FOR GRAPH MyGraph { | ||
CREATE QUERY contact_when(VERTEX<Contact> contact, DATETIME time) FOR GRAPH MyGraph { | ||
/* | ||
Sample input: | ||
contact: Chris-Xi | ||
datetime: 2019-06-05 | ||
*/ | ||
|
||
typedef tuple <dtime datetime, attribute string, source string> updates; | ||
ListAccum<vertex> @@earliest_first; | ||
HeapAccum<updates>(1,dtime desc) @email_update; | ||
HeapAccum<updates>(1,dtime desc) @phone_update; | ||
HeapAccum<updates>(1,dtime desc) @title_update; | ||
typedef tuple <dtime DATETIME, attribute STRING, source STRING> updates; | ||
ListAccum<VERTEX> @@earliest_first; | ||
HeapAccum<updates>(1,dtime DESC) @email_update; | ||
HeapAccum<updates>(1,dtime DESC) @phone_update; | ||
HeapAccum<updates>(1,dtime DESC) @title_update; | ||
|
||
Start = {contact}; | ||
|
||
get_updates = SELECT t FROM Start:s-(wasUpdated:e)-ContactOnDate:t | ||
where t.modifiedDate <= time and s.outdegree("wasUpdated") > 1 | ||
order by t.modifiedDate asc; | ||
WHERE t.modifiedDate <= time AND s.outdegree("wasUpdated") > 1 | ||
ORDER BY t.modifiedDate ASC; | ||
|
||
print get_updates; | ||
PRINT get_updates; | ||
|
||
updated_contacts = SELECT t FROM get_updates:s-(wasUpdated:e)-Contact:t | ||
accum | ||
ACCUM | ||
@@earliest_first += get_updates, | ||
if s.email != "" then | ||
IF s.email != "" THEN | ||
t.@email_update += updates(s.modifiedDate,s.email,s.source) | ||
end, | ||
if s.phone != "" then | ||
END, | ||
IF s.phone != "" THEN | ||
t.@phone_update += updates(s.modifiedDate,s.phone,s.source) | ||
end, | ||
if s.title != "" then | ||
END, | ||
IF s.title != "" THEN | ||
t.@title_update += updates(s.modifiedDate,s.title,s.source) | ||
end; | ||
END; | ||
|
||
updated_contacts2 = SELECT t from get_updates:s-(wasUpdated:e)-Contact:t | ||
post-accum | ||
if get_updates.size() > 0 then | ||
if t.@email_update.size() > 0 then | ||
updated_contacts2 = SELECT t FROM get_updates:s-(wasUpdated:e)-Contact:t | ||
POST-ACCUM | ||
IF get_updates.size() > 0 THEN | ||
IF t.@email_update.size() > 0 THEN | ||
t.LastModifiedDate = t.@email_update.top().dtime, | ||
t.LastModifiedByid = t.@email_update.top().source, | ||
t.Email = t.@email_update.top().attribute, | ||
t.Updated = true | ||
end, | ||
if t.@phone_update.size() > 0 then | ||
if t.@phone_update.top().dtime > t.@email_update.top().dtime then | ||
t.Updated = TRUE | ||
END, | ||
IF t.@phone_update.size() > 0 THEN | ||
IF t.@phone_update.top().dtime > t.@email_update.top().dtime THEN | ||
t.LastModifiedDate = t.@phone_update.top().dtime, | ||
t.LastModifiedByid = t.@phone_update.top().source, | ||
t.Phone = t.@phone_update.top().attribute, | ||
t.Updated = true | ||
t.Updated = TRUE | ||
else | ||
t.Phone = t.@phone_update.top().attribute, | ||
t.Updated = true | ||
end | ||
end, | ||
if t.@title_update.size() > 0 then | ||
if t.@title_update.top().dtime > t.@email_update.top().dtime and t.@title_update.top().dtime > t.@phone_update.top().dtime then | ||
t.Updated = TRUE | ||
END | ||
END, | ||
IF t.@title_update.size() > 0 THEN | ||
IF t.@title_update.top().dtime > t.@email_update.top().dtime AND t.@title_update.top().dtime > t.@phone_update.top().dtime THEN | ||
t.LastModifiedDate = t.@title_update.top().dtime, | ||
t.LastModifiedByid = t.@title_update.top().source, | ||
t.Title = t.@title_update.top().attribute, | ||
t.Updated = true | ||
t.Updated = TRUE | ||
else | ||
t.Title = t.@title_update.top().attribute, | ||
t.Updated = true | ||
end | ||
end | ||
end; | ||
t.Updated = TRUE | ||
END | ||
END | ||
END; | ||
|
||
} |