Skip to content

Commit

Permalink
add cypher result interface
Browse files Browse the repository at this point in the history
  • Loading branch information
lipanpan03 committed Jun 6, 2024
1 parent 9919a2c commit 3615bc2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
<artifactId>protobuf-java-format</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.16.3</version>
</dependency>
<dependency>
<groupId>com.baidu</groupId>
<artifactId>jprotobuf</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions rpc-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.baidu.brpc.client.loadbalance.LoadBalanceStrategy;
import com.baidu.brpc.protocol.Options;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lgraph.Lgraph;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
Expand All @@ -24,6 +25,7 @@
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import com.google.protobuf.util.JsonFormat;

/**
* @Author: haoyongdong.hyd@antgroup.com
Expand Down Expand Up @@ -387,7 +389,7 @@ private TuGraphSingleRpcClient getClientByNode(String ipAndPort) throws Exceptio
throw new Exception("do not exit " + ipAndPort +" client");
}

private void refreshClientPool() {
private void refreshClientPool() throws InvalidProtocolBufferException {
rpcClientPool.clear();
if (clientType == ClientType.DIRECT_HA_CONNECTION) {
String result = baseClient.callCypher("CALL dbms.ha.clusterInfo()", "default", 10);
Expand Down Expand Up @@ -483,7 +485,7 @@ public TuGraphSingleRpcClient(String url, String user, String pass) {
this.url = url;
}

private String handleGraphQueryRequest(Lgraph.ProtoGraphQueryType type, String query, String graph, double timeout, boolean jsonFormat) {
private String handleGraphQueryRequest(Lgraph.ProtoGraphQueryType type, String query, String graph, double timeout, boolean jsonFormat) throws InvalidProtocolBufferException {
Lgraph.GraphQueryRequest queryRequest =
Lgraph.GraphQueryRequest.newBuilder().setType(type).setQuery(query).setResultInJsonFormat(jsonFormat)
.setGraph(graph).setTimeout(timeout).build();
Expand All @@ -498,14 +500,14 @@ private String handleGraphQueryRequest(Lgraph.ProtoGraphQueryType type, String q
if (jsonFormat)
return response.getGraphQueryResponse().getJsonResult();
else
return response.getGraphQueryResponse().getBinaryResult().toString();
return JsonFormat.printer().print(response.getGraphQueryResponse().getBinaryResult());
}

private String handleCypherRequest(String query, String graph, double timeout, boolean jsonFormat) {
private String handleCypherRequest(String query, String graph, double timeout, boolean jsonFormat) throws InvalidProtocolBufferException {
return handleGraphQueryRequest(Lgraph.ProtoGraphQueryType.CYPHER, query, graph, timeout, jsonFormat);
}

private String handleGqlRequest(String query, String graph, double timeout, boolean jsonFormat) {
private String handleGqlRequest(String query, String graph, double timeout, boolean jsonFormat) throws InvalidProtocolBufferException {
return handleGraphQueryRequest(Lgraph.ProtoGraphQueryType.GQL, query, graph, timeout, jsonFormat);
}

Expand Down Expand Up @@ -702,19 +704,19 @@ public String getUrl() {
return url;
}

public String callCypher(String cypher, String graph, double timeout, boolean jsonFormat) {
public String callCypher(String cypher, String graph, double timeout, boolean jsonFormat) throws InvalidProtocolBufferException {
return handleCypherRequest(cypher, graph, timeout, jsonFormat);
}

public String callCypher(String cypher, String graph, double timeout) {
public String callCypher(String cypher, String graph, double timeout) throws InvalidProtocolBufferException {
return handleCypherRequest(cypher, graph, timeout, true);
}

public String callGql(String gql, String graph, double timeout, boolean jsonFormat) {
public String callGql(String gql, String graph, double timeout, boolean jsonFormat) throws InvalidProtocolBufferException {
return handleGqlRequest(gql, graph, timeout, jsonFormat);
}

public String callGql(String gql, String graph, double timeout) {
public String callGql(String gql, String graph, double timeout) throws InvalidProtocolBufferException {
return handleGqlRequest(gql, graph, timeout, true);
}

Expand Down Expand Up @@ -830,7 +832,7 @@ public boolean deleteProcedure(String procedureType,
return true;
}

public boolean importSchemaFromContent(String schema, String graph, double timeout) throws InputException{
public boolean importSchemaFromContent(String schema, String graph, double timeout) throws InputException, InvalidProtocolBufferException {
byte[] textByte = schema.getBytes(StandardCharsets.UTF_8);
String schema64 = Base64.getEncoder().encodeToString(textByte);
String sb = "CALL db.importor.schemaImportor('"
Expand All @@ -845,7 +847,7 @@ public boolean importSchemaFromContent(String schema, String graph, double timeo
}

public boolean importDataFromContent(String desc, String data, String delimiter,
boolean continueOnError, int threadNums, String graph, double timeout) throws UnsupportedEncodingException {
boolean continueOnError, int threadNums, String graph, double timeout) throws InvalidProtocolBufferException {
byte[] textByteDesc = desc.getBytes(StandardCharsets.UTF_8);
byte[] textByteData = data.getBytes(StandardCharsets.UTF_8);
String desc64 = Base64.getEncoder().encodeToString(textByteDesc);
Expand Down

0 comments on commit 3615bc2

Please sign in to comment.