Skip to content

Commit

Permalink
Merge branch 'master' into fix/rewrite-edge-filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg authored Nov 23, 2022
2 parents a95430f + 77f13a1 commit e3679de
Show file tree
Hide file tree
Showing 64 changed files with 483 additions and 180 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,30 @@ jobs:
esac
- name: Make
run: |
ccache -z
ninja -j $(nproc)
ccache -s
case ${{ matrix.compiler }} in
gcc-*)
case ${{ matrix.os }} in
centos7)
# build with Release type
ccache -z
ninja -j $(nproc)
ccache -s
;;
ubuntu2004)
# build with Debug type
ccache -z
ninja -j $(($(nproc)/2+1))
ccache -s
;;
esac
;;
clang-*)
# build with Sanitizer
ccache -z
ninja -j $(nproc)
ccache -s
;;
esac
working-directory: build/
- name: CTest
env:
Expand Down
2 changes: 1 addition & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ NebulaGraph内核 1.x 与 2.x 数据格式、通信协议、客户端等均双

## 加入 NebulaGraph 社区

[![Discussions](https://img.shields.io/badge/GitHub_Discussion-000000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/vesoft-inc/nebula/discussions) [![Discourse](https://img.shields.io/badge/中文论坛-4285F4?style=for-the-badge&logo=discourse&logoColor=white)](https://discuss.nebula-graph.com.cn/) [![Slack](https://img.shields.io/badge/Slack-9F2B68?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/nebulagraph/shared_invite/zt-7ybejuqa-NCZBroh~PCh66d9kOQj45g) [![Tecent_Meeting](https://img.shields.io/badge/腾讯会议-2D8CFF?style=for-the-badge&logo=googlemeet&logoColor=white)](https://meeting.tencent.com/dm/F8NX1aRZ8PQv) [![Google Calendar](https://img.shields.io/badge/Calander-4285F4?style=for-the-badge&logo=google&logoColor=white)](https://calendar.google.com/calendar/u/0?cid=Z29mbGttamM3ZTVlZ2hpazI2cmNlNXVnZThAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) [![Meetup](https://img.shields.io/badge/Meetup-FF0000?style=for-the-badge&logo=meetup&logoColor=white)](https://www.meetup.com/nebulagraph/events/287180186?utm_medium=referral&utm_campaign=share-btn_savedevents_share_modal&utm_source=link) [![Meeting Archive](https://img.shields.io/badge/Community_wiki-808080?style=for-the-badge&logo=readthedocs&logoColor=white)](https://github.com/vesoft-inc/nebula-community/wiki)
[![Discussions](https://img.shields.io/badge/GitHub_Discussion-000000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/vesoft-inc/nebula/discussions) [![Discourse](https://img.shields.io/badge/中文论坛-4285F4?style=for-the-badge&logo=discourse&logoColor=white)](https://discuss.nebula-graph.com.cn/) [![Slack](https://img.shields.io/badge/Slack-9F2B68?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/nebulagraph/shared_invite/zt-7ybejuqa-NCZBroh~PCh66d9kOQj45g) [![Tencent_Meeting](https://img.shields.io/badge/腾讯会议-2D8CFF?style=for-the-badge&logo=googlemeet&logoColor=white)](https://meeting.tencent.com/dm/F8NX1aRZ8PQv) [![Google Calendar](https://img.shields.io/badge/Calander-4285F4?style=for-the-badge&logo=google&logoColor=white)](https://calendar.google.com/calendar/u/0?cid=Z29mbGttamM3ZTVlZ2hpazI2cmNlNXVnZThAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) [![Meetup](https://img.shields.io/badge/Meetup-FF0000?style=for-the-badge&logo=meetup&logoColor=white)](https://www.meetup.com/nebulagraph/events/287180186?utm_medium=referral&utm_campaign=share-btn_savedevents_share_modal&utm_source=link) [![Meeting Archive](https://img.shields.io/badge/Community_wiki-808080?style=for-the-badge&logo=readthedocs&logoColor=white)](https://github.com/vesoft-inc/nebula-community/wiki)

<br />

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ You can also freely deploy **NebulaGraph** as a back-end service to support your

## Community

[![Discussions](https://img.shields.io/badge/GitHub_Discussion-000000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/vesoft-inc/nebula/discussions) [![Slack](https://img.shields.io/badge/Slack-9F2B68?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/nebulagraph/shared_invite/zt-7ybejuqa-NCZBroh~PCh66d9kOQj45g) [![Zoom](https://img.shields.io/badge/Zoom-2D8CFF?style=for-the-badge&logo=zoom&logoColor=white)](https://us02web.zoom.us/meeting/register/tZ0rcuypqDMvGdLuIm4VprTlx96wrEf062SH) [![Google Calendar](https://img.shields.io/badge/Calander-4285F4?style=for-the-badge&logo=google&logoColor=white)](https://calendar.google.com/calendar/u/0?cid=Z29mbGttamM3ZTVlZ2hpazI2cmNlNXVnZThAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) [![Meetup](https://img.shields.io/badge/Meetup-FF0000?style=for-the-badge&logo=meetup&logoColor=white)](https://www.meetup.com/nebulagraph/events/287180186?utm_medium=referral&utm_campaign=share-btn_savedevents_share_modal&utm_source=link) [![Meeting Archive](https://img.shields.io/badge/Community_wiki-808080?style=for-the-badge&logo=readthedocs&logoColor=white)](https://github.com/vesoft-inc/nebula-community/wiki) [![Discourse](https://img.shields.io/badge/中文论坛-4285F4?style=for-the-badge&logo=discourse&logoColor=white)](https://discuss.nebula-graph.com.cn/) [![Tecent_Meeting](https://img.shields.io/badge/腾讯会议-2D8CFF?style=for-the-badge&logo=googlemeet&logoColor=white)](https://meeting.tencent.com/dm/F8NX1aRZ8PQv)
[![Discussions](https://img.shields.io/badge/GitHub_Discussion-000000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/vesoft-inc/nebula/discussions) [![Slack](https://img.shields.io/badge/Slack-9F2B68?style=for-the-badge&logo=slack&logoColor=white)](https://join.slack.com/t/nebulagraph/shared_invite/zt-7ybejuqa-NCZBroh~PCh66d9kOQj45g) [![Zoom](https://img.shields.io/badge/Zoom-2D8CFF?style=for-the-badge&logo=zoom&logoColor=white)](https://us02web.zoom.us/meeting/register/tZ0rcuypqDMvGdLuIm4VprTlx96wrEf062SH) [![Google Calendar](https://img.shields.io/badge/Calander-4285F4?style=for-the-badge&logo=google&logoColor=white)](https://calendar.google.com/calendar/u/0?cid=Z29mbGttamM3ZTVlZ2hpazI2cmNlNXVnZThAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) [![Meetup](https://img.shields.io/badge/Meetup-FF0000?style=for-the-badge&logo=meetup&logoColor=white)](https://www.meetup.com/nebulagraph/events/287180186?utm_medium=referral&utm_campaign=share-btn_savedevents_share_modal&utm_source=link) [![Meeting Archive](https://img.shields.io/badge/Community_wiki-808080?style=for-the-badge&logo=readthedocs&logoColor=white)](https://github.com/vesoft-inc/nebula-community/wiki) [![Discourse](https://img.shields.io/badge/中文论坛-4285F4?style=for-the-badge&logo=discourse&logoColor=white)](https://discuss.nebula-graph.com.cn/) [![Tencent_Meeting](https://img.shields.io/badge/腾讯会议-2D8CFF?style=for-the-badge&logo=googlemeet&logoColor=white)](https://meeting.tencent.com/dm/F8NX1aRZ8PQv)

<br />

Expand Down
2 changes: 1 addition & 1 deletion docs/rfcs/0000-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ A few examples of what this can include are:
- For practical proposals: Does this feature exist in other database and what experience have their community had?
- Papers: Are there any published papers or great posts that discuss this? If you have some relevant papers to refer to, this can serve as a more detailed theoretical background.

The proposal won't accepted for they are in other projects, but this will show we more productive meaning.
The proposal won't be accepted for they are in other projects, but this will show us more productive meaning.

# Unresolved questions

Expand Down
7 changes: 7 additions & 0 deletions src/common/context/ExpressionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class ExpressionContext {
// Get the latest version value for the given variable name, such as $a, $b
virtual const Value& getVar(const std::string& var) const = 0;

// Set the value of innerVar. The innerVar is a variable defined in an expression.
// e.g. ListComprehension
virtual void setInnerVar(const std::string& var, Value val) = 0;

// Get the value of innerVar.
virtual const Value& getInnerVar(const std::string& var) const = 0;

// Get the given version value for the given variable name, such as $a, $b
virtual const Value& getVersionedVar(const std::string& var, int64_t version) const = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/common/expression/ListComprehensionExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Value& ListComprehensionExpression::eval(ExpressionContext& ctx) {

for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
if (filter_ != nullptr) {
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
Expand Down
8 changes: 4 additions & 4 deletions src/common/expression/PredicateExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
result_ = true;
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
return Value::kNullBadType;
Expand All @@ -104,7 +104,7 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
result_ = false;
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
return Value::kNullBadType;
Expand All @@ -120,7 +120,7 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
result_ = false;
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
return Value::kNullBadType;
Expand All @@ -140,7 +140,7 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
result_ = true;
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
return Value::kNullBadType;
Expand Down
8 changes: 4 additions & 4 deletions src/common/expression/ReduceExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const Value& ReduceExpression::eval(ExpressionContext& ctx) {
}
auto& list = listVal.getList();

ctx.setVar(accumulator_, initVal);
ctx.setInnerVar(accumulator_, initVal);
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setVar(innerVar_, v);
ctx.setInnerVar(innerVar_, v);
auto& mappingVal = mapping_->eval(ctx);
ctx.setVar(accumulator_, mappingVal);
ctx.setInnerVar(accumulator_, mappingVal);
}

result_ = ctx.getVar(accumulator_);
result_ = ctx.getInnerVar(accumulator_);
return result_;
}

Expand Down
3 changes: 3 additions & 0 deletions src/common/expression/VariableExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace nebula {
const Value& VariableExpression::eval(ExpressionContext& ctx) {
if (isInner_) {
return ctx.getInnerVar(var_);
}
return ctx.getVar(var_);
}

Expand Down
15 changes: 10 additions & 5 deletions src/common/expression/VariableExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
namespace nebula {
class VariableExpression final : public Expression {
public:
static VariableExpression* make(ObjectPool* pool,
const std::string& var = "",
bool isInner = false) {
return pool->makeAndAdd<VariableExpression>(pool, var, isInner);
// Make a non-inner variable expression
static VariableExpression* make(ObjectPool* pool, const std::string& var = "") {
return pool->makeAndAdd<VariableExpression>(pool, var, false);
}

// Make a inner variable expression. Inner variable is a variable defined in an expression.
// e.g. ListComprehensionExpression [i IN range(1, 10) | i+1]
static VariableExpression* makeInner(ObjectPool* pool, const std::string& var = "") {
return pool->makeAndAdd<VariableExpression>(pool, var, true);
}

const std::string& var() const {
Expand All @@ -39,7 +44,7 @@ class VariableExpression final : public Expression {
void accept(ExprVisitor* visitor) override;

Expression* clone() const override {
return VariableExpression::make(pool_, var(), isInner_);
return pool_->makeAndAdd<VariableExpression>(pool_, var(), isInner_);
}

private:
Expand Down
12 changes: 12 additions & 0 deletions src/common/expression/test/ExpressionContextMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class ExpressionContextMock final : public ExpressionContext {
}
}

void setInnerVar(const std::string& var, Value val) override {
exprValueMap_[var] = std::move(val);
}

const Value& getInnerVar(const std::string& var) const override {
auto it = exprValueMap_.find(var);
DCHECK(it != exprValueMap_.end());
return it->second;
}

const Value& getVersionedVar(const std::string& var, int64_t version) const override {
auto found = indices_.find(var);
if (found == indices_.end()) {
Expand Down Expand Up @@ -143,5 +153,7 @@ class ExpressionContextMock final : public ExpressionContext {
static std::unordered_map<std::string, std::size_t> indices_;
static std::vector<Value> vals_;
std::unordered_map<std::string, std::regex> regex_;
// Expression value map that stores the value of innerVar
std::unordered_map<std::string, Value> exprValueMap_;
};
} // namespace nebula
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ TEST_F(ListComprehensionExpressionTest, ListComprehensionEvaluate) {
"n",
ListExpression::make(&pool, listItems),
RelationalExpression::makeGE(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 2)),
&pool, VariableExpression::makeInner(&pool, "n"), ConstantExpression::make(&pool, 2)),
ArithmeticExpression::makeAdd(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 10)));
&pool, VariableExpression::makeInner(&pool, "n"), ConstantExpression::make(&pool, 10)));

auto value = Expression::eval(expr, gExpCtxt);
List expected;
Expand Down Expand Up @@ -57,7 +57,7 @@ TEST_F(ListComprehensionExpressionTest, ListComprehensionEvaluate) {
ArithmeticExpression::makeAdd(
&pool,
AttributeExpression::make(&pool,
VariableExpression::make(&pool, "n"),
VariableExpression::makeInner(&pool, "n"),
ConstantExpression::make(&pool, "age")),
ConstantExpression::make(&pool, 5)));

Expand Down
10 changes: 5 additions & 5 deletions src/common/expression/test/PredicateExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_F(PredicateExpressionTest, PredicateEvaluate) {
"n",
ListExpression::make(&pool, listItems),
RelationalExpression::makeGE(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 2)));
&pool, VariableExpression::makeInner(&pool, "n"), ConstantExpression::make(&pool, 2)));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isBool());
Expand All @@ -51,7 +51,7 @@ TEST_F(PredicateExpressionTest, PredicateEvaluate) {
RelationalExpression::makeGE(
&pool,
AttributeExpression::make(&pool,
VariableExpression::make(&pool, "n"),
VariableExpression::makeInner(&pool, "n"),
ConstantExpression::make(&pool, "age")),
ConstantExpression::make(&pool, 19)));

Expand All @@ -74,7 +74,7 @@ TEST_F(PredicateExpressionTest, PredicateEvaluate) {
"n",
ListExpression::make(&pool, listItems),
RelationalExpression::makeEQ(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 2)));
&pool, VariableExpression::makeInner(&pool, "n"), ConstantExpression::make(&pool, 2)));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isBool());
Expand All @@ -101,7 +101,7 @@ TEST_F(PredicateExpressionTest, PredicateEvaluate) {
RelationalExpression::makeGE(
&pool,
AttributeExpression::make(&pool,
VariableExpression::make(&pool, "n"),
VariableExpression::makeInner(&pool, "n"),
ConstantExpression::make(&pool, "age")),
ConstantExpression::make(&pool, 19)));

Expand All @@ -117,7 +117,7 @@ TEST_F(PredicateExpressionTest, PredicateEvaluate) {
"n",
ConstantExpression::make(&pool, Value(NullType::__NULL__)),
RelationalExpression::makeEQ(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 1)));
&pool, VariableExpression::makeInner(&pool, "n"), ConstantExpression::make(&pool, 1)));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_EQ(Value::kNullValue, value.getNull());
Expand Down
7 changes: 4 additions & 3 deletions src/common/expression/test/ReduceExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ TEST_F(ReduceExpressionTest, ReduceEvaluate) {
FunctionCallExpression::make(&pool, "range", argList),
ArithmeticExpression::makeAdd(
&pool,
VariableExpression::make(&pool, "totalNum"),
ArithmeticExpression::makeMultiply(
&pool, VariableExpression::make(&pool, "n"), ConstantExpression::make(&pool, 2))));
VariableExpression::makeInner(&pool, "totalNum"),
ArithmeticExpression::makeMultiply(&pool,
VariableExpression::makeInner(&pool, "n"),
ConstantExpression::make(&pool, 2))));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_EQ(Value::Type::INT, value.type());
Expand Down
9 changes: 9 additions & 0 deletions src/common/utils/DefaultValueContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ class DefaultValueContext final : public ExpressionContext {
return Value::kEmpty;
}

void setInnerVar(const std::string&, Value) override {
LOG(FATAL) << "Not allowed to call";
}

const Value& getInnerVar(const std::string&) const override {
LOG(FATAL) << "Not allowed to call";
return Value::kEmpty;
}

const Value& getVersionedVar(const std::string&, int64_t) const override {
LOG(FATAL) << "Not allowed to call";
return Value::kEmpty;
Expand Down
10 changes: 10 additions & 0 deletions src/graph/context/QueryExpressionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ const Value& QueryExpressionContext::getVar(const std::string& var) const {
return ectx_->getValue(var);
}

void QueryExpressionContext::setInnerVar(const std::string& var, Value val) {
exprValueMap_[var] = std::move(val);
}

const Value& QueryExpressionContext::getInnerVar(const std::string& var) const {
auto it = exprValueMap_.find(var);
if (it == exprValueMap_.end()) return Value::kEmpty;
return it->second;
}

const Value& QueryExpressionContext::getVersionedVar(const std::string& var,
int64_t version) const {
if (ectx_ == nullptr) {
Expand Down
10 changes: 10 additions & 0 deletions src/graph/context/QueryExpressionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class QueryExpressionContext final : public ExpressionContext {
// Get the latest version value for the given variable name, such as $a, $b
const Value& getVar(const std::string& var) const override;

// Set the value of innerVar. The innerVar is a variable defined in an expression.
// e.g. ListComprehension
void setInnerVar(const std::string& var, Value val) override;

// Get the value of innerVar
const Value& getInnerVar(const std::string& var) const override;

// Get the given version value for the given variable name, such as $a, $b
const Value& getVersionedVar(const std::string& var, int64_t version) const override;

Expand Down Expand Up @@ -75,6 +82,9 @@ class QueryExpressionContext final : public ExpressionContext {
// could be evaluated as constant value.
ExecutionContext* ectx_{nullptr};
Iterator* iter_{nullptr};

// Expression value map that stores the value of innerVar
std::unordered_map<std::string, Value> exprValueMap_;
};

} // namespace graph
Expand Down
2 changes: 1 addition & 1 deletion src/graph/context/Symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Variable* SymbolTable::newVariable(const std::string& name) {
DCHECK(vars_.find(name) == vars_.end());
auto* variable = objPool_->makeAndAdd<Variable>(name);
addVar(name, variable);
// Initialize all variable in variable map (ouput of node, inner variable etc.)
// Initialize all variable in variable map (output of node, inner variable etc.)
// Some variable will be useless after optimizer, maybe we could remove it.
ectx_->initVar(name);
return variable;
Expand Down
Loading

0 comments on commit e3679de

Please sign in to comment.