use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals in project gradoop by dbs-leipzig.
the class HBaseDataSinkSourceTest method testReadWithPropEqualsPredicate.
/**
* Test reading a graph collection from {@link HBaseDataSource}
* with a {@link HBasePropEquals} predicate on each graph element
*
* @throws Exception on failure
*/
@Test(dataProvider = "store index")
public void testReadWithPropEqualsPredicate(int storeIndex) throws Exception {
PropertyValue propertyValueVertexCount = PropertyValue.create(3);
PropertyValue propertyValueSince = PropertyValue.create(2013);
PropertyValue propertyValueCity = PropertyValue.create("Leipzig");
// Extract parts of social graph to filter for
List<EPGMGraphHead> graphHeads = Lists.newArrayList(getSocialGraphHeads()).stream().filter(g -> g.hasProperty(PROP_VERTEX_COUNT)).filter(g -> g.getPropertyValue(PROP_VERTEX_COUNT).equals(propertyValueVertexCount)).collect(Collectors.toList());
List<EPGMEdge> edges = Lists.newArrayList(getSocialEdges()).stream().filter(e -> e.hasProperty(PROP_SINCE)).filter(e -> e.getPropertyValue(PROP_SINCE).equals(propertyValueSince)).collect(Collectors.toList());
List<EPGMVertex> vertices = Lists.newArrayList(getSocialVertices()).stream().filter(v -> v.hasProperty(PROP_CITY)).filter(v -> v.getPropertyValue(PROP_CITY).equals(propertyValueCity)).collect(Collectors.toList());
// Define HBase source
HBaseDataSource hBaseDataSource = new HBaseDataSource(epgmStores[storeIndex], getConfig());
// Apply graph predicate
hBaseDataSource = hBaseDataSource.applyGraphPredicate(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_VERTEX_COUNT, propertyValueVertexCount)));
// Apply edge predicate
hBaseDataSource = hBaseDataSource.applyEdgePredicate(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_SINCE, propertyValueSince)));
// Apply vertex predicate
hBaseDataSource = hBaseDataSource.applyVertexPredicate(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_CITY, propertyValueCity)));
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();
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.HBasePropEquals in project gradoop by dbs-leipzig.
the class HBasePropEqualsTest method testToHBaseFilter.
/**
* Test the toHBaseFilter function
*/
@Test(dataProvider = "property values")
public void testToHBaseFilter(String propertyKey, Object value) {
PropertyValue propertyValue = PropertyValue.create(value);
HBasePropEquals<EPGMVertex> vertexFilter = new HBasePropEquals<>(propertyKey, propertyValue);
FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.BytesUtils.getRawBytesWithoutType(propertyValue));
// 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(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.BytesUtils.getTypeByte(propertyValue));
// Define that the entire row will be skipped if the column is not found
typeFilter.setFilterIfMissing(true);
expectedFilter.addFilter(valueFilter);
expectedFilter.addFilter(typeFilter);
assertEquals(vertexFilter.toHBaseFilter(false).toString(), expectedFilter.toString(), "Failed during filter comparison for type [" + propertyValue.getType() + "].");
}
use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals in project gradoop by dbs-leipzig.
the class HBaseGraphStoreTest method testGetElementSpaceWithPropEqualsPredicate.
/**
* Test the getGraphSpace(), getVertexSpace() and getEdgeSpace() method
* with the {@link HBasePropEquals} predicate
*
* @throws IOException on failure
*/
@Test(dataProvider = "store index")
public void testGetElementSpaceWithPropEqualsPredicate(int storeIndex) throws IOException {
// Create the expected graph elements
PropertyValue propertyValueVertexCount = PropertyValue.create(3);
PropertyValue propertyValueSince = PropertyValue.create(2013);
PropertyValue propertyValueCity = PropertyValue.create("Leipzig");
// Extract parts of social graph to filter for
List<EPGMGraphHead> graphHeads = Lists.newArrayList(getSocialGraphHeads()).stream().filter(g -> g.hasProperty(PROP_VERTEX_COUNT)).filter(g -> g.getPropertyValue(PROP_VERTEX_COUNT).equals(propertyValueVertexCount)).collect(Collectors.toList());
List<EPGMEdge> edges = Lists.newArrayList(getSocialEdges()).stream().filter(e -> e.hasProperty(PROP_SINCE)).filter(e -> e.getPropertyValue(PROP_SINCE).equals(propertyValueSince)).collect(Collectors.toList());
List<EPGMVertex> vertices = Lists.newArrayList(getSocialVertices()).stream().filter(v -> v.hasProperty(PROP_CITY)).filter(v -> v.getPropertyValue(PROP_CITY).equals(propertyValueCity)).collect(Collectors.toList());
// Query the store
List<EPGMGraphHead> graphHeadResult = epgmStores[storeIndex].getGraphSpace(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_VERTEX_COUNT, propertyValueVertexCount))).readRemainsAndClose();
List<EPGMEdge> edgeResult = epgmStores[storeIndex].getEdgeSpace(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_SINCE, propertyValueSince))).readRemainsAndClose();
List<EPGMVertex> vertexResult = epgmStores[storeIndex].getVertexSpace(Query.elements().fromAll().where(HBaseFilters.propEquals(PROP_CITY, propertyValueCity))).readRemainsAndClose();
validateElementCollections(graphHeads, graphHeadResult);
validateElementCollections(vertices, vertexResult);
validateElementCollections(edges, edgeResult);
}
Aggregations