Created
July 12, 2020 13:13
-
-
Save saswata-dutta/fd2a0cc762d04034c06a53175cc632c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
graph = TinkerGraph.open() | |
g = graph.traversal() | |
a1 = g.addV("acc").property(id, 1).next() | |
a2 = g.addV("acc").property(id, 2).next() | |
a3 = g.addV("acc").property(id, 3).next() | |
a4 = g.addV("acc").property(id, 4).next() | |
a5 = g.addV("acc").property(id, 5).next() | |
a6 = g.addV("acc").property(id, 6).next() | |
a7 = g.addV("acc").property(id, 7).next() | |
sfid_a = g.addV("sfid").property(id, "a").next() | |
sfid_b = g.addV("sfid").property(id, "b").next() | |
sfid_c = g.addV("sfid").property(id, "c").next() | |
cust_x = g.addV("cust").property(id, "X").next() | |
cust_y = g.addV("cust").property(id, "Y").next() | |
ind = g.addV("region").property(id, "in").next() | |
usa = g.addV("region").property(id, "us").next() | |
aws = g.addV("business").property(id, "aws").next() | |
g.addE('has_payer').from(a2).to(a4) | |
g.addE('has_sfid').from(a5).to(sfid_b) | |
g.addE('has_sfid').from(a3).to(sfid_a) | |
g.addE('has_sfid').from(a4).to(sfid_a) | |
g.addE('has_sfid').from(a6).to(sfid_c) | |
g.addE('has_sfid').from(a7).to(sfid_c) | |
g.addE('has_cust').from(sfid_b).to(cust_x) | |
g.addE('has_cust').from(sfid_a).to(cust_x) | |
g.addE('has_cust').from(cust_x).to(cust_y) | |
g.addE('has_cust').from(a1).to(cust_y) | |
g.addE('has_cust').from(a6).to(cust_y) | |
g.addE('has_business').from(a1).to(aws) | |
g.addE('has_business').from(a2).to(aws) | |
g.addE('has_business').from(a3).to(aws) | |
g.addE('has_business').from(a4).to(aws) | |
g.addE('has_business').from(a5).to(aws) | |
g.addE('has_business').from(a6).to(aws) | |
g.addE('has_region').from(a1).to(ind) | |
g.addE('has_region').from(a1).to(usa) | |
g.addE('has_region').from(a2).to(ind) | |
g.addE('has_region').from(a2).to(usa) | |
g.addE('has_region').from(a3).to(ind) | |
g.addE('has_region').from(a4).to(usa) | |
g.addE('has_region').from(a5).to(ind) | |
g.addE('has_region').from(a5).to(usa) | |
g.addE('has_region').from(a5).to(usa) | |
g.V(2).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(0)) | |
g.V(6).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(0)).valueMap(true) | |
// transitive closure = all related accounts | |
g.V(7).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(0)).repeat(both().not(hasLabel('region', 'business')).dedup()).emit().until {t -> false}.where(hasLabel('acc')).path() | |
// filter by region + business | |
g.V(7).repeat(out().not(hasLabel('region', 'business')).simplePath()).until(outE().count().is(0)).repeat(both().not(hasLabel('region', 'business')).dedup()).emit().until {t -> false}.where(and(hasLabel('acc'), out('has_region').id().is('in'), out('has_business').id().is('aws'))).path() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment