-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 3 Pattern Matching
Kevin Gómez edited this page Sep 3, 2020
·
15 revisions
Have a look at the Wiki pages of Gradoop - Query for further details about this operator. There are several pre-defined aggregations available.
- Find all friends of John Jones (assuming that knowing someone is equal to a friendOf relationship)
Solution
graph = graph.query(
// add query string here
"MATCH (p1:person)-[:knows]->(p2:person) WHERE p1.firstName=\"John\" AND p1.lastName=\"Jones\""
).reduce(new ReduceCombination<>());
Solution
graph = graph.callForGraph(
new KeyedGrouping<>(
Arrays.asList(GroupingKeys.label(), GroupingKeys.property("gender")),
Arrays.asList(new Count(), new AverageProperty("age")),
Arrays.asList(GroupingKeys.label(), GroupingKeys.property("classYear")),
Arrays.asList(new Count())
)
);
Solution
graph = graph.callForGraph(
new KeyedGrouping<>(
Arrays.asList(GroupingKeys.label(), new GetYearOfDate<>()),
Arrays.asList(new Count(), new MinProperty("age"), new MaxProperty("age")),
Arrays.asList(GroupingKeys.label()),
Arrays.asList(new Count())
)
);
private static class GetYearOfDate<V extends Vertex> implements KeyFunction<V, String> {
@Override
public String getKey(V vertex) {
String dayOfWeek = "unknown";
if (vertex.hasProperty("birthday")) {
dayOfWeek = vertex.getPropertyValue("birthday").getDate().getDayOfWeek().name();
}
return dayOfWeek;
}
...
}