-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zhanfu/csr Framework for the CSR structure #4688
Merged
wenhaocs
merged 9 commits into
vesoft-inc:release-3.2-subgraphmatch
from
peter-rich:zhanfu/csr
Oct 27, 2022
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d1f5588
geet data
peter-rich f65e863
new csr structure
peter-rich c66c8fa
new api for edge and vertex
peter-rich d60470b
offset
peter-rich f890de8
fix subgraph.cpp
peter-rich 6abc99b
Run subgraph algorithm
peter-rich a8d21ad
new
peter-rich d1b7544
add comment fo offset and neighborhood
peter-rich 654d489
change degree
peter-rich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,152 @@ | ||
// Copyright (c) 2020 vesoft inc. All rights reserved. | ||
// | ||
// This source code is licensed under Apache 2.0 License. | ||
|
||
#include "graph/executor/algo/IsomorExecutor.h" | ||
|
||
#include "graph/planner/plan/Algo.h" | ||
#include <fstream> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "graph/planner/plan/Algo.h" | ||
#include "graph/subgraph_provenance/graph.h" | ||
#include "graph/subgraph_provenance/subgraph.h" | ||
namespace nebula { | ||
namespace graph { | ||
|
||
static const char kDefaultProp[] = "default"; // | ||
|
||
folly::Future<Status> IsomorExecutor::execute() { | ||
// TODO: Replace the following codes with subgraph matching. Return type. | ||
SCOPED_TIMER(&execTime_); | ||
auto* subgraph = asNode<Subgraph>(node()); | ||
DataSet ds; | ||
ds.colNames = subgraph->colNames(); | ||
|
||
uint32_t steps = subgraph->steps(); | ||
const auto& currentStepVal = ectx_->getValue(subgraph->currentStepVar()); | ||
DCHECK(currentStepVal.isInt()); | ||
auto currentStep = currentStepVal.getInt(); | ||
auto resultVar = subgraph->resultVar(); | ||
|
||
auto iter = ectx_->getResult(subgraph->inputVar()).iter(); | ||
auto gnSize = iter->size(); | ||
|
||
ResultBuilder builder; | ||
builder.value(iter->valuePtr()); | ||
|
||
std::unordered_map<Value, int64_t> currentVids; | ||
currentVids.reserve(gnSize); | ||
historyVids_.reserve(historyVids_.size() + gnSize); | ||
if (currentStep == 1) { | ||
for (; iter->valid(); iter->next()) { | ||
const auto& src = iter->getColumn(nebula::kVid); | ||
currentVids.emplace(src, 0); | ||
} | ||
iter->reset(); | ||
} | ||
auto& biDirectEdgeTypes = subgraph->biDirectEdgeTypes(); | ||
while (iter->valid()) { | ||
const auto& dst = iter->getEdgeProp("*", nebula::kDst); | ||
auto findIter = historyVids_.find(dst); | ||
if (findIter != historyVids_.end()) { | ||
if (biDirectEdgeTypes.empty()) { | ||
iter->next(); | ||
} else { | ||
const auto& typeVal = iter->getEdgeProp("*", nebula::kType); | ||
if (UNLIKELY(!typeVal.isInt())) { | ||
iter->erase(); | ||
continue; | ||
} | ||
auto type = typeVal.getInt(); | ||
if (biDirectEdgeTypes.find(type) != biDirectEdgeTypes.end()) { | ||
if (type < 0 || findIter->second + 2 == currentStep) { | ||
iter->erase(); | ||
} else { | ||
iter->next(); | ||
} | ||
} else { | ||
iter->next(); | ||
} | ||
} | ||
} else { | ||
if (currentStep == steps) { | ||
iter->erase(); | ||
continue; | ||
} | ||
if (currentVids.emplace(dst, currentStep).second) { | ||
Row row; | ||
row.values.emplace_back(std::move(dst)); | ||
ds.rows.emplace_back(std::move(row)); | ||
} | ||
iter->next(); | ||
} | ||
} | ||
iter->reset(); | ||
builder.iter(std::move(iter)); | ||
ectx_->setResult(resultVar, builder.build()); | ||
// update historyVids | ||
historyVids_.insert(std::make_move_iterator(currentVids.begin()), | ||
std::make_move_iterator(currentVids.end())); | ||
return finish(ResultBuilder().value(Value(std::move(ds))).build()); | ||
} | ||
// TODO: Replace the following codes with subgraph matching. Return type. | ||
// Define 2: | ||
SCOPED_TIMER(&execTime_); | ||
auto* isomor = asNode<Isomor>(node()); | ||
DataSet ds; | ||
ds.colNames = isomor->colNames(); | ||
auto iterDV = ectx_->getResult(isomor->getdScanVOut()).iter(); | ||
auto iterQV = ectx_->getResult(isomor->getqScanVOut()).iter(); | ||
auto iterDE = ectx_->getResult(isomor->getdScanEOut()).iter(); | ||
auto iterQE = ectx_->getResult(isomor->getqScanEOut()).iter(); | ||
unsigned int v_count = iterDV->size(); | ||
unsigned int l_count = iterDV->size(); | ||
unsigned int e_count = iterDE->size(); | ||
unsigned int* offset = new unsigned int[v_count + 2]; | ||
unsigned int* neighbors = new unsigned int[e_count * 2]; | ||
unsigned int* labels = new unsigned int[l_count]; | ||
// load data vertices id and tags | ||
while (iterDV->valid()) { | ||
const auto vertex = iterDV->getColumn(nebula::kVid); // check if v is a vertex | ||
auto v_id = vertex.getInt(); | ||
const auto label = iterDV->getColumn(nebula::graph::kDefaultProp); // get label by index | ||
auto l_id = label.getInt(); | ||
// unsigned int v_id = (unsigned int)v.getInt(0); | ||
labels[v_id] = l_id; // Tag Id | ||
iterDV->next(); | ||
} | ||
// load edges degree | ||
while (iterDE->valid()) { | ||
auto s = iterDE->getEdgeProp("*", kSrc); | ||
unsigned int src = s.getInt(); | ||
offset[src]++; | ||
iterDE->next(); | ||
} | ||
for (unsigned int i = 0; i < v_count; i++) { | ||
offset[i + 1] = offset[i]; | ||
} | ||
|
||
// load data edges | ||
offset[0] = 0; | ||
iterDE = ectx_->getResult(isomor->getdScanEOut()).iter(); | ||
while (iterDE->valid()) { | ||
unsigned int src = iterDE->getEdgeProp("*", kSrc).getInt(); | ||
unsigned int dst = iterDE->getEdgeProp("*", kDst).getInt(); | ||
|
||
neighbors[offset[src + 1]] = dst; | ||
offset[src + 1]++; | ||
iterDE->next(); | ||
} | ||
for (unsigned int i = 0; i < v_count; i++) { | ||
offset[i + 1] = offset[i]; | ||
} | ||
|
||
Graph* data_graph = new Graph(); | ||
data_graph->loadGraphFromExecutor(v_count, l_count, e_count, offset, neighbors, labels); | ||
|
||
// load query vertices id and tags | ||
while (iterQV->valid()) { | ||
const auto vertex = iterQV->getColumn(nebula::kVid); // check if v is a vertex | ||
auto v_id = vertex.getInt(); | ||
const auto label = iterQV->getColumn(nebula::graph::kDefaultProp); // get label by index | ||
auto l_id = label.getInt(); | ||
// unsigned int v_id = (unsigned int)v.getInt(0); | ||
labels[v_id] = l_id; // Tag Id | ||
iterQV->next(); | ||
} | ||
|
||
// load query edges degree | ||
while (iterQE->valid()) { | ||
auto s = iterQE->getEdgeProp("*", kSrc); | ||
unsigned int src = s.getInt(); | ||
offset[src]++; | ||
iterDE->next(); | ||
} | ||
for (unsigned int i = 0; i < v_count; i++) { | ||
offset[i + 1] = offset[i]; | ||
} | ||
|
||
// load query edges | ||
offset[0] = 0; | ||
iterQE = ectx_->getResult(isomor->getdScanEOut()).iter(); | ||
while (iterDE->valid()) { | ||
unsigned int src = iterQE->getEdgeProp("*", kSrc).getInt(); | ||
unsigned int dst = iterQE->getEdgeProp("*", kDst).getInt(); | ||
|
||
neighbors[offset[src + 1]] = dst; | ||
offset[src + 1]++; | ||
iterQE->next(); | ||
} | ||
for (unsigned int i = 0; i < v_count; i++) { | ||
offset[i + 1] = offset[i]; | ||
} | ||
|
||
Graph* query_graph = new Graph(); | ||
query_graph->loadGraphFromExecutor(v_count, l_count, e_count, offset, neighbors, labels); | ||
|
||
ui** candidates = nullptr; | ||
ui* candidates_count = nullptr; | ||
|
||
TreeNode* ceci_tree = nullptr; | ||
ui* ceci_order = nullptr; | ||
ui* provenance = nullptr; | ||
|
||
std::vector<std::unordered_map<V_ID, std::vector<V_ID>>> | ||
P_Candidates; // Parent, first branch, second branch. | ||
std::vector<std::unordered_map<V_ID, std::vector<V_ID>>> P_Provenance; | ||
// std::cout"Provenance Function: " << std::endl:endl; | ||
|
||
bool result = CECIFunction(data_graph, | ||
query_graph, | ||
candidates, | ||
candidates_count, | ||
ceci_order, | ||
provenance, | ||
ceci_tree, | ||
P_Candidates, | ||
P_Provenance); | ||
delete data_graph; | ||
delete query_graph; | ||
delete[] ceci_order; | ||
delete[] provenance; | ||
delete[] candidates_count; | ||
delete[] candidates; | ||
delete ceci_tree; | ||
|
||
delete[] offset; | ||
delete[] neighbors; | ||
delete[] labels; | ||
ResultBuilder builder; | ||
|
||
// Set result in the ds and set the new column name for the (isomor matching 's) result. | ||
return finish(ResultBuilder().value(Value(std::move(result))).build()); | ||
} | ||
} // namespace graph | ||
} // namespace nebula |
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,10 @@ | ||
# Copyright (c) 2020 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License. | ||
|
||
nebula_add_library( | ||
executor_provenance OBJECT | ||
ceci.cpp | ||
graph.cpp | ||
subgraph.cpp | ||
) |
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,6 @@ | ||
# subgraph_provenance | ||
|
||
|
||
`make all` | ||
|
||
`./ceci test/sample_dataset/query.graph test/sample_dataset/data.graph` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this wrong?