Search in sources :

Example 1 with PropertyValue

use of org.gradoop.common.model.impl.properties.PropertyValue in project gradoop by dbs-leipzig.

the class ListStrategy method get.

/**
 * {@inheritDoc}
 * @throws IOException if converting the byte array to a List fails.
 */
@Override
public List<PropertyValue> get(byte[] bytes) throws IOException {
    PropertyValue item;
    List<PropertyValue> list = new ArrayList<>();
    try (ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
        DataInputStream inputStream = new DataInputStream(byteStream);
        DataInputViewStreamWrapper inputView = new DataInputViewStreamWrapper(inputStream)) {
        if (inputView.skipBytes(PropertyValue.OFFSET) != PropertyValue.OFFSET) {
            throw new IOException("Malformed entry in PropertyValue List.");
        }
        while (inputView.available() > 0) {
            item = new PropertyValue();
            item.read(inputView);
            list.add(item);
        }
    } catch (IOException e) {
        throw new IOException("Error reading PropertyValue with ListStrategy.", e);
    }
    return list;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper)

Example 2 with PropertyValue

use of org.gradoop.common.model.impl.properties.PropertyValue in project gradoop by dbs-leipzig.

the class MapStrategy method get.

/**
 * {@inheritDoc}
 * @throws IOException if converting the byte array to a Map fails.
 */
@Override
public Map<PropertyValue, PropertyValue> get(byte[] bytes) throws IOException {
    DataInputViewStreamWrapper inputView = createInputView(bytes);
    Map<PropertyValue, PropertyValue> map;
    try {
        if (inputView.skipBytes(PropertyValue.OFFSET) != PropertyValue.OFFSET) {
            throw new IOException("Malformed entry in PropertyValue Map.");
        }
        map = createMap(inputView);
    } catch (IOException e) {
        throw new IOException("Error while processing DataInputViewStreamWrapper.");
    }
    return map;
}
Also used : PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) IOException(java.io.IOException) DataInputViewStreamWrapper(org.apache.flink.core.memory.DataInputViewStreamWrapper)

Example 3 with PropertyValue

use of org.gradoop.common.model.impl.properties.PropertyValue in project gradoop by dbs-leipzig.

the class MapStrategy method getRawBytes.

/**
 * {@inheritDoc}
 * @throws IOException if converting the value to a byte array fails.
 */
@Override
public byte[] getRawBytes(Map<PropertyValue, PropertyValue> value) throws IOException {
    int size = value.keySet().stream().mapToInt(PropertyValue::byteSize).sum() + value.values().stream().mapToInt(PropertyValue::byteSize).sum() + PropertyValue.OFFSET;
    try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream(size);
        DataOutputStream outputStream = new DataOutputStream(byteStream);
        DataOutputViewStreamWrapper outputView = new DataOutputViewStreamWrapper(outputStream)) {
        outputStream.write(Type.MAP.getTypeByte());
        for (Map.Entry<PropertyValue, PropertyValue> entry : value.entrySet()) {
            entry.getKey().write(outputView);
            entry.getValue().write(outputView);
        }
        return byteStream.toByteArray();
    } catch (IOException e) {
        throw new IOException("Error writing PropertyValue with MapStrategy.", e);
    }
}
Also used : DataOutputViewStreamWrapper(org.apache.flink.core.memory.DataOutputViewStreamWrapper) DataOutputStream(java.io.DataOutputStream) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with PropertyValue

use of org.gradoop.common.model.impl.properties.PropertyValue in project gradoop by dbs-leipzig.

the class GetPropertiesAsListTest method testWithAllUnset.

/**
 * Test the function with no properties set.
 *
 * @throws IOException When accessing the property value list fails.
 */
@Test
public void testWithAllUnset() throws IOException {
    Vertex testVertex = getConfig().getLogicalGraphFactory().getVertexFactory().createVertex();
    List<PropertyValue> result = toList(new GetPropertiesAsList<>(testKeys).getKey(testVertex));
    assertEquals(2, result.size());
    assertEquals(PropertyValue.NULL_VALUE, result.get(0));
    assertEquals(PropertyValue.NULL_VALUE, result.get(1));
}
Also used : Vertex(org.gradoop.common.model.api.entities.Vertex) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) Test(org.junit.Test)

Example 5 with PropertyValue

use of org.gradoop.common.model.impl.properties.PropertyValue in project gradoop by dbs-leipzig.

the class MarkDuplicatesInGroupTest method testReduce.

/**
 * Test the reduce functionality.
 *
 * @throws Exception when the execution in Flink fails.
 */
@Test
public void testReduce() throws Exception {
    VertexFactory<EPGMVertex> vertexFactory = getConfig().getLogicalGraphFactory().getVertexFactory();
    List<EPGMVertex> testVertices = IntStream.range(0, 10).mapToObj(i -> vertexFactory.createVertex()).collect(Collectors.toList());
    for (EPGMVertex testVertex : testVertices) {
        testVertex.setLabel("Test");
        testVertex.setProperty("a", PropertyValue.NULL_VALUE);
    }
    List<EPGMVertex> reduced = getExecutionEnvironment().fromCollection(testVertices).groupBy(new GetPropertiesAsList<>(Collections.singletonList("a"))).reduceGroup(new MarkDuplicatesInGroup<>()).collect();
    assertEquals(testVertices.size(), reduced.size());
    int numberOfMarkedElements = 0;
    GradoopId duplicateId = null;
    for (EPGMVertex vertex : reduced) {
        if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
            numberOfMarkedElements++;
        } else {
            assertNull("Duplicate ID was already found", duplicateId);
            duplicateId = vertex.getId();
        }
    }
    assertEquals(testVertices.size() - 1, numberOfMarkedElements);
    for (EPGMVertex vertex : reduced) {
        if (vertex.hasProperty(MarkDuplicatesInGroup.PROPERTY_KEY)) {
            PropertyValue propertyValue = vertex.getPropertyValue(MarkDuplicatesInGroup.PROPERTY_KEY);
            assertTrue(propertyValue.isGradoopId());
            assertEquals(duplicateId, propertyValue.getGradoopId());
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) VertexFactory(org.gradoop.common.model.api.entities.VertexFactory) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) GradoopFlinkTestBase(org.gradoop.flink.model.GradoopFlinkTestBase) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Collections(java.util.Collections) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) Assert.assertEquals(org.junit.Assert.assertEquals) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) GradoopId(org.gradoop.common.model.impl.id.GradoopId) Test(org.junit.Test)

Aggregations

PropertyValue (org.gradoop.common.model.impl.properties.PropertyValue)100 Test (org.junit.Test)44 EPGMVertex (org.gradoop.common.model.impl.pojo.EPGMVertex)17 ArrayList (java.util.ArrayList)16 GradoopId (org.gradoop.common.model.impl.id.GradoopId)16 EPGMGraphHead (org.gradoop.common.model.impl.pojo.EPGMGraphHead)14 Embedding (org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.Embedding)13 Test (org.testng.annotations.Test)13 IOException (java.io.IOException)11 HashMap (java.util.HashMap)11 EPGMEdge (org.gradoop.common.model.impl.pojo.EPGMEdge)11 EmbeddingMetaData (org.gradoop.flink.model.impl.operators.matching.single.cypher.pojos.EmbeddingMetaData)10 List (java.util.List)9 GraphCollection (org.gradoop.flink.model.impl.epgm.GraphCollection)9 LogicalGraph (org.gradoop.flink.model.impl.epgm.LogicalGraph)9 FlinkAsciiGraphLoader (org.gradoop.flink.util.FlinkAsciiGraphLoader)9 AggregateFunction (org.gradoop.flink.model.api.functions.AggregateFunction)8 HashSet (java.util.HashSet)7 PhysicalOperatorTest (org.gradoop.flink.model.impl.operators.matching.single.cypher.operators.PhysicalOperatorTest)6 Collectors (java.util.stream.Collectors)5