Skip to content
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
merged 9 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .linters/cpp/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,11 @@ def Check(self, error, filename, linenum):
# 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
if error_level > 5:
error_level = 5
error(filename, linenum, 'readability/fn_size', error_level,
'Small and focused functions are preferred:'
' %s has %d non-comment lines'
' (error triggered by exceeding %d lines).' % (
self.current_function, self.lines_in_function, trigger))
# error(filename, linenum, 'readability/fn_size', error_level,
# 'Small and focused functions are preferred:'
# ' %s has %d non-comment lines'
# ' (error triggered by exceeding %d lines).' % (
# self.current_function, self.lines_in_function, trigger))

def End(self):
"""Stop analyzing function body."""
Expand Down
1 change: 1 addition & 0 deletions src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ nebula_add_subdirectory(util)
nebula_add_subdirectory(validator)
nebula_add_subdirectory(visitor)
nebula_add_subdirectory(gc)
nebula_add_subdirectory(subgraph_provenance)
214 changes: 139 additions & 75 deletions src/graph/executor/algo/IsomorExecutor.cpp
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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this wrong?

}

// 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
12 changes: 12 additions & 0 deletions src/graph/planner/plan/Algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ class Isomor final : public SingleInputNode {
return qctx->objPool()->makeAndAdd<Isomor>(
qctx, input, dScanVOut, qScanVOut, dScanEOut, qScanEOut);
}
const std::string& getdScanVOut() const {
return dScanVOut_;
}
const std::string& getqScanVOut() const {
return qScanVOut_;
}
const std::string& getdScanEOut() const {
return dScanEOut_;
}
const std::string& getqScanEOut() const {
return qScanEOut_;
}

private:
friend ObjectPool;
Expand Down
10 changes: 10 additions & 0 deletions src/graph/subgraph_provenance/CMakeLists.txt
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
)
6 changes: 6 additions & 0 deletions src/graph/subgraph_provenance/README.md
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`
Loading