-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(interactive): Fix
stored_procedure
parsing in old-version schem…
…a and refactor CI (#3853) - Fix the problem of procedure loading with schema of version v0.0. - Fix the related CI test. Two cpp procedures are added ```cpp class ExampleQuery : public CypherReadAppBase<int32_t>; class ReadExample : public ReadAppBase; ``` The first use `CypherJson` InputFormat, and the latter use `CppEncoder` format.
- Loading branch information
1 parent
2cafc1a
commit b0d81f5
Showing
9 changed files
with
309 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "flex/engines/graph_db/app/app_base.h" | ||
#include "flex/utils/app_utils.h" | ||
|
||
namespace gs { | ||
class PlusOne : public ReadAppBase { | ||
public: | ||
PlusOne() {} | ||
// Query function for query class | ||
bool Query(const gs::GraphDBSession& sess, Decoder& input, | ||
Encoder& output) override { | ||
int32_t param1 = input.get_int(); | ||
LOG(INFO) << "param1: " << param1; | ||
output.put_int(param1 + 1); | ||
return true; | ||
} | ||
}; | ||
} // namespace gs | ||
|
||
extern "C" { | ||
void* CreateApp(gs::PlusOne& db) { | ||
gs::PlusOne* app = new gs::PlusOne(); | ||
return static_cast<void*>(app); | ||
} | ||
|
||
void DeleteApp(void* app) { | ||
gs::PlusOne* casted = static_cast<gs::PlusOne*>(app); | ||
delete casted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2020 Alibaba Group Holding Limited. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
|
||
import os | ||
import sys | ||
|
||
sys.path.append("../../interactive/sdk/python") | ||
|
||
from interactive_sdk.client.driver import Driver | ||
from interactive_sdk.openapi.models.base_edge_type_vertex_type_pair_relations_inner import ( | ||
BaseEdgeTypeVertexTypePairRelationsInner, | ||
) | ||
from interactive_sdk.openapi.models.create_edge_type import CreateEdgeType | ||
from interactive_sdk.openapi.models.create_graph_request import CreateGraphRequest | ||
from interactive_sdk.openapi.models.create_graph_schema_request import ( | ||
CreateGraphSchemaRequest, | ||
) | ||
from interactive_sdk.openapi.models.create_procedure_request import ( | ||
CreateProcedureRequest, | ||
) | ||
from interactive_sdk.openapi.models.create_property_meta import CreatePropertyMeta | ||
from interactive_sdk.openapi.models.create_vertex_type import CreateVertexType | ||
from interactive_sdk.openapi.models.edge_mapping import EdgeMapping | ||
from interactive_sdk.openapi.models.edge_mapping_type_triplet import ( | ||
EdgeMappingTypeTriplet, | ||
) | ||
from interactive_sdk.openapi.models.gs_data_type import GSDataType | ||
from interactive_sdk.openapi.models.typed_value import TypedValue | ||
from interactive_sdk.openapi.models.job_status import JobStatus | ||
from interactive_sdk.openapi.models.long_text import LongText | ||
from interactive_sdk.openapi.models.primitive_type import PrimitiveType | ||
from interactive_sdk.openapi.models.schema_mapping import SchemaMapping | ||
from interactive_sdk.openapi.models.schema_mapping_loading_config import ( | ||
SchemaMappingLoadingConfig, | ||
) | ||
from interactive_sdk.openapi.models.schema_mapping_loading_config_format import ( | ||
SchemaMappingLoadingConfigFormat, | ||
) | ||
from interactive_sdk.openapi.models.start_service_request import StartServiceRequest | ||
from interactive_sdk.openapi.models.string_type import StringType | ||
from interactive_sdk.openapi.models.string_type_string import StringTypeString | ||
from interactive_sdk.openapi.models.vertex_mapping import VertexMapping | ||
from interactive_sdk.openapi.models.query_request import QueryRequest | ||
|
||
# Among the above procedures, the correct input format for each is: | ||
# count_vertex_num: () -> (num: int64), CypherProcedure. | ||
# plus_one: (num: int64) -> (num: int64), CppEncoder | ||
# sample_app: (num: int64) -> (num: int64), kCypherJson | ||
|
||
|
||
class ProcedureCaller(): | ||
def __init__(self, endpoint): | ||
self._driver = Driver(endpoint) | ||
self._sess = self._driver.session() | ||
|
||
def call_cypher_queries(self): | ||
with self._driver.getNeo4jSession() as session: | ||
result = session.run("CALL count_vertex_num();") | ||
print("call procedure result: ", result) | ||
|
||
def callProcedureWithJsonFormat(self, graph_id : str): | ||
# get_person_name | ||
sample_app_ref = QueryRequest( | ||
query_name="sample_app", | ||
arguments=[ | ||
TypedValue( | ||
type=GSDataType( | ||
PrimitiveType(primitive_type="DT_SIGNED_INT32") | ||
), | ||
value = 2 | ||
) | ||
] | ||
) | ||
resp = self._sess.call_procedure(graph_id, sample_app_ref) | ||
if not resp.is_ok(): | ||
print("call sample_app failed: ", resp.get_status_message()) | ||
exit(1) | ||
self.call_cypher_queries() | ||
|
||
def callProcedureWithEncoder(self, graph_id : str): | ||
# count_vertex_num, should be with id 1 | ||
# construct a byte array with bytes: 0x01 | ||
params = chr(1) | ||
resp = self._sess.call_procedure_raw(graph_id, params) | ||
if not resp.is_ok(): | ||
print("call count_vertex_num failed: ", resp.get_status_message()) | ||
exit(1) | ||
|
||
# plus_one, should be with id 3 | ||
# construct a byte array with bytes: the 4 bytes of integer 1, and a byte 3 | ||
byte_string = bytes([0,0,0,0,2]) # 4 bytes of integer 1, and a byte 3 | ||
params = byte_string.decode('utf-8') | ||
resp = self._sess.call_procedure_raw(graph_id, params) | ||
if not resp.is_ok(): | ||
print("call plus_one failed: ", resp.get_status_message()) | ||
exit(1) | ||
|
||
if __name__ == "__main__": | ||
#parse command line args | ||
import argparse | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--endpoint", type=str, default="http://localhost:7777") | ||
parser.add_argument("--graph_id", type=str, default="1") | ||
parser.add_argument("--input-format", type=str, default="json") | ||
#finish | ||
args = parser.parse_args() | ||
print(args) | ||
caller = ProcedureCaller(args.endpoint) | ||
if args.input_format == "json": | ||
caller.callProcedureWithJsonFormat(args.graph_id) | ||
elif args.input_format == "encoder": | ||
caller.callProcedureWithEncoder(args.graph_id) | ||
else: | ||
raise ValueError("Invalid input format: " + args.input_format) | ||
|
Oops, something went wrong.