Skip to content

Commit

Permalink
refactor(interactive): Add type and queryStr for StoredProcedureMeta (
Browse files Browse the repository at this point in the history
alibaba#3622)

Add optional field `type: cpp/cypher` and `queryStr: ` for stored
procedure's metadata. The queryStr could be cypher query or c++ code.
  • Loading branch information
zhanglei1949 authored Mar 13, 2024
1 parent a9f3e1a commit ac1eb75
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions flex/bin/load_plan_and_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,40 @@ public class StoredProcedureMeta {
private final Mode mode;
private final String description;
private final String extension;
private final Map<String, Object> options;

protected StoredProcedureMeta(
String name,
Mode mode,
String description,
String extension,
RelDataType returnType,
List<Parameter> parameters) {
List<Parameter> parameters,
Map<String, Object> 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<Parameter> parameters) {
Configs configs, String queryStr, RelDataType returnType, List<Parameter> 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() {
Expand All @@ -80,6 +89,10 @@ public List<Parameter> getParameters() {
return Collections.unmodifiableList(parameters);
}

public Object getOption(String key) {
return options.getOrDefault(key, null);
}

@Override
public String toString() {
return "StoredProcedureMeta{"
Expand All @@ -90,6 +103,8 @@ public String toString() {
+ returnType
+ ", parameters="
+ parameters
+ ", option="
+ options
+ '}';
}

Expand Down Expand Up @@ -167,7 +182,9 @@ private static Map<String, Object> createProduceMetaMap(StoredProcedureMeta meta
ImmutableMap.of(
"name", k.getName(),
"type", Utils.typeToStr(k.getType())))
.collect(Collectors.toList()));
.collect(Collectors.toList()),
"option",
meta.options);
}
}

Expand All @@ -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<String, Object>) config.get("option"));
}

private static RelDataType createReturnType(List config) {
Expand Down Expand Up @@ -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<String> MODE =
com.alibaba.graphscope.common.config.Config.stringConfig("mode", "READ");
// option configurations.
public static final com.alibaba.graphscope.common.config.Config<String> TYPE =
com.alibaba.graphscope.common.config.Config.stringConfig(
"type", "UNKNOWN"); // cypher or cpp
public static final com.alibaba.graphscope.common.config.Config<String> QUERY_STR =
com.alibaba.graphscope.common.config.Config.stringConfig("queryStr", "UNKNOWN");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;"

0 comments on commit ac1eb75

Please sign in to comment.