Search in sources :

Example 1 with HBasePropEquals

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);
}
Also used : HBaseLabelReg(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelReg) GradoopTestUtils.validateGraphElementCollections(org.gradoop.common.GradoopTestUtils.validateGraphElementCollections) DataProvider(org.testng.annotations.DataProvider) HBaseElementFilter(org.gradoop.storage.hbase.impl.predicate.filter.api.HBaseElementFilter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HBasePropLargerThan(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropLargerThan) GradoopTestUtils(org.gradoop.common.GradoopTestUtils) GradoopTestUtils.validateElementCollections(org.gradoop.common.GradoopTestUtils.validateElementCollections) ArrayList(java.util.ArrayList) HBaseFilters(org.gradoop.storage.hbase.utils.HBaseFilters) GradoopIdSet(org.gradoop.common.model.impl.id.GradoopIdSet) HBaseLabelIn(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn) Lists(com.google.common.collect.Lists) HBaseDataSink(org.gradoop.storage.hbase.impl.io.HBaseDataSink) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) GradoopHBaseTestBase(org.gradoop.storage.impl.hbase.GradoopHBaseTestBase) HBaseEPGMStore(org.gradoop.storage.hbase.impl.HBaseEPGMStore) LogicalGraph(org.gradoop.flink.model.impl.epgm.LogicalGraph) GradoopHBaseConfig(org.gradoop.storage.hbase.config.GradoopHBaseConfig) Assert.assertFalse(org.testng.Assert.assertFalse) AfterClass(org.testng.annotations.AfterClass) HBasePropEquals(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals) BeforeClass(org.testng.annotations.BeforeClass) Collection(java.util.Collection) IOException(java.io.IOException) GraphCollection(org.gradoop.flink.model.impl.epgm.GraphCollection) Collectors(java.util.stream.Collectors) EPGMGraphHead(org.gradoop.common.model.impl.pojo.EPGMGraphHead) List(java.util.List) HBasePropReg(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropReg) LocalCollectionOutputFormat(org.apache.flink.api.java.io.LocalCollectionOutputFormat) Query(org.gradoop.storage.common.predicate.query.Query) GradoopFlinkTestBase(org.gradoop.flink.model.GradoopFlinkTestBase) HBaseDataSource(org.gradoop.storage.hbase.impl.io.HBaseDataSource) Assert.assertTrue(org.testng.Assert.assertTrue) FlinkAsciiGraphLoader(org.gradoop.flink.util.FlinkAsciiGraphLoader) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Identifiable(org.gradoop.common.model.api.entities.Identifiable) InputStream(java.io.InputStream) GraphCollection(org.gradoop.flink.model.impl.epgm.GraphCollection) HBaseDataSource(org.gradoop.storage.hbase.impl.io.HBaseDataSource) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) EPGMGraphHead(org.gradoop.common.model.impl.pojo.EPGMGraphHead) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Test(org.testng.annotations.Test)

Example 2 with HBasePropEquals

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() + "].");
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) FilterList(org.apache.hadoop.hbase.filter.FilterList) HBasePropEquals(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals) Test(org.testng.annotations.Test)

Example 3 with HBasePropEquals

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);
}
Also used : HBaseLabelReg(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelReg) DataProvider(org.testng.annotations.DataProvider) HBaseElementFilter(org.gradoop.storage.hbase.impl.predicate.filter.api.HBaseElementFilter) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HBasePropLargerThan(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropLargerThan) GradoopTestUtils.validateElementCollections(org.gradoop.common.GradoopTestUtils.validateElementCollections) HBaseFilters(org.gradoop.storage.hbase.utils.HBaseFilters) GradoopIdSet(org.gradoop.common.model.impl.id.GradoopIdSet) HBaseLabelIn(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn) Lists(com.google.common.collect.Lists) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) HBaseEPGMStore(org.gradoop.storage.hbase.impl.HBaseEPGMStore) GradoopHBaseConfig(org.gradoop.storage.hbase.config.GradoopHBaseConfig) AfterClass(org.testng.annotations.AfterClass) HBasePropEquals(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals) BeforeClass(org.testng.annotations.BeforeClass) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) EPGMGraphHead(org.gradoop.common.model.impl.pojo.EPGMGraphHead) List(java.util.List) HBasePropReg(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropReg) Query(org.gradoop.storage.common.predicate.query.Query) Assert.assertTrue(org.testng.Assert.assertTrue) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Identifiable(org.gradoop.common.model.api.entities.Identifiable) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) EPGMGraphHead(org.gradoop.common.model.impl.pojo.EPGMGraphHead) Test(org.testng.annotations.Test)

Aggregations

EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)3 PropertyValue (org.gradoop.common.model.impl.properties.PropertyValue)3 HBasePropEquals (org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals)3 Test (org.testng.annotations.Test)3 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 GradoopTestUtils.validateElementCollections (org.gradoop.common.GradoopTestUtils.validateElementCollections)2 Identifiable (org.gradoop.common.model.api.entities.Identifiable)2 GradoopIdSet (org.gradoop.common.model.impl.id.GradoopIdSet)2 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)2 EPGMGraphHead (org.gradoop.common.model.impl.pojo.EPGMGraphHead)2 Query (org.gradoop.storage.common.predicate.query.Query)2 GradoopHBaseConfig (org.gradoop.storage.hbase.config.GradoopHBaseConfig)2 HBaseEPGMStore (org.gradoop.storage.hbase.impl.HBaseEPGMStore)2 HBaseElementFilter (org.gradoop.storage.hbase.impl.predicate.filter.api.HBaseElementFilter)2 HBaseLabelIn (org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn)2 HBaseLabelReg (org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelReg)2 HBasePropLargerThan (org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropLargerThan)2