Search in sources :

Example 1 with HBaseLabelIn

use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn in project gradoop by dbs-leipzig.

the class HBaseDataSinkSourceTest method testReadWithLabelInPredicate.

/**
 * Test reading a graph collection from {@link HBaseDataSource}
 * with a {@link HBaseLabelIn} predicate on each graph element
 *
 * @throws Exception on failure
 */
@Test(dataProvider = "store index")
public void testReadWithLabelInPredicate(int storeIndex) throws Exception {
    // Extract parts of social graph to filter for
    List<EPGMGraphHead> graphHeads = Lists.newArrayList(getSocialGraphHeads()).stream().filter(e -> e.getLabel().equals(LABEL_FORUM)).collect(Collectors.toList());
    List<EPGMEdge> edges = Lists.newArrayList(getSocialEdges()).stream().filter(e -> e.getLabel().equals(LABEL_HAS_MODERATOR) || e.getLabel().equals(LABEL_HAS_MEMBER)).collect(Collectors.toList());
    List<EPGMVertex> vertices = Lists.newArrayList(getSocialVertices()).stream().filter(e -> e.getLabel().equals(LABEL_TAG) || e.getLabel().equals(LABEL_FORUM)).collect(Collectors.toList());
    // Define HBase source
    HBaseDataSource hBaseDataSource = new HBaseDataSource(epgmStores[storeIndex], getConfig());
    // Apply graph predicate
    hBaseDataSource = hBaseDataSource.applyGraphPredicate(Query.elements().fromAll().where(HBaseFilters.labelIn(LABEL_FORUM)));
    // Apply edge predicate
    hBaseDataSource = hBaseDataSource.applyEdgePredicate(Query.elements().fromAll().where(HBaseFilters.labelIn(LABEL_HAS_MODERATOR, LABEL_HAS_MEMBER)));
    // Apply vertex predicate
    hBaseDataSource = hBaseDataSource.applyVertexPredicate(Query.elements().fromAll().where(HBaseFilters.labelIn(LABEL_TAG, LABEL_FORUM)));
    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) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) HBaseDataSource(org.gradoop.storage.hbase.impl.io.HBaseDataSource) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) EPGMGraphHead(org.gradoop.common.model.impl.pojo.EPGMGraphHead) Test(org.testng.annotations.Test)

Example 2 with HBaseLabelIn

use of org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn in project gradoop by dbs-leipzig.

the class HBaseLabelInTest method testToHBaseFilter.

/**
 * Test the toHBaseFilter function
 */
@Test
public void testToHBaseFilter() {
    String testLabel1 = "test1";
    String testLabel2 = "test2";
    HBaseLabelIn<EPGMEdge> edgeFilter = new HBaseLabelIn<>(testLabel1, testLabel2);
    FilterList expectedFilterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
    for (String label : Arrays.asList(testLabel2, testLabel1)) {
        SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_META), Bytes.toBytesBinary(COL_LABEL), CompareFilter.CompareOp.EQUAL, Bytes.toBytesBinary(label));
        expectedFilterList.addFilter(valueFilter);
    }
    assertEquals(edgeFilter.toHBaseFilter(false).toString(), expectedFilterList.toString());
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) HBaseLabelIn(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn) FilterList(org.apache.hadoop.hbase.filter.FilterList) Test(org.testng.annotations.Test)

Aggregations

EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)2 HBaseLabelIn (org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 LocalCollectionOutputFormat (org.apache.flink.api.java.io.LocalCollectionOutputFormat)1 FilterList (org.apache.hadoop.hbase.filter.FilterList)1 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)1 GradoopTestUtils (org.gradoop.common.GradoopTestUtils)1 GradoopTestUtils.validateElementCollections (org.gradoop.common.GradoopTestUtils.validateElementCollections)1 GradoopTestUtils.validateGraphElementCollections (org.gradoop.common.GradoopTestUtils.validateGraphElementCollections)1 Identifiable (org.gradoop.common.model.api.entities.Identifiable)1 GradoopIdSet (org.gradoop.common.model.impl.id.GradoopIdSet)1 EPGMGraphHead (org.gradoop.common.model.impl.pojo.EPGMGraphHead)1 EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)1 PropertyValue (org.gradoop.common.model.impl.properties.PropertyValue)1