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

upload multiple cpp files #13

Merged
merged 1 commit into from
Mar 18, 2024
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 @@ -5,6 +5,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;

public class TuGraphDbRpcClientTest {
static Logger log = LoggerFactory.getLogger(TuGraphDbRpcClientTest.class);
Expand Down Expand Up @@ -35,6 +36,16 @@ public static void loadProcedure(TuGraphDbRpcClient client) {
result = client.loadProcedure("./scan_graph.so", "CPP", "scan_graph", "SO", "test scan_graph", true,
"v1", "default");
log.info("loadProcedure : " + result);

String[] multi_files = {
"../../test/test_procedures/multi_files.cpp",
"../../test/test_procedures/multi_files.h",
"../../test/test_procedures/multi_files_core.cpp"
};
result = client.loadProcedure(multi_files, "CPP", "multi_file", "CPP", "test sortstr", true,
"v1", "default");
log.info("loadProcedure : " + result);
assert (result);
} catch (IOException e) {
log.info("catch IOException : " + e.getMessage());
} catch (Exception e) {
Expand All @@ -48,7 +59,7 @@ public static void listProcedures(TuGraphDbRpcClient client) throws Exception {
String result = client.listProcedures("CPP", "any", "default");
log.info("testListProcedure: " + result);
JSONArray jsonArray = JSONArray.parseArray(result);
assert (jsonArray.size() == 2);
assert (jsonArray.size() == 3);
} catch (TuGraphDbRpcException e) {
log.info("catch TuGraphDbRpcException : " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@ public boolean loadProcedure(String sourceFile, String procedureType, String pro
}
}

public boolean loadProcedure(String[] sourceFiles, String procedureType, String procedureName, String codeType,
String procedureDescription, boolean readOnly, String version, String graph) throws Exception {
if (clientType == ClientType.SINGLE_CONNECTION) {
return baseClient.loadProcedure(sourceFiles, procedureType, procedureName, codeType, procedureDescription, readOnly, version, graph);
} else {
return doubleCheckQuery(()-> {
boolean succeed = leaderClient.loadProcedure(sourceFiles, procedureType, procedureName, codeType, procedureDescription, readOnly, version, graph);
//update procedure info
if (succeed) {
refreshUserDefinedProcedure();
}
return succeed;
});
}
}

public String listProcedures(String procedureType, String version, String graph) throws Exception {
if (clientType == ClientType.SINGLE_CONNECTION) {
return baseClient.listProcedures(procedureType, version, graph);
Expand Down Expand Up @@ -705,17 +721,35 @@ public boolean loadProcedure(String sourceFile,
String codeType,
String procedureDescription, boolean readOnly,
String version, String graph) throws IOException {
String[] sourceFiles = {sourceFile};
return loadProcedure(sourceFiles, procedureType, procedureName, codeType, procedureDescription, readOnly, version, graph);
}

public boolean loadProcedure(String[] sourceFiles,
String procedureType, String procedureName,
String codeType,
String procedureDescription, boolean readOnly,
String version, String graph) throws IOException {
Lgraph.PluginRequest.PluginType type =
"CPP".equals(procedureType) ? Lgraph.PluginRequest.PluginType.CPP : Lgraph.PluginRequest.PluginType.PYTHON;
Lgraph.LoadPluginRequest.CodeType cType =
"SO".equals(codeType) ? Lgraph.LoadPluginRequest.CodeType.SO :
"PY".equals(codeType) ? Lgraph.LoadPluginRequest.CodeType.PY :
"CPP".equals(codeType) ? Lgraph.LoadPluginRequest.CodeType.CPP :
Lgraph.LoadPluginRequest.CodeType.ZIP;
ByteString content = ByteString.copyFrom(Objects.requireNonNull(binaryFileReader(sourceFile)));
List<ByteString> contents = new ArrayList<ByteString>();
List<String> filenames = new ArrayList<String>();
for (String sourceFile : sourceFiles) {
ByteString content = ByteString.copyFrom(Objects.requireNonNull(binaryFileReader(sourceFile)));
contents.add(content);
String[] files = sourceFile.split("/");
String fn = files[files.length - 1];
filenames.add(fn);
}
Lgraph.LoadPluginRequest lpRequest =
Lgraph.LoadPluginRequest.newBuilder().setName(procedureName).setDesc(procedureDescription)
.setReadOnly(readOnly).setCode(content).setCodeType(cType).build();
.setReadOnly(readOnly).setCodeType(cType)
.addAllCode(contents).addAllFileName(filenames).build();
Lgraph.PluginRequest req =
Lgraph.PluginRequest.newBuilder().setType(type).setLoadPluginRequest(lpRequest).setGraph(graph).setVersion(version).build();
Lgraph.LGraphRequest request =
Expand Down
3 changes: 2 additions & 1 deletion rpc-client/src/main/proto/lgraph.proto
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,10 @@ message LoadPluginRequest {

required string name = 1;
required bool read_only = 2;
required bytes code = 3;
repeated bytes code = 3;
optional string desc = 4;
optional CodeType code_type = 5;
repeated string file_name = 6;
};

message LoadPluginResponse {};
Expand Down
Loading