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
4 changes: 1 addition & 3 deletions .github/workflows/computer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
TRAVIS_DIR: computer-dist/src/assembly/travis
BSP_ETCD_URL: http://localhost:2579
KUBERNETES_VERSION: 1.20.1
# TODO: adapt the HugeGraph Server/Loader version to 1.5.0 (EdgeID has 5 parts now)
# NOTE: Remember to adaptor/update the version before new release
GRAPH_ENV_VERSION: 1.3.0
GRAPH_ENV_VERSION: 1.7.0

steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@
import org.apache.hugegraph.computer.core.graph.value.NullValue;
import org.apache.hugegraph.computer.core.graph.value.StringValue;
import org.apache.hugegraph.computer.core.graph.value.Value;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.SplicingIdGenerator;

public final class HugeConverter {

private static final int LEGACY_EDGE_ID_PARTS = 4;
private static final int PARENT_EDGE_ID_PARTS = 5;
private static final int DIRECTIONAL_EDGE_ID_PARTS = 6;
private static final int PARENT_EDGE_NAME_INDEX = 3;
private static final int DIRECTIONAL_EDGE_NAME_INDEX = 4;

private static final GraphFactory GRAPH_FACTORY =
ComputerContext.instance().graphFactory();

Expand Down Expand Up @@ -96,4 +104,27 @@ public static Properties convertProperties(
}
return properties;
}

public static String convertEdgeName(Edge edge) {
E.checkArgumentNotNull(edge, "The edge can't be null");
String edgeId = edge.id();
if (edgeId == null) {
return edge.name();
}

String[] parts = SplicingIdGenerator.split(edgeId);
if (parts.length == LEGACY_EDGE_ID_PARTS) {
return edge.name();
} else if (parts.length == PARENT_EDGE_ID_PARTS) {
return parts[PARENT_EDGE_NAME_INDEX];
} else if (parts.length == DIRECTIONAL_EDGE_ID_PARTS &&
isEdgeDirection(parts[1])) {
return parts[DIRECTIONAL_EDGE_NAME_INDEX];
}
return edge.name();
}

private static boolean isEdgeDirection(String part) {
return "EDGE_OUT".equals(part) || "EDGE_IN".equals(part);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ private Edge convert(org.apache.hugegraph.structure.graph.Edge edge) {
Properties properties = HugeConverter.convertProperties(
edge.properties());
Edge computerEdge = graphFactory.createEdge(edge.label(),
edge.name(), targetId
HugeConverter.convertEdgeName(edge),
targetId
);
computerEdge.label(edge.label());
computerEdge.properties(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hugegraph.computer.core.graph.value.StringValue;
import org.apache.hugegraph.computer.core.graph.value.ValueType;
import org.apache.hugegraph.computer.suite.unit.UnitTestBase;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.testutil.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -126,4 +127,40 @@ public void testConvertProperties() {
Assert.assertEquals(properties,
HugeConverter.convertProperties(rawProperties));
}

@Test
public void testConvertEdgeNameWithLegacyFourPartEdgeId() {
Edge edge = new Edge("belong_to_el_defect");
edge.id("S1:178201>5>参数标准!3BA0>S4:239464");

Assert.assertEquals("参数标准!3BA0",
HugeConverter.convertEdgeName(edge));
}

@Test
public void testConvertEdgeNameWithFivePartEdgeId() {
Edge edge = new Edge("belong_to_el_defect");
edge.id("S1:178201>5>5>参数标准!3BA0>S4:239464");

Assert.assertEquals("参数标准!3BA0",
HugeConverter.convertEdgeName(edge));
}

@Test
public void testConvertEdgeNameWithSixPartEdgeId() {
Edge edge = new Edge("belong_to_el_defect");
edge.id("S1:178201>EDGE_OUT>5>5>参数标准!3BA0>S4:239464");

Assert.assertEquals("参数标准!3BA0",
HugeConverter.convertEdgeName(edge));
}

@Test
public void testConvertEdgeNameWithSixPartInEdgeId() {
Edge edge = new Edge("belong_to_el_defect");
edge.id("S4:239464>EDGE_IN>5>5>参数标准!3BA0>S1:178201");

Assert.assertEquals("参数标准!3BA0",
HugeConverter.convertEdgeName(edge));
}
}
Loading