Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.graphar.info.yaml.GraphYaml;
import org.apache.graphar.util.GeneralParams;
import org.yaml.snakeyaml.Yaml;
Expand Down Expand Up @@ -98,8 +99,8 @@ public Optional<GraphInfo> addVertexAsNew(VertexInfo vertexInfo) {
.collect(Collectors.toList());
final Map<String, VertexInfo> newVertexInfoMap =
Stream.concat(
cachedVertexInfoMap.entrySet().stream(),
Stream.of(Map.entry(vertexInfo.getType(), vertexInfo)))
cachedVertexInfoMap.entrySet().stream(),
Stream.of(Map.entry(vertexInfo.getType(), vertexInfo)))
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey, Map.Entry::getValue));
Expand All @@ -112,10 +113,63 @@ public Optional<GraphInfo> addVertexAsNew(VertexInfo vertexInfo) {
cachedEdgeInfoMap));
}

public Optional<GraphInfo> removeEdgeAsNew(String srcLabel, String edgeLabel, String dstLabel) {
if (edgeInfo == null
|| hasEdgeInfo(
srcLabel, edgeLabel, dstLabel)) {
return Optional.empty();
}
String edgePath = getPrefix() + "/" + EdgeInfo.concat(srcLabel, edgeLabel, dstLabel) + ".edge.yaml";
final org.apache.graphar.proto.GraphInfo newProtoGraphInfo =
org.apache.graphar.proto.GraphInfo.newBuilder(protoGraphInfo)
.removeEdges(edgePath)
.build();
final List<EdgeInfo> newEdgeInfos = Stream.concat(cachedEdgeInfoList.stream().filter(e ->
!e.getSrcLabel().equals(srcLabel)
&& !e.getDstLabel().equals(dstLabel)
&& !e.getEdgeLabel().equals(edgeLabel)))
.collect(Collectors.toList());


List<VertexInfo> newCachedVertexInfoList = newEdgeInfos.stream()
// flatMap is used because for each edge, we might generate a stream of multiple vertices
.flatMap(e -> {
Stream<VertexInfo> vertexStream = Stream.empty(); // Start with an empty stream
if (e.getSrcLabel().equals("")) {
// If srcLabel is empty, filter vertices where dstLabel doesn't match
vertexStream = Stream.concat(vertexStream,
cachedVertexInfoList.stream()
.filter(vertex -> !e.getDstLabel().equals(vertex.getType())));
}
if (e.getDstLabel().equals("")) {
// If dstLabel is empty, filter vertices where srcLabel doesn't match
vertexStream = Stream.concat(vertexStream,
cachedVertexInfoList.stream()
.filter(vertex -> !e.getSrcLabel().equals(vertex.getType())));
}
return vertexStream; // Return the combined stream of vertices for this edge
})
.distinct()
.collect(Collectors.toList());

final Map<String, EdgeInfo> newEdgeConcat2EdgeInfo =
cachedEdgeInfoMap.entrySet().stream()
.filter(e -> !e.getConcat().equals(edgeInfo.getConcat()))
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));
// TODO if logic is correct create newCachedVertexInfoMap as well
return Optional.of(
new GraphInfo(
newProtoGraphInfo,
newCachedVertexInfoList,
newEdgeInfos,
cachedVertexInfoMap,
newEdgeConcat2EdgeInfo));
}

public Optional<GraphInfo> addEdgeAsNew(EdgeInfo edgeInfo) {
if (edgeInfo == null
|| hasEdgeInfo(
edgeInfo.getSrcLabel(), edgeInfo.getEdgeLabel(), edgeInfo.getDstLabel())) {
edgeInfo.getSrcLabel(), edgeInfo.getEdgeLabel(), edgeInfo.getDstLabel())) {
return Optional.empty();
}
final org.apache.graphar.proto.GraphInfo newProtoGraphInfo =
Expand All @@ -127,8 +181,8 @@ public Optional<GraphInfo> addEdgeAsNew(EdgeInfo edgeInfo) {
.collect(Collectors.toList());
final Map<String, EdgeInfo> newEdgeConcat2EdgeInfo =
Stream.concat(
cachedEdgeInfoMap.entrySet().stream(),
Stream.of(Map.entry(edgeInfo.getConcat(), edgeInfo)))
cachedEdgeInfoMap.entrySet().stream(),
Stream.of(Map.entry(edgeInfo.getConcat(), edgeInfo)))
.collect(
Collectors.toUnmodifiableMap(
Map.Entry::getKey, Map.Entry::getValue));
Expand Down Expand Up @@ -182,6 +236,7 @@ public List<EdgeInfo> getEdgeInfos() {
public String getPrefix() {
return protoGraphInfo.getPrefix();
}


private void checkVertexExist(String label) {
if (!hasVertexInfo(label)) {
Expand Down
2 changes: 1 addition & 1 deletion maven-projects/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<artifactId>llvm4jni</artifactId>
<version>${fastffi.revision}</version>
<classifier>${os.detected.classifier}</classifier>
<scope>provided</scope>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down
Loading