Skip to content
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
67 changes: 34 additions & 33 deletions examples/src/main/java/com/vesoft/nebula/GraphClientExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ public class GraphClientExample {

private static final Logger log = LoggerFactory.getLogger(GraphClientExample.class);
static String host = "127.0.0.1:9669";
// static String multipleHosts = "ip1:9669,ip2:9669";
static String user = "root";
static String passwd = "NebulaGraph01";

public static void main(String[] args) {
NebulaClient client = null;
try {
client = NebulaClient.builder(host, user, passwd)
.withAuthOptions(Collections.emptyMap())
.withConnectTimeoutMills(1000)
.withRequestTimeoutMills(3000)
.build();
.withAuthOptions(Collections.emptyMap())
.withConnectTimeoutMills(1000)
.withRequestTimeoutMills(3000)
.build();
createGraphType(client);
createGraph(client);
insertData(client);
Expand All @@ -63,10 +64,10 @@ public static void main(String[] args) {
private static void createGraphType(NebulaClient client) throws IOErrorException,
InterruptedException {
String createSchema = "CREATE GRAPH TYPE IF NOT EXISTS graph_type_nba AS {"
+ "NODE TYPE node_type_player (LABEL player {id INT PRIMARY KEY, name STRING, "
+ "score FLOAT, gender bool, rate DOUBLE}),"
+ "EDGE TYPE edge_type_follow(node_type_player)-[LABEL follow "
+ "{followness INT, likeness FLOAT64}]->(node_type_player)}";
+ "NODE TYPE node_type_player (LABEL player {id INT PRIMARY KEY, name STRING, "
+ "score FLOAT, gender bool, rate DOUBLE}),"
+ "EDGE TYPE edge_type_follow(node_type_player)-[LABEL follow "
+ "{followness INT, likeness FLOAT64}]->(node_type_player)}";
ResultSet resp = client.execute(createSchema);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
Expand Down Expand Up @@ -96,13 +97,13 @@ private static void createGraph(NebulaClient client) throws IOErrorException,

private static void insertData(NebulaClient client) throws IOErrorException {
String insertVertexes = "TABLE t{id,name,score,gender,rate} =\n"
+ "(1,\"Tim\",87.0,true,7.32),\n"
+ "(2,\"Jerry\",95.0,false,4.01),\n"
+ "(3,\"Kyle\",100,true,9.99)\n"
+ "USE nba \n"
+ "FOR r IN t\n"
+ "INSERT OR IGNORE(@node_type_player"
+ "{id:r.id,name:r.name,score:r.score,gender:r.gender,rate:r.rate})";
+ "(1,\"Tim\",87.0,true,7.32),\n"
+ "(2,\"Jerry\",95.0,false,4.01),\n"
+ "(3,\"Kyle\",100,true,9.99)\n"
+ "USE nba \n"
+ "FOR r IN t\n"
+ "INSERT OR IGNORE(@node_type_player"
+ "{id:r.id,name:r.name,score:r.score,gender:r.gender,rate:r.rate})";
ResultSet resp = client.execute(insertVertexes);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
Expand All @@ -113,15 +114,15 @@ private static void insertData(NebulaClient client) throws IOErrorException {
log.info("insert graph node succeed!");

String insertEdges = "TABLE t{id1,id2,followness,likeness}=\n"
+ "(1,2,90,66.8),\n"
+ "(2,3,100,93.35)\n"
+ "USE nba \n"
+ "FOR r IN t\n"
+ "OPTIONAL MATCH(src_node) WHERE src_node.id=r.id1 \n"
+ "OPTIONAL MATCH(dst_node) WHERE dst_node.id=r.id2\n"
+ "INSERT OR IGNORE (src_node)-"
+ "[@edge_type_follow{followness:r.followness,likeness:r.likeness}]"
+ "->(dst_node)";
+ "(1,2,90,66.8),\n"
+ "(2,3,100,93.35)\n"
+ "USE nba \n"
+ "FOR r IN t\n"
+ "OPTIONAL MATCH(src_node) WHERE src_node.id=r.id1 \n"
+ "OPTIONAL MATCH(dst_node) WHERE dst_node.id=r.id2\n"
+ "INSERT OR IGNORE (src_node)-"
+ "[@edge_type_follow{followness:r.followness,likeness:r.likeness}]"
+ "->(dst_node)";
resp = client.execute(insertEdges);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
Expand All @@ -134,7 +135,7 @@ private static void insertData(NebulaClient client) throws IOErrorException {

private static void query(NebulaClient client) throws IOErrorException {
String queryNode = "USE nba MATCH (v:player) RETURN v.id, v.name, v.score, v.gender, "
+ "v.rate";
+ "v.rate";
ResultSet resp = client.execute(queryNode);
if (!resp.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
Expand Down Expand Up @@ -166,7 +167,7 @@ private static void query(NebulaClient client) throws IOErrorException {
*/
private static void queryWithMultiThread(NebulaClient client) {
String queryNode = "USE nba MATCH (v:player) RETURN v.id, v.name, v.score, v.gender, "
+ "v.rate";
+ "v.rate";
int parallel = 200;

CountDownLatch countDownLatch = new CountDownLatch(parallel);
Expand All @@ -176,7 +177,7 @@ private static void queryWithMultiThread(NebulaClient client) {
executorService.submit(() -> {
try {
ResultSet result = client.execute(
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
if (!result.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
queryNode, result.getErrorMessage()));
Expand Down Expand Up @@ -206,7 +207,7 @@ private static void queryWithMultiThread(NebulaClient client) {
*/
private static void queryWithMultiThread() {
String queryNode = "USE nba MATCH (v:player) RETURN v.id, v.name, v.score, v.gender, "
+ "v.rate";
+ "v.rate";
int parallel = 200;

CountDownLatch countDownLatch = new CountDownLatch(parallel);
Expand All @@ -217,12 +218,12 @@ private static void queryWithMultiThread() {
NebulaClient client = null;
try {
client = NebulaClient.builder(host, user, passwd)
.withAuthOptions(Collections.emptyMap())
.withConnectTimeoutMills(5000)
.withRequestTimeoutMills(3000)
.build();
.withAuthOptions(Collections.emptyMap())
.withConnectTimeoutMills(5000)
.withRequestTimeoutMills(3000)
.build();
ResultSet result = client.execute(
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
if (!result.isSucceeded()) {
log.error(String.format("Execute: `%s', failed: %s",
queryNode, result.getErrorMessage()));
Expand Down
29 changes: 15 additions & 14 deletions examples/src/main/java/com/vesoft/nebula/NebulaPoolExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ public class NebulaPoolExample {
private static final Logger logger = LoggerFactory.getLogger(NebulaPoolExample.class);

public static void main(String[] args) {
String addresses = "127.0.0.1:9669";
String userName = "root";
String password = "NebulaGraph01";
NebulaPool pool = null;
String addresses = "127.0.0.1:9669";
// String addresses = "ip1:9669,ip2:9669";
String userName = "root";
String password = "NebulaGraph01";
NebulaPool pool = null;
try {
pool = NebulaPool
.builder(addresses, userName, password)
.withMaxClientSize(10)
.withMinClientSize(1)
.withConnectTimeoutMills(1000)
.withRequestTimeoutMills(30000)
.withBlockWhenExhausted(true)
.withMaxWaitMills(Long.MAX_VALUE)
.build();
.builder(addresses, userName, password)
.withMaxClientSize(10)
.withMinClientSize(1)
.withConnectTimeoutMills(1000)
.withRequestTimeoutMills(30000)
.withBlockWhenExhausted(true)
.withMaxWaitMills(Long.MAX_VALUE)
.build();
queryWithMultipleThreads(pool);
} catch (Exception e) {
logger.error("failed :", e);
Expand All @@ -48,7 +49,7 @@ public static void main(String[] args) {

public static void queryWithMultipleThreads(NebulaPool pool) {
String queryNode = "USE nba MATCH (v:player) RETURN v.id, v.name, v.score, v.gender, "
+ "v.rate";
+ "v.rate";
int parallel = 200;

CountDownLatch countDownLatch = new CountDownLatch(parallel);
Expand All @@ -60,7 +61,7 @@ public static void queryWithMultipleThreads(NebulaPool pool) {
try {
client = pool.getClient();
ResultSet result = client.execute(
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
"USE nba MATCH ()-[e:follow]->() RETURN e.followness, e.likeness");
if (!result.isSucceeded()) {
logger.error(String.format("Execute: `%s', failed: %s",
queryNode, result.getErrorMessage()));
Expand Down