local runner support specify a graph state class name

This commit is contained in:
youdonghai 2023-12-21 10:16:27 +08:00
parent 52ca5d8a4d
commit 1eadad5ddd
3 changed files with 24 additions and 18 deletions

View File

@ -176,26 +176,28 @@ public class KGReasonerLocalRunner {
return graphState; return graphState;
} }
String graphLoadClass = task.getGraphLoadClass(); String graphStateClass = task.getGraphStateClassName();
MemGraphState memGraphState = new MemGraphState(); if (StringUtils.isNotEmpty(graphStateClass)) {
AbstractLocalGraphLoader graphLoader;
if (StringUtils.isEmpty(task.getGraphStateInitString())) {
try { try {
graphLoader = graphState =
(AbstractLocalGraphLoader) Class.forName(graphLoadClass).getConstructor().newInstance(); (GraphState<IVertexId>)
} catch (Exception e) { Class.forName(graphStateClass)
throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e);
}
} else {
try {
graphLoader =
(AbstractLocalGraphLoader)
Class.forName(graphLoadClass)
.getConstructor(String.class) .getConstructor(String.class)
.newInstance(task.getGraphStateInitString()); .newInstance(task.getGraphStateInitString());
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("can not create graph loader from name " + graphLoadClass, e); throw new RuntimeException("can not create graph state from name " + graphStateClass, e);
} }
return graphState;
}
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);
} }
graphLoader.setGraphState(memGraphState); graphLoader.setGraphState(memGraphState);
graphLoader.load(); graphLoader.load();

View File

@ -217,7 +217,7 @@ public class LocalRunnerMain {
task.setDsl(dsl); task.setDsl(dsl);
task.setOutputFile(outputFile); task.setOutputFile(outputFile);
task.setConnInfo(new KgSchemaConnectionInfo(schemaUri, schemaToken)); task.setConnInfo(new KgSchemaConnectionInfo(schemaUri, schemaToken));
task.setGraphLoadClass(graphStateClass); task.setGraphStateClassName(graphStateClass);
task.setGraphStateInitString(graphStateUrl); task.setGraphStateInitString(graphStateUrl);
task.setStartIdList(new ArrayList<>()); task.setStartIdList(new ArrayList<>());
task.addStartId(startIdList); task.addStartId(startIdList);

View File

@ -51,12 +51,16 @@ public class LocalReasonerTask implements Serializable {
private KgSchemaConnectionInfo connInfo = null; private KgSchemaConnectionInfo connInfo = null;
private String schemaString = null; private String schemaString = null;
/** Choose between graphLoadClass or graphState */ /** Choose between graphLoadClass and graphState, or specify a class name */
private String graphLoadClass = null; private String graphLoadClass = null;
private String graphStateInitString = null;
private GraphState<IVertexId> graphState = null; private GraphState<IVertexId> graphState = null;
/** User specified the name of graphstate */
private String graphStateClassName = null;
private String graphStateInitString = null;
/** start id from input */ /** start id from input */
private List<Tuple2<String, String>> startIdList; private List<Tuple2<String, String>> startIdList;