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

Fix the toString of path #327

Merged
merged 1 commit into from
Jul 15, 2021
Merged
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 @@ -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