Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 committed Dec 10, 2021
1 parent 57e1baf commit 93eccab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,61 +85,60 @@ public static void main(String[] args) {
try {
NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig();
nebulaPoolConfig.setMaxConnSize(100);
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669),
new HostAddress("127.0.0.1", 9670));
List<HostAddress> addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669));
pool.init(addresses, nebulaPoolConfig);
session = pool.getSession("root", "nebula", false);
{
String createSchema = "CREATE SPACE IF NOT EXISTS test; "
+ "USE test;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS like(likeness double)";
String createSchema = "CREATE SPACE IF NOT EXISTS test(vid_type=fixed_string(20)); "
+ "USE test;"
+ "CREATE TAG IF NOT EXISTS person(name string, age int);"
+ "CREATE EDGE IF NOT EXISTS like(likeness double)";
ResultSet resp = session.execute(createSchema);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
createSchema, resp.getErrorMessage()));
createSchema, resp.getErrorMessage()));
System.exit(1);
}
}

TimeUnit.SECONDS.sleep(5);
{
String insertVertexes = "INSERT VERTEX person(name, age) VALUES "
+ "'Bob':('Bob', 10), "
+ "'Lily':('Lily', 9), "
+ "'Tom':('Tom', 10), "
+ "'Jerry':('Jerry', 13), "
+ "'John':('John', 11);";
+ "'Bob':('Bob', 10), "
+ "'Lily':('Lily', 9), "
+ "'Tom':('Tom', 10), "
+ "'Jerry':('Jerry', 13), "
+ "'John':('John', 11);";
ResultSet resp = session.execute(insertVertexes);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
insertVertexes, resp.getErrorMessage()));
insertVertexes, resp.getErrorMessage()));
System.exit(1);
}
}

{
String insertEdges = "INSERT EDGE like(likeness) VALUES "
+ "'Bob'->'Lily':(80.0), "
+ "'Bob'->'Tom':(70.0), "
+ "'Lily'->'Jerry':(84.0), "
+ "'Tom'->'Jerry':(68.3), "
+ "'Bob'->'John':(97.2);";
+ "'Bob'->'Lily':(80.0), "
+ "'Bob'->'Tom':(70.0), "
+ "'Lily'->'Jerry':(84.0), "
+ "'Tom'->'Jerry':(68.3), "
+ "'Bob'->'John':(97.2);";
ResultSet resp = session.execute(insertEdges);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
insertEdges, resp.getErrorMessage()));
insertEdges, resp.getErrorMessage()));
System.exit(1);
}
}

{
String query = "GO FROM \"Bob\" OVER like "
+ "YIELD $^.person.name, $^.person.age, like.likeness";
+ "YIELD $^.person.name, $^.person.age, like.likeness";
ResultSet resp = session.execute(query);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
query, resp.getErrorMessage()));
query, resp.getErrorMessage()));
System.exit(1);
}
printResult(resp);
Expand All @@ -166,7 +165,7 @@ public static void main(String[] args) {
"examples/src/main/resources/ssl/casigned.crt",
"examples/src/main/resources/ssl/casigned.key"));
NebulaPool sslPool = new NebulaPool();
sslPool.init(Arrays.asList(new HostAddress("192.168.8.123", 9669)),
sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 9669)),
nebulaSslPoolConfig);
String queryForJson = "YIELD 1";
Session sslSession = sslPool.getSession("root", "nebula", false);
Expand All @@ -189,7 +188,7 @@ public static void main(String[] args) {
"examples/src/main/resources/ssl/selfsigned.key",
"vesoft"));
NebulaPool sslPool = new NebulaPool();
sslPool.init(Arrays.asList(new HostAddress("192.168.8.123", 9669)),
sslPool.init(Arrays.asList(new HostAddress("127.0.0.1", 9669)),
nebulaSslPoolConfig);
String queryForJson = "YIELD 1";
Session sslSession = sslPool.getSession("root", "nebula", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,21 @@ public static void scanVertex(StorageClient client) {
if (result.isEmpty()) {
continue;
}
System.out.println(result.getPropNames());

List<VertexRow> vertexRows = result.getVertices();
for (VertexRow row : vertexRows) {
if (result.getVertex(row.getVid()) != null) {
System.out.println("vid : " + result.getVertex(row.getVid()));
System.out.println(result.getVertex(row.getVid()));
}
}
System.out.println(result.getVidVertices());


System.out.println("result vertex table view:");
System.out.println("\nresult vertex table view:");
System.out.println(result.getPropNames());
List<VertexTableRow> vertexTableRows = result.getVertexTableRows();
for (VertexTableRow vertex : vertexTableRows) {
try {
System.out.println("_vid: " + vertex.getVid().asString());
System.out.println(vertex.getValues());
} catch (UnsupportedEncodingException e) {
LOGGER.error("decode String error, ", e);
}
System.out.println(vertex.getValues());
}
System.out.println(result.getVertices());
System.out.println("\n");
}
}

Expand All @@ -108,21 +102,16 @@ public static void scanEdge(StorageClient client) {
if (result.isEmpty()) {
continue;
}
System.out.println(result.getPropNames());

System.out.println(result.getEdges());

System.out.println("result edge table view:");
System.out.println("\nresult edge table view:");
System.out.println(result.getPropNames());
List<EdgeTableRow> edgeTableRows = result.getEdgeTableRows();
for (EdgeTableRow edge : edgeTableRows) {
try {
System.out.println("_src:" + edge.getSrcId().asString());
System.out.println("_dst:" + edge.getDstId().asString());
} catch (UnsupportedEncodingException e) {
LOGGER.error("decode String error, ", e);
}
System.out.println("_rank:" + edge.getRank());
System.out.println(edge.getValues());
}
System.out.println("\n");
}
}
}

0 comments on commit 93eccab

Please sign in to comment.