diff --git a/flex/bin/load_plan_and_gen.sh b/flex/bin/load_plan_and_gen.sh index 3af35f30a25b..6f4df31706f6 100755 --- a/flex/bin/load_plan_and_gen.sh +++ b/flex/bin/load_plan_and_gen.sh @@ -136,6 +136,7 @@ cypher_to_plan() { # add extra_key_value_config extra_config="name:${procedure_name}" extra_config="${extra_config},description:${procedure_description}" + extra_config="${extra_config},type:cypher" cmd="java -cp ${COMPILER_LIB_DIR}/*:${COMPILER_JAR}" cmd="${cmd} -Dgraph.schema=${graph_schema_path}" diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/StoredProcedureMeta.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/StoredProcedureMeta.java index 1e63748fb1a0..432ac1f34989 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/StoredProcedureMeta.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/meta/procedure/StoredProcedureMeta.java @@ -41,6 +41,7 @@ public class StoredProcedureMeta { private final Mode mode; private final String description; private final String extension; + private final Map options; protected StoredProcedureMeta( String name, @@ -48,24 +49,32 @@ protected StoredProcedureMeta( String description, String extension, RelDataType returnType, - List parameters) { + List parameters, + Map options) { this.name = name; this.mode = mode; this.description = description; this.extension = extension; this.returnType = returnType; this.parameters = Objects.requireNonNull(parameters); + this.options = options; } public StoredProcedureMeta( - Configs configs, RelDataType returnType, List parameters) { + Configs configs, String queryStr, RelDataType returnType, List parameters) { + // For optional keys, construct a map and pass it to the constructor. this( Config.NAME.get(configs), Mode.valueOf(Config.MODE.get(configs)), Config.DESCRIPTION.get(configs), Config.EXTENSION.get(configs), returnType, - parameters); + parameters, + ImmutableMap.of( + Config.TYPE.getKey(), + Config.TYPE.get(configs), + Config.QUERY_STR.getKey(), + queryStr)); } public String getName() { @@ -80,6 +89,10 @@ public List getParameters() { return Collections.unmodifiableList(parameters); } + public Object getOption(String key) { + return options.getOrDefault(key, null); + } + @Override public String toString() { return "StoredProcedureMeta{" @@ -90,6 +103,8 @@ public String toString() { + returnType + ", parameters=" + parameters + + ", option=" + + options + '}'; } @@ -167,7 +182,9 @@ private static Map createProduceMetaMap(StoredProcedureMeta meta ImmutableMap.of( "name", k.getName(), "type", Utils.typeToStr(k.getType()))) - .collect(Collectors.toList())); + .collect(Collectors.toList()), + "option", + meta.options); } } @@ -181,7 +198,8 @@ public static StoredProcedureMeta perform(InputStream inputStream) throws IOExce (String) config.get("description"), (String) config.get("extension"), createReturnType((List) config.get("returns")), - createParameters((List) config.get("params"))); + createParameters((List) config.get("params")), + (Map) config.get("option")); } private static RelDataType createReturnType(List config) { @@ -230,5 +248,11 @@ public static class Config { com.alibaba.graphscope.common.config.Config.stringConfig("extension", ".so"); public static final com.alibaba.graphscope.common.config.Config MODE = com.alibaba.graphscope.common.config.Config.stringConfig("mode", "READ"); + // option configurations. + public static final com.alibaba.graphscope.common.config.Config TYPE = + com.alibaba.graphscope.common.config.Config.stringConfig( + "type", "UNKNOWN"); // cypher or cpp + public static final com.alibaba.graphscope.common.config.Config QUERY_STR = + com.alibaba.graphscope.common.config.Config.stringConfig("queryStr", "UNKNOWN"); } } diff --git a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java index 8691c2518b10..98dc085d47b8 100644 --- a/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java +++ b/interactive_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/tools/GraphPlanner.java @@ -293,7 +293,10 @@ public static void main(String[] args) throws Exception { Configs extraConfigs = createExtraConfigs(args.length > 4 ? args[4] : null); StoredProcedureMeta procedureMeta = new StoredProcedureMeta( - extraConfigs, logicalPlan.getOutputType(), logicalPlan.getDynamicParams()); + extraConfigs, + query, + logicalPlan.getOutputType(), + logicalPlan.getDynamicParams()); StoredProcedureMeta.Serializer.perform(procedureMeta, new FileOutputStream(args[3])); } } diff --git a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/config/YamlConfigTest.java b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/config/YamlConfigTest.java index d230d3c5f238..a158afa2b612 100644 --- a/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/config/YamlConfigTest.java +++ b/interactive_engine/compiler/src/test/java/com/alibaba/graphscope/common/config/YamlConfigTest.java @@ -41,8 +41,10 @@ public void procedure_config_test() throws Exception { StoredProcedureMeta meta = procedures.getStoredProcedure("ldbc_ic2"); Assert.assertEquals( "StoredProcedureMeta{name='ldbc_ic2', returnType=RecordType(CHAR(1) name)," - + " parameters=[Parameter{name='personId2', dataType=BIGINT}," - + " Parameter{name='maxDate', dataType=BIGINT}]}", + + " parameters=[Parameter{name='personId2', dataType=BIGINT}," + + " Parameter{name='maxDate', dataType=BIGINT}], option={type=cypher," + + " queryStr=MATCH(n: PERSON ${personId2}) WHERE n.creationDate < ${maxDate}" + + " RETURN n.firstName AS name LIMIT 10;}}", meta.toString()); } diff --git a/interactive_engine/compiler/src/test/resources/config/modern/plugins/ldbc_ic2.yaml b/interactive_engine/compiler/src/test/resources/config/modern/plugins/ldbc_ic2.yaml index ea7768bff5d3..2ec09e9637da 100644 --- a/interactive_engine/compiler/src/test/resources/config/modern/plugins/ldbc_ic2.yaml +++ b/interactive_engine/compiler/src/test/resources/config/modern/plugins/ldbc_ic2.yaml @@ -12,3 +12,6 @@ params: returns: - name: "name" type: "string" +option: # consistent with standard cypher procedure meta, use field 'option' to specify additional meta info. + type: cypher # cypher/cpp + queryStr: "MATCH(n: PERSON ${personId2}) WHERE n.creationDate < ${maxDate} RETURN n.firstName AS name LIMIT 10;"