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;
}
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;
}
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);
}
}
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));
}
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());
}
}
}
Aggregations