use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropReg in project gradoop by dbs-leipzig.
the class HBaseDataSinkSourceTest method testReadWithPropRegPredicate.
/**
* Test reading a graph collection from {@link HBaseDataSource}
* with a {@link HBasePropReg} predicate on each graph element
*
* @throws Exception on failure
*/
@Test(dataProvider = "store index")
public void testReadWithPropRegPredicate(int storeIndex) throws Exception {
// Extract parts of social graph to filter for
List<EPGMGraphHead> graphHeads = Lists.newArrayList(getSocialGraphHeads()).stream().filter(g -> g.hasProperty(PROP_INTEREST)).filter(g -> g.getPropertyValue(PROP_INTEREST).getString().matches(PATTERN_GRAPH_PROP.pattern())).collect(Collectors.toList());
List<EPGMEdge> edges = Lists.newArrayList(getSocialEdges()).stream().filter(e -> e.hasProperty(PROP_STATUS)).filter(e -> e.getPropertyValue(PROP_STATUS).getString().matches(PATTERN_EDGE_PROP.pattern())).collect(Collectors.toList());
List<EPGMVertex> vertices = Lists.newArrayList(getSocialVertices()).stream().filter(v -> v.hasProperty(PROP_NAME)).filter(v -> v.getPropertyValue(PROP_NAME).getString().matches(PATTERN_VERTEX_PROP.pattern())).collect(Collectors.toList());
// Define HBase source
HBaseDataSource hBaseDataSource = new HBaseDataSource(epgmStores[storeIndex], getConfig());
// Apply graph predicate
hBaseDataSource = hBaseDataSource.applyGraphPredicate(Query.elements().fromAll().where(HBaseFilters.propReg(PROP_INTEREST, PATTERN_GRAPH_PROP)));
// Apply edge predicate
hBaseDataSource = hBaseDataSource.applyEdgePredicate(Query.elements().fromAll().where(HBaseFilters.propReg(PROP_STATUS, PATTERN_EDGE_PROP)));
// Apply vertex predicate
hBaseDataSource = hBaseDataSource.applyVertexPredicate(Query.elements().fromAll().where(HBaseFilters.propReg(PROP_NAME, PATTERN_VERTEX_PROP)));
assertTrue(hBaseDataSource.isFilterPushedDown());
GraphCollection graphCollection = hBaseDataSource.getGraphCollection();
Collection<EPGMGraphHead> loadedGraphHeads = graphCollection.getGraphHeads().collect();
Collection<EPGMVertex> loadedVertices = graphCollection.getVertices().collect();
Collection<EPGMEdge> loadedEdges = graphCollection.getEdges().collect();
assertEquals(loadedGraphHeads.size(), 1);
assertEquals(loadedEdges.size(), 2);
assertEquals(loadedVertices.size(), 2);
validateElementCollections(graphHeads, loadedGraphHeads);
validateElementCollections(vertices, loadedVertices);
validateGraphElementCollections(vertices, loadedVertices);
validateElementCollections(edges, loadedEdges);
validateGraphElementCollections(edges, loadedEdges);
}
use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropReg in project gradoop by dbs-leipzig.
the class HBasePropRegTest method testToHBaseFilter.
/**
* Test the toHBaseFilter function
*/
@Test
public void testToHBaseFilter() {
String key = "key";
Pattern pattern = Pattern.compile("^FooBar.*$");
HBasePropReg<EPGMVertex> vertexFilter = new HBasePropReg<>(key, pattern);
FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(key), CompareFilter.CompareOp.EQUAL, new RegexStringComparator(pattern.pattern()));
// Define that the entire row will be skipped if the column is not found
valueFilter.setFilterIfMissing(true);
SingleColumnValueFilter typeFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_TYPE), Bytes.toBytesBinary(key), CompareFilter.CompareOp.EQUAL, new byte[] { Type.STRING.getTypeByte() });
// Define that the entire row will be skipped if the column is not found
typeFilter.setFilterIfMissing(true);
expectedFilter.addFilter(typeFilter);
expectedFilter.addFilter(valueFilter);
assertEquals(vertexFilter.toHBaseFilter(false).toString(), expectedFilter.toString(), "Failed during filter comparison for key [" + key + "].");
}
Aggregations