From 93eccabab7b037354c427784778153b50f3c4602 Mon Sep 17 00:00:00 2001 From: Nicole00 Date: Fri, 10 Dec 2021 17:34:42 +0800 Subject: [PATCH] update example --- .../nebula/examples/GraphClientExample.java | 45 +++++++++---------- .../nebula/examples/StorageClientExample.java | 31 +++++-------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java b/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java index 3204d461c..0d10704d3 100644 --- a/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java +++ b/examples/src/main/java/com/vesoft/nebula/examples/GraphClientExample.java @@ -85,19 +85,18 @@ public static void main(String[] args) { try { NebulaPoolConfig nebulaPoolConfig = new NebulaPoolConfig(); nebulaPoolConfig.setMaxConnSize(100); - List addresses = Arrays.asList(new HostAddress("127.0.0.1", 9669), - new HostAddress("127.0.0.1", 9670)); + List 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); } } @@ -105,41 +104,41 @@ public static void main(String[] args) { 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); @@ -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); @@ -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); diff --git a/examples/src/main/java/com/vesoft/nebula/examples/StorageClientExample.java b/examples/src/main/java/com/vesoft/nebula/examples/StorageClientExample.java index bd0608878..26e98c9f5 100644 --- a/examples/src/main/java/com/vesoft/nebula/examples/StorageClientExample.java +++ b/examples/src/main/java/com/vesoft/nebula/examples/StorageClientExample.java @@ -61,27 +61,21 @@ public static void scanVertex(StorageClient client) { if (result.isEmpty()) { continue; } - System.out.println(result.getPropNames()); + List 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 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"); } } @@ -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 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"); } } }