Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(algorithm): support single source shortest path algorithm #285

Merged
merged 24 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
28691fd
feat: ListValue add clear() method
diaohancai Nov 21, 2023
d9c5c84
feat: Source Target Shortest Path
diaohancai Nov 21, 2023
3aff95d
test: test data is complicated
diaohancai Nov 21, 2023
b6c0f4c
test: ListValue.clear unit test
diaohancai Nov 21, 2023
f5a5de9
fix: ring loop
diaohancai Nov 21, 2023
4c37b2d
optimize: message combine
diaohancai Nov 21, 2023
15f95f6
Merge branch 'master' into pr/285
imbajin Dec 4, 2023
6630b82
refactor(algorithm): Single Source Shortest Path
diaohancai Dec 26, 2023
9524900
refactor(algorithm): output json
diaohancai Dec 26, 2023
2804bd7
feat(algorithm): multiple target optimization
diaohancai Dec 26, 2023
cdaba23
feat(core): IdList Merge Combiner
diaohancai Dec 26, 2023
125bba6
chore(algorithm): simple adjustments
diaohancai Dec 31, 2023
9587802
optimization(algorithm): change reachedTargets from IdList to IdSet
diaohancai Jan 1, 2024
01cde50
chore: json style key
diaohancai Jan 22, 2024
6b42bf5
improve: convert id from string to ID with type
diaohancai Jan 25, 2024
55b0ed3
chore: add IdUtilTest unit test
diaohancai Jan 25, 2024
2828bb7
fix: all targets reached
diaohancai Feb 6, 2024
a0a0103
improve: remove unnecessary member var
diaohancai Feb 6, 2024
c4ca8fe
improve: source vertex and target vertex specify idType
diaohancai Feb 6, 2024
174584e
chore: get properties
diaohancai Feb 7, 2024
aa8238d
improve: input vertex id parse
diaohancai Feb 29, 2024
0b1c720
chore: log improvement
diaohancai Feb 29, 2024
6510424
test: apply exception testing
diaohancai Mar 3, 2024
d55c7c7
test: parse empty id throws IllegalArgumentException
diaohancai Mar 3, 2024
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 @@ -26,27 +26,28 @@
import org.apache.hugegraph.computer.core.graph.id.IdType;
import org.apache.hugegraph.util.JsonUtil;

public class IdUtil {

Check warning on line 29 in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java

View check run for this annotation

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java#L29

Added line #L29 was not covered by tests

public static Id parseId(String idStr) {
if (StringUtils.isBlank(idStr)) {
throw new ComputerException("Can't parse Id for empty string");

Check warning on line 33 in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java

View check run for this annotation

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java#L33

Added line #L33 was not covered by tests
}

if (idStr.startsWith("U\"")) {
return IdFactory.parseId(IdType.UUID,
UUID.fromString(idStr.substring(1)
.replaceAll("\"", "")));
}

try {
if (idStr.startsWith("U\"")) {
return IdFactory.parseId(IdType.UUID,
UUID.fromString(idStr.substring(1)
.replaceAll("\"", "")));

Check warning on line 41 in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java

View check run for this annotation

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java#L39-L41

Added lines #L39 - L41 were not covered by tests
}

Object id = JsonUtil.fromJson(idStr, Object.class);
idStr = idStr.replaceAll("\"", "");
return id instanceof Number ?
IdFactory.parseId(IdType.LONG, Long.valueOf(idStr)) :

Check warning on line 47 in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java

View check run for this annotation

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java#L47

Added line #L47 was not covered by tests
IdFactory.parseId(IdType.UTF8, idStr);
} catch (Exception e) {
throw new IllegalArgumentException(String.format(

Check warning on line 50 in computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java

View check run for this annotation

Codecov / codecov/patch

computer-api/src/main/java/org/apache/hugegraph/computer/core/util/IdUtil.java#L49-L50

Added lines #L49 - L50 were not covered by tests
"The vertex id must be formatted as Number/String/UUID" +
", but got '%s'", idStr));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hugegraph.computer.core.util;

import org.apache.hugegraph.computer.core.common.exception.ComputerException;
import org.apache.hugegraph.computer.core.graph.id.IdType;
import org.apache.hugegraph.testutil.Assert;
import org.junit.Test;
Expand All @@ -25,14 +26,32 @@ public class IdUtilTest {

@Test
public void testParseId() {
String utf81 = "\"abc\"";
String utf82 = "\"222\"";
String l = "222";
String uuid = "U\"3b676b77-c484-4ba6-b627-8c040bc42863\"";
String idUtf8WithString = "\"abc\"";
String idUtf8WithNumber = "\"222\"";
String idLong = "222";
String idUuid = "U\"3b676b77-c484-4ba6-b627-8c040bc42863\"";

Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf81).idType());
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(utf82).idType());
Assert.assertEquals(IdType.LONG, IdUtil.parseId(l).idType());
Assert.assertEquals(IdType.UUID, IdUtil.parseId(uuid).idType());
String idNull = null;
String idEmpty = "";
String idDouble = "1.23";
String idUuidInvalid = "U\"123\"";

Assert.assertEquals(IdType.UTF8, IdUtil.parseId(idUtf8WithString).idType());
Assert.assertEquals(IdType.UTF8, IdUtil.parseId(idUtf8WithNumber).idType());
Assert.assertEquals(IdType.LONG, IdUtil.parseId(idLong).idType());
Assert.assertEquals(IdType.UUID, IdUtil.parseId(idUuid).idType());

Assert.assertThrows(ComputerException.class, () -> {
IdUtil.parseId(idNull).idType();
});
Assert.assertThrows(ComputerException.class, () -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also keep IllegalArgumentException?

IdUtil.parseId(idEmpty).idType();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
IdUtil.parseId(idDouble).idType();
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
IdUtil.parseId(idUuidInvalid).idType();
});
}
}
Loading