-
Notifications
You must be signed in to change notification settings - Fork 89
Gradoop Store API
The Store API offers a way to define predicates at the DataSources of the supported Store instances. The predicates, containing id, label and property filters, will be executed directly at the distributed store system which results in a smaller amount of data transferred to Gradoop. In this chapter providing predicates for the HBaseDataSource
will be explained as usage example. Obviously, they can be adapted to other stores.
A DataSource
which implements the FilterableDataSource
interface, offers functions to apply predicates for all three the graph elements Vertex
, Edge
and GraphHead
of the EPGM. Each returns a copy of the DataSource instance including the applied filter. The available functions are:
source.applyVertexPredicate(ElementQuery)
source.applyEdgePredicate(ElementQuery)
source.applyGraphPredicate(ElementQuery)
Each function requires a ElementQuery
as parameter which represents the unity of all element predicates. An instance can be created through the Query
helper class:
Query.elements().fromAll() .where(ElementFilter)
.fromSets(GradoopIdSet gradoopIds) .noFilter()
.fromSets(GradoopId... gradoopIds)
An ElementFilter
can be a single filter instance or a logical combination of them. The following filters are available:
Signature | Description |
---|---|
LabelIn(String... labels) |
Returns graph elements whose labels are equal to the defined ones. |
LabelReg(Pattern reg) |
Returns graph elements whose labels match with the given regular expression. |
PropEquals(String key, Object value) |
Returns graph elements that have a property with the given name and value. |
PropReg(String key, Pattern reg) |
Returns graph elements that have a property with the given name and a value that matches the given regular expression. |
PropLargerThan(String key, Object min, boolean include) |
Returns graph elements that have a property with the given name and a numeric value that is larger than the given min value. If the include flag is set to true, elements with values that are equal to min will be included to the result set. |
Example usage
DataSource dataSource = new HBaseDataSource(store, config);
dataSource = dataSource.applyEdgePredicate(
// fromAll() => No ID filter
Query.elements().fromAll()
// WHERE edge.label LIKE '^has.*$' OR edge.since < 2015
.where(HBaseFilters.<Edge>labelReg(Pattern.compile("^has.*"))
.or(HBaseFilters.<Edge>propLargerThan("since", 2015, true).negate())));
dataSource = dataSource.applyVertexPredicate(
// fromAll() => No ID filter
Query.elements().fromAll()
// WHERE vertex.label = 'Person' AND
// (vertex.name = 'Meier' OR vertex.name = 'Mueller')
.where(HBaseFilters.<Vertex>labelIn("Person")
.and(HBaseFilters.<Vertex>propEquals("name", "Meier")
.or(HBaseFilters.<Vertex>propEquals("name", "Mueller"));
LogicalGraph g = dataSource.getLogicalGraph();