-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interactive): Support builtin app in Interactive (#4242)
This PR introduces support for built-in procedures in Interactive. Users can access these procedures as soon as the graph is created, with more built-in apps to be added in the future. For instance, a user can count the vertices of a specific label using: ```cypher call count_vertices("person"); ``` Please note that built-in procedures cannot be deleted or updated, and users cannot create procedures with the same name as a built-in procedure.
- Loading branch information
1 parent
36313cf
commit 56963cd
Showing
16 changed files
with
249 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* 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. | ||
*/ | ||
#include "flex/engines/graph_db/app/builtin/count_vertices.h" | ||
|
||
namespace gs { | ||
|
||
bool CountVertices::DoQuery(GraphDBSession& sess, Decoder& input, | ||
Encoder& output) { | ||
// First get the read transaction. | ||
auto txn = sess.GetReadTransaction(); | ||
// We expect one param of type string from decoder. | ||
if (input.empty()) { | ||
return false; | ||
} | ||
std::string label_name{input.get_string()}; | ||
const auto& schema = txn.schema(); | ||
if (!schema.has_vertex_label(label_name)) { | ||
output.put_string_view("The requested label doesn't exits."); | ||
return false; // The requested label doesn't exits. | ||
} | ||
auto label_id = schema.get_vertex_label_id(label_name); | ||
// The vertices are labeled internally from 0 ~ vertex_label_num, accumulate | ||
auto vertex_num = txn.GetVertexNum(label_id); | ||
// the count. | ||
results::CollectiveResults results; | ||
auto result = results.add_results(); | ||
result->mutable_record() | ||
->add_columns() | ||
->mutable_entry() | ||
->mutable_element() | ||
->mutable_object() | ||
->set_i32(vertex_num); | ||
|
||
output.put_string_view(results.SerializeAsString()); | ||
txn.Commit(); | ||
return true; | ||
} | ||
|
||
AppWrapper CountVerticesFactory::CreateApp(const GraphDB& db) { | ||
return AppWrapper(new CountVertices(), NULL); | ||
} | ||
} // namespace gs |
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,39 @@ | ||
/** Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#ifndef ENGINES_GRAPH_DB_APP_BUILDIN_COUNT_VERTICES_H_ | ||
#define ENGINES_GRAPH_DB_APP_BUILDIN_COUNT_VERTICES_H_ | ||
#include "flex/engines/graph_db/database/graph_db_session.h" | ||
#include "flex/engines/hqps_db/app/interactive_app_base.h" | ||
|
||
namespace gs { | ||
// A simple app to count the number of vertices of a given label. | ||
class CountVertices : public CypherInternalPbWriteAppBase { | ||
public: | ||
CountVertices() {} | ||
bool DoQuery(GraphDBSession& sess, Decoder& input, Encoder& output) override; | ||
}; | ||
|
||
class CountVerticesFactory : public AppFactoryBase { | ||
public: | ||
CountVerticesFactory() = default; | ||
~CountVerticesFactory() = default; | ||
|
||
AppWrapper CreateApp(const GraphDB& db) override; | ||
}; | ||
|
||
} // namespace gs | ||
|
||
#endif // ENGINES_GRAPH_DB_APP_BUILDIN_COUNT_VERTICES_H_ |
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
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
Oops, something went wrong.