Skip to content

Commit

Permalink
Merge branch 'master' into fix_hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-ding authored Jul 15, 2021
2 parents 1447f4e + b825171 commit 6730456
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PathWrapper extends BaseDataObject {
private List<Segment> segments = new ArrayList<>();
private List<Node> nodes = new ArrayList<>();
private List<Relationship> relationships = new ArrayList<>();
private Path path = null;

public static class Segment {
Node startNode;
Expand Down Expand Up @@ -153,6 +154,7 @@ public PathWrapper(Path path) throws InvalidValueException, UnsupportedEncodingE
this.segments = new ArrayList<>();
return;
}
this.path = path;
nodes.add((Node) new Node(path.src)
.setDecodeType(getDecodeType())
.setTimezoneOffset(getTimezoneOffset()));
Expand Down Expand Up @@ -191,7 +193,7 @@ public PathWrapper(Path path) throws InvalidValueException, UnsupportedEncodingE
step.props);
Relationship relationShip = (Relationship) new Relationship(edge)
.setDecodeType(getDecodeType())
.setTimezoneOffset(getTimezoneOffset());;
.setTimezoneOffset(getTimezoneOffset());
relationships.add(relationShip);
Segment segment = new Segment(startNode, relationShip, endNode);
if (segment.getStartNode() != nodes.get(nodes.size() - 1)
Expand All @@ -207,48 +209,30 @@ public PathWrapper(Path path) throws InvalidValueException, UnsupportedEncodingE
@Override
public String toString() {
try {
Node startNode = getStartNode();
List<String> edgeStrs = new ArrayList<>();
if (segments.size() >= 1) {
for (int i = 0; i < relationships.size(); i++) {
Relationship relationship = relationships.get(i);
List<String> propStrs = new ArrayList<>();
Map<String, ValueWrapper> props = segments.get(0).getRelationShip().properties();
Map<String, ValueWrapper> props = relationship.properties();
for (String key : props.keySet()) {
propStrs.add(key + ": " + props.get(key).toString());
}
if (segments.get(0).getStartNode() == startNode) {
edgeStrs.add(String.format("-[:%s@%d{%s}]->%s",
segments.get(0).getRelationShip().edgeName(),
segments.get(0).getRelationShip().ranking(),
String.join(", ", propStrs),
segments.get(0).getEndNode().toString()));
} else {
edgeStrs.add(String.format("<-[:%s@%d{%s}]-%s",
segments.get(0).getRelationShip().edgeName(),
segments.get(0).getRelationShip().ranking(),
String.join(", ", propStrs),
segments.get(0).getStartNode().toString()));
}

}

for (int i = 1; i < segments.size(); i++) {
List<String> propStrs = new ArrayList<>();
Map<String, ValueWrapper> props = segments.get(i).getRelationShip().properties();
for (String key : props.keySet()) {
propStrs.add(key + ": " + props.get(key).toString());
}
if (segments.get(i).getStartNode() == segments.get(i - 1).getEndNode()) {
Step step = path.steps.get(i);
Node node = (Node) new Node(step.dst)
.setDecodeType(getDecodeType())
.setTimezoneOffset(getTimezoneOffset());
if (step.type > 0) {
edgeStrs.add(String.format("-[:%s@%d{%s}]->%s",
segments.get(i).getRelationShip().edgeName(),
segments.get(i).getRelationShip().ranking(),
relationship.edgeName(),
relationship.ranking(),
String.join(", ", propStrs),
segments.get(i).getEndNode().toString()));
node.toString()));
} else {
edgeStrs.add(String.format("<-[:%s@%d{%s}]-%s",
segments.get(i).getRelationShip().edgeName(),
segments.get(i).getRelationShip().ranking(),
relationship.edgeName(),
relationship.ranking(),
String.join(", ", propStrs),
segments.get(i).getStartNode().toString()));
node.toString()));
}
}
return String.format("%s%s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TestDataFromServer {
public void setUp() throws Exception {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(1);
Assert.assertTrue(pool.init(Arrays.asList(new HostAddress("127.0.0.1", 9671)),
Assert.assertTrue(pool.init(Arrays.asList(new HostAddress("127.0.0.1", 9670)),
nebulaPoolConfig));
session = pool.getSession("root", "nebula", true);
ResultSet resp = session.execute("CREATE SPACE IF NOT EXISTS test_data"
Expand Down Expand Up @@ -340,6 +340,46 @@ public void testPath() {
}
}

@Test
public void tesDataset() {
try {
ResultSet result = session.execute(
"CREATE TAG IF NOT EXISTS player(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS like(likeness int);");
Assert.assertTrue(result.getErrorMessage(), result.isSucceeded());
TimeUnit.SECONDS.sleep(6);
result = session.execute(
"INSERT VERTEX player(name, age) values \"a\":(\"a\", 1); "
+ "INSERT VERTEX player(name, age) values \"b\":(\"b\", 2); "
+ "INSERT VERTEX player(name, age) values \"c\":(\"c\", 3); "
+ "INSERT VERTEX player(name, age) values \"d\":(\"d\", 4);"
+ "INSERT VERTEX player(name, age) values \"f\":(\"f\", 5);"
+ "INSERT VERTEX player(name, age) values \"g\":(\"g\", 6);"
+ "INSERT EDGE like(likeness) values \"d\" -> \"a\":(10); "
+ "INSERT EDGE like(likeness) values \"d\" -> \"c\":(10);"
+ "INSERT EDGE like(likeness) values \"b\" -> \"a\":(10); "
+ "INSERT EDGE like(likeness) values \"c\" -> \"b\":(10);"
+ "INSERT EDGE like(likeness) values \"a\" -> \"f\":(10); "
+ "INSERT EDGE like(likeness) values \"c\" -> \"f\":(10);"
+ "INSERT EDGE like(likeness) values \"a\" -> \"g\":(10); "
+ "INSERT EDGE like(likeness) values \"g\" -> \"c\":(10);");
Assert.assertTrue(result.getErrorMessage(), result.isSucceeded());
result = session.execute(
"FIND NOLOOP PATH FROM \"a\" TO \"c\" OVER like BIDIRECT UPTO 5 STEPS");
Assert.assertTrue(result.getErrorMessage(), result.isSucceeded());
Assert.assertEquals(4, result.rowsSize());
String expectString = "ColumnName: [path], "
+ "Rows: [(\"a\" )-[:like@0{}]->(\"g\" )-[:like@0{}]->(\"c\" ), "
+ "(\"a\" )<-[:like@0{}]-(\"d\" )-[:like@0{}]->(\"c\" ), "
+ "(\"a\" )<-[:like@0{}]-(\"b\" )<-[:like@0{}]-(\"c\" ), "
+ "(\"a\" )-[:like@0{}]->(\"f\" )<-[:like@0{}]-(\"c\" )]";
Assert.assertEquals(expectString, result.toString());
} catch (IOErrorException | InterruptedException e) {
e.printStackTrace();
assert false;
}
}

@Test
public void testErrorResult() {
try {
Expand Down

0 comments on commit 6730456

Please sign in to comment.