Skip to content

Commit 0ed8b64

Browse files
committed
edge property hack: prereq for flatgraph -> odb converter
In order to prepare for a potential rollback to overflowdb in the future, we're creating a flatgraph->overflowdb converter. Since flatgraph supports exactly one edge property only, there are no edge property names. So when we deserialise and find exactly one edge property with the name `EDGE_PROPERTY`, and the schema defines exactly one edge property, then we assume that's the one. Let's be clear: this is a dirty hack, but since we're phasing out overflowdb in favor of flatgraph, it's arguably ok.
1 parent 09bc7ec commit 0ed8b64

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

core/src/main/java/overflowdb/storage/NodeDeserializer.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414
import overflowdb.util.StringInterner;
1515

1616
import java.io.IOException;
17-
import java.util.ArrayList;
18-
import java.util.Iterator;
19-
import java.util.List;
20-
import java.util.Map;
17+
import java.util.*;
2118

2219
public class NodeDeserializer extends BookKeeper {
2320
protected final Graph graph;
2421
private final Map<String, NodeFactory> nodeFactoryByLabel;
2522
private final OdbStorage storage;
2623
private final StringInterner stringInterner;
24+
private static final String FLATGRAPH_DEFAULT_EDGE_PROPERTY_NAME = "EDGE_PROPERTY";
2725

2826
public NodeDeserializer(Graph graph, Map<String, NodeFactory> nodeFactoryByLabel, boolean statsEnabled, OdbStorage storage) {
2927
super(statsEnabled);
@@ -68,7 +66,9 @@ private void deserializeEdges(MessageUnpacker unpacker, NodeDb node, Direction d
6866
for (int edgeIdx = 0; edgeIdx < edgeCount; edgeIdx++) {
6967
long adjacentNodeId = unpacker.unpackLong();
7068
NodeRef adjacentNode = (NodeRef) graph.node(adjacentNodeId);
71-
Object[] edgeProperties = unpackProperties(unpacker);
69+
// hack for flatgraph->odb converter, see `maybeReviseKeyForFlatgraph` below
70+
Set<String> allowedEdgePropertyKeys = node.layoutInformation().edgePropertyKeys(edgeLabel);
71+
Object[] edgeProperties = unpackProperties(unpacker, allowedEdgePropertyKeys);
7272
node.storeAdjacentNode(direction, edgeLabel, adjacentNode, edgeProperties);
7373
}
7474
}
@@ -87,7 +87,7 @@ public final NodeRef deserializeRef(byte[] bytes) throws IOException {
8787
}
8888
}
8989

90-
private final Object[] unpackProperties(MessageUnpacker unpacker) throws IOException {
90+
private final Object[] unpackProperties(MessageUnpacker unpacker, Set<String> allowedEdgePropertyKeys) throws IOException {
9191
int propertyCount = unpacker.unpackMapHeader();
9292
Object[] res = new Object[propertyCount * 2];
9393
int resIdx = 0;
@@ -96,12 +96,26 @@ private final Object[] unpackProperties(MessageUnpacker unpacker) throws IOExcep
9696
final String key = storage.reverseLookupStringToIntMapping(keyId);
9797
final ImmutableValue unpackedValue = unpacker.unpackValue();
9898
final Object unpackedProperty = unpackValue(unpackedValue.asArrayValue());
99-
res[resIdx++] = key;
99+
final String keyRevised = maybeReviseKeyForFlatgraph(key, allowedEdgePropertyKeys);
100+
res[resIdx++] = keyRevised;
100101
res[resIdx++] = unpackedProperty;
101102
}
102103
return res;
103104
}
104105

106+
/** In order to prepare for a potential rollback to overflowdb in the future, we're creating a
107+
* flatgraph->overflowdb converter. Since flatgraph supports exactly one edge property only,
108+
* there are no edge property names. So when we deserialise and find exactly one edge property with
109+
* the name `EDGE_PROPERTY`, and the schema defines exactly one edge property, then we assume that's the one.
110+
* Let's be clear: this is a dirty hack, but since we're phasing out overflowdb in favor of flatgraph, it's
111+
* arguably ok.
112+
*/
113+
private String maybeReviseKeyForFlatgraph(String key, Set<String> allowedEdgePropertyKeys) {
114+
if (FLATGRAPH_DEFAULT_EDGE_PROPERTY_NAME.equals(key) && allowedEdgePropertyKeys.size() == 1) {
115+
return allowedEdgePropertyKeys.iterator().next();
116+
} else return key;
117+
}
118+
105119
private final Object unpackValue(final ArrayValue packedValueAndType) {
106120
final Iterator<Value> iter = packedValueAndType.iterator();
107121
final byte valueTypeId = iter.next().asIntegerValue().asByte();

0 commit comments

Comments
 (0)