diff --git a/pom.xml b/pom.xml
index f51b085d..98bfa33f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -305,6 +305,11 @@
QLExpress
3.3.2
+
+ commons-cli
+ commons-cli
+ 1.6.0
+
diff --git a/reasoner/runner/local-runner/pom.xml b/reasoner/runner/local-runner/pom.xml
index 15e4f8b4..b3f937a5 100644
--- a/reasoner/runner/local-runner/pom.xml
+++ b/reasoner/runner/local-runner/pom.xml
@@ -114,6 +114,10 @@
com.antgroup.openspg.reasoner
reasoner-common
+
+ commons-cli
+ commons-cli
+
diff --git a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/KGReasonerLocalRunner.java b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/KGReasonerLocalRunner.java
index 61c3d15c..8847d212 100644
--- a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/KGReasonerLocalRunner.java
+++ b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/KGReasonerLocalRunner.java
@@ -57,7 +57,7 @@ public class KGReasonerLocalRunner {
return doRun(task);
} catch (Throwable e) {
log.error("KGReasonerLocalRunner,error", e);
- return new LocalReasonerResult("KGReasonerLocalRunner,error " + e.getMessage());
+ return new LocalReasonerResult("KGReasonerLocalRunner,error:" + e.getMessage());
}
}
@@ -179,11 +179,23 @@ public class KGReasonerLocalRunner {
String graphLoadClass = task.getGraphLoadClass();
MemGraphState memGraphState = new MemGraphState();
AbstractLocalGraphLoader graphLoader;
- try {
- graphLoader =
- (AbstractLocalGraphLoader) Class.forName(graphLoadClass).getConstructor().newInstance();
- } catch (Exception e) {
- throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
+ if (StringUtils.isEmpty(task.getGraphStateInitString())) {
+ try {
+ graphLoader =
+ (AbstractLocalGraphLoader) Class.forName(graphLoadClass).getConstructor().newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
+ }
+ } else {
+ try {
+ graphLoader =
+ (AbstractLocalGraphLoader)
+ Class.forName(graphLoadClass)
+ .getConstructor(String.class)
+ .newInstance(task.getGraphStateInitString());
+ } catch (Exception e) {
+ throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
+ }
}
graphLoader.setGraphState(memGraphState);
graphLoader.load();
diff --git a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/LocalRunnerMain.java b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/LocalRunnerMain.java
index 1728fd42..dbf32c8b 100644
--- a/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/LocalRunnerMain.java
+++ b/reasoner/runner/local-runner/src/main/java/com/antgroup/openspg/reasoner/runner/local/LocalRunnerMain.java
@@ -14,26 +14,214 @@
package com.antgroup.openspg.reasoner.runner.local;
import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.antgroup.openspg.reasoner.catalog.impl.KgSchemaConnectionInfo;
import com.antgroup.openspg.reasoner.runner.local.model.LocalReasonerResult;
import com.antgroup.openspg.reasoner.runner.local.model.LocalReasonerTask;
+import com.opencsv.CSVWriter;
+import java.io.FileWriter;
+import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.Base64;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.DefaultParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.lang3.StringUtils;
@Slf4j
public class LocalRunnerMain {
- /** result */
- public static LocalReasonerResult result = null;
-
/** KGReasoner main */
public static void main(String[] args) {
- String taskInfoJson = new String(Base64.getDecoder().decode(args[0]), StandardCharsets.UTF_8);
- LocalReasonerTask task = JSON.parseObject(taskInfoJson, LocalReasonerTask.class);
+ LocalReasonerTask task = parseArgs(args);
+ if (null == task) {
+ System.exit(1);
+ }
KGReasonerLocalRunner runner = new KGReasonerLocalRunner();
- result = runner.run(task);
- if (null != result) {
- log.info(result.toString());
+ LocalReasonerResult result = runner.run(task);
+ if (null == result) {
+ log.error("local runner return null");
+ return;
+ }
+ if (StringUtils.isNotEmpty(result.getErrMsg())) {
+ log.error(result.getErrMsg());
+ }
+ if (StringUtils.isNotEmpty(task.getOutputFile())) {
+ writeOutputFile(result, task.getOutputFile());
}
}
+
+ private static void writeOutputFile(LocalReasonerResult result, String file) {
+ Path path = Paths.get(file);
+ try {
+ if (Files.notExists(path.getParent())) {
+ Files.createDirectories(path.getParent());
+ }
+ if (Files.exists(path)) {
+ Files.delete(path);
+ }
+ } catch (IOException e) {
+ log.error("write result file error, file=" + file, e);
+ return;
+ }
+
+ if (StringUtils.isNotEmpty(result.getErrMsg())) {
+ writeFile(path, result.getErrMsg());
+ } else if (result.isGraphResult()) {
+ // write graph result
+ writeFile(path, result.toString());
+ } else {
+ // write csv
+ writeCsv(path, result.getColumns(), result.getRows());
+ }
+ }
+
+ private static void writeCsv(Path path, List columns, List