Skip to content

Commit

Permalink
Merge branch 'master' into lookup-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie-Xie authored Jan 19, 2023
2 parents f17db26 + 001f968 commit e2835b5
Show file tree
Hide file tree
Showing 96 changed files with 2,497 additions and 655 deletions.
16 changes: 16 additions & 0 deletions conf/nebula-graphd.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@
########## session ##########
# Maximum number of sessions that can be created per IP and per user
--max_sessions_per_ip_per_user=300

########## memory tracker ##########
# trackable memory ratio (trackable_memory / (total_memory - untracked_reserved_memory) )
--memory_tracker_limit_ratio=0.8
# untracked reserved memory in Mib
--memory_tracker_untracked_reserved_memory_mb=50

# enable log memory tracker stats periodically
--memory_tracker_detail_log=false
# log memory tacker stats interval in milliseconds
--memory_tracker_detail_log_interval_ms=60000

# enable memory background purge (if jemalloc is used)
--memory_purge_enabled=true
# memory background purge interval in seconds
--memory_purge_interval_seconds=10
16 changes: 16 additions & 0 deletions conf/nebula-graphd.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@
########## session ##########
# Maximum number of sessions that can be created per IP and per user
--max_sessions_per_ip_per_user=300

########## memory tracker ##########
# trackable memory ratio (trackable_memory / (total_memory - untracked_reserved_memory) )
--memory_tracker_limit_ratio=0.8
# untracked reserved memory in Mib
--memory_tracker_untracked_reserved_memory_mb=50

# enable log memory tracker stats periodically
--memory_tracker_detail_log=false
# log memory tacker stats interval in milliseconds
--memory_tracker_detail_log_interval_ms=60000

# enable memory background purge (if jemalloc is used)
--memory_purge_enabled=true
# memory background purge interval in seconds
--memory_purge_interval_seconds=10
16 changes: 16 additions & 0 deletions conf/nebula-storaged.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,19 @@
--rebuild_index_part_rate_limit=4194304
# The amount of data sent in each batch when leader synchronizes rebuilding index
--rebuild_index_batch_size=1048576

########## memory tracker ##########
# trackable memory ratio (trackable_memory / (total_memory - untracked_reserved_memory) )
--memory_tracker_limit_ratio=0.8
# untracked reserved memory in Mib
--memory_tracker_untracked_reserved_memory_mb=50

# enable log memory tracker stats periodically
--memory_tracker_detail_log=false
# log memory tacker stats interval in milliseconds
--memory_tracker_detail_log_interval_ms=60000

# enable memory background purge (if jemalloc is used)
--memory_purge_enabled=true
# memory background purge interval in seconds
--memory_purge_interval_seconds=10
16 changes: 16 additions & 0 deletions conf/nebula-storaged.conf.production
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,19 @@
--rebuild_index_part_rate_limit=4194304
# The amount of data sent in each batch when leader synchronizes rebuilding index
--rebuild_index_batch_size=1048576

########## memory tracker ##########
# trackable memory ratio (trackable_memory / (total_memory - untracked_reserved_memory) )
--memory_tracker_limit_ratio=0.8
# untracked reserved memory in Mib
--memory_tracker_untracked_reserved_memory_mb=50

# enable log memory tracker stats periodically
--memory_tracker_detail_log=false
# log memory tacker stats interval in milliseconds
--memory_tracker_detail_log_interval_ms=60000

# enable memory background purge (if jemalloc is used)
--memory_purge_enabled=true
# memory background purge interval in seconds
--memory_purge_interval_seconds=10
2 changes: 2 additions & 0 deletions src/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ Status MetaClient::handleResponse(const RESP& resp) {
return Status::Error("No hosts!");
case nebula::cpp2::ErrorCode::E_EXISTED:
return Status::Error("Existed!");
case nebula::cpp2::ErrorCode::E_HISTORY_CONFLICT:
return Status::Error("Schema exisited before!");
case nebula::cpp2::ErrorCode::E_SPACE_NOT_FOUND:
return Status::SpaceNotFound("Space not existed!");
case nebula::cpp2::ErrorCode::E_TAG_NOT_FOUND:
Expand Down
8 changes: 8 additions & 0 deletions src/common/datatypes/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,14 @@ Value::Value(Duration&& v) {
setDU(std::make_unique<Duration>(std::move(v)));
}

Value::Value(const std::unordered_map<std::string, Value>& map) {
setM(std::make_unique<Map>(map));
}

Value::Value(std::unordered_map<std::string, Value>&& map) {
setM(std::make_unique<Map>(std::move(map)));
}

const std::string& Value::typeName() const {
static const std::unordered_map<Type, std::string> typeNames = {
{Type::__EMPTY__, "__EMPTY__"},
Expand Down
88 changes: 45 additions & 43 deletions src/common/datatypes/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,49 +91,51 @@ struct Value {
// matched ctor it will convert to bool type and the match the bool value
// ctor, So we disable all pointer ctor except the char*
template <typename T>
Value(T*) = delete; // NOLINT
Value(const std::nullptr_t) = delete; // NOLINT
Value(const NullType& v); // NOLINT
Value(NullType&& v); // NOLINT
Value(const bool& v); // NOLINT
Value(bool&& v); // NOLINT
Value(const int8_t& v); // NOLINT
Value(int8_t&& v); // NOLINT
Value(const int16_t& v); // NOLINT
Value(int16_t&& v); // NOLINT
Value(const int32_t& v); // NOLINT
Value(int32_t&& v); // NOLINT
Value(const int64_t& v); // NOLINT
Value(int64_t&& v); // NOLINT
Value(const double& v); // NOLINT
Value(double&& v); // NOLINT
Value(const std::string& v); // NOLINT
Value(std::string&& v); // NOLINT
Value(const char* v); // NOLINT
Value(const Date& v); // NOLINT
Value(Date&& v); // NOLINT
Value(const Time& v); // NOLINT
Value(Time&& v); // NOLINT
Value(const DateTime& v); // NOLINT
Value(DateTime&& v); // NOLINT
Value(const Vertex& v); // NOLINT
Value(Vertex&& v); // NOLINT
Value(const Edge& v); // NOLINT
Value(Edge&& v); // NOLINT
Value(const Path& v); // NOLINT
Value(Path&& v); // NOLINT
Value(const List& v); // NOLINT
Value(List&& v); // NOLINT
Value(const Map& v); // NOLINT
Value(Map&& v); // NOLINT
Value(const Set& v); // NOLINT
Value(Set&& v); // NOLINT
Value(const DataSet& v); // NOLINT
Value(DataSet&& v); // NOLINT
Value(const Geography& v); // NOLINT
Value(Geography&& v); // NOLINT
Value(const Duration& v); // NOLINT
Value(Duration&& v); // NOLINT
Value(T*) = delete; // NOLINT
Value(const std::nullptr_t) = delete; // NOLINT
Value(const NullType& v); // NOLINT
Value(NullType&& v); // NOLINT
Value(const bool& v); // NOLINT
Value(bool&& v); // NOLINT
Value(const int8_t& v); // NOLINT
Value(int8_t&& v); // NOLINT
Value(const int16_t& v); // NOLINT
Value(int16_t&& v); // NOLINT
Value(const int32_t& v); // NOLINT
Value(int32_t&& v); // NOLINT
Value(const int64_t& v); // NOLINT
Value(int64_t&& v); // NOLINT
Value(const double& v); // NOLINT
Value(double&& v); // NOLINT
Value(const std::string& v); // NOLINT
Value(std::string&& v); // NOLINT
Value(const char* v); // NOLINT
Value(const Date& v); // NOLINT
Value(Date&& v); // NOLINT
Value(const Time& v); // NOLINT
Value(Time&& v); // NOLINT
Value(const DateTime& v); // NOLINT
Value(DateTime&& v); // NOLINT
Value(const Vertex& v); // NOLINT
Value(Vertex&& v); // NOLINT
Value(const Edge& v); // NOLINT
Value(Edge&& v); // NOLINT
Value(const Path& v); // NOLINT
Value(Path&& v); // NOLINT
Value(const List& v); // NOLINT
Value(List&& v); // NOLINT
Value(const Map& v); // NOLINT
Value(Map&& v); // NOLINT
Value(const Set& v); // NOLINT
Value(Set&& v); // NOLINT
Value(const DataSet& v); // NOLINT
Value(DataSet&& v); // NOLINT
Value(const Geography& v); // NOLINT
Value(Geography&& v); // NOLINT
Value(const Duration& v); // NOLINT
Value(Duration&& v); // NOLINT
Value(const std::unordered_map<std::string, Value>& map); // NOLINT
Value(std::unordered_map<std::string, Value>&& map); // NOLINT
~Value() {
clear();
}
Expand Down
68 changes: 22 additions & 46 deletions src/common/expression/AttributeExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,57 +17,30 @@ const Value &AttributeExpression::eval(ExpressionContext &ctx) {
auto &lvalue = left()->eval(ctx);
auto &rvalue = right()->eval(ctx);
DCHECK(rvalue.isStr());
auto la = [&rvalue](const Tag &t) { return t.name == rvalue.getStr(); };

// TODO(dutor) Take care of the builtin properties, _src, _vid, _type, etc.
switch (lvalue.type()) {
case Value::Type::MAP:
return lvalue.getMap().at(rvalue.getStr());
case Value::Type::MAP: {
auto &m = lvalue.getMap().kvs;
auto iter = m.find(rvalue.getStr());
if (iter == m.end()) {
return Value::kNullValue;
}
return iter->second;
}
case Value::Type::VERTEX: {
/*
* WARNING(Xuntao): Vertices shall not be evaluated as AttributeExpressions,
* since there shall always be a tag specified in the format of:
* var.tag.property. Due to design flaws, however, we have to keep
* this case segment.
*/
if (rvalue.getStr() == kVid) {
result_ = lvalue.getVertex().vid;
return result_;
}
/*
* WARNING(Xuntao): the following code snippet is dedicated to address the legacy
* problem of treating LabelTagProperty expressions as Attribute expressions.
* This snippet is necessary to allow users to write var.tag.prop in
* ListComprehensionExpression without making structural changes to the implementation.
*/
if (left()->kind() != Expression::Kind::kAttribute) {
if (right()->kind() == Expression::Kind::kConstant &&
rvalue.type() == Value::Type::STRING) {
auto rStr = rvalue.getStr();
for (auto &tag : lvalue.getVertex().tags) {
if (rStr.compare(tag.name) == 0) {
return lvalue;
}
}
LOG(ERROR) << "Tag not found for: " << rStr
<< "Please check whether the related expression "
<< "follows the format of vertex.tag.property.";
}
} else if (left()->kind() == Expression::Kind::kAttribute &&
dynamic_cast<AttributeExpression *>(left())->right()->kind() ==
Expression::Kind::kConstant) {
auto &tagName = dynamic_cast<AttributeExpression *>(left())->right()->eval(ctx).getStr();
for (auto &tag : lvalue.getVertex().tags) {
if (tagName.compare(tag.name) != 0) {
continue;
} else {
auto iter = tag.props.find(rvalue.getStr());
if (iter != tag.props.end()) {
return iter->second;
}
}
}
const auto &tags = lvalue.getVertex().tags;
auto iter = std::find_if(tags.begin(), tags.end(), la);
if (iter == tags.end()) {
return Value::kNullValue;
}
return Value::kNullUnknownProp;
result_.setMap(Map(iter->props));
return result_;
}
case Value::Type::EDGE: {
DCHECK(!rvalue.getStr().empty());
Expand Down Expand Up @@ -98,11 +71,14 @@ const Value &AttributeExpression::eval(ExpressionContext &ctx) {
case Value::Type::DATETIME:
result_ = time::TimeUtils::getDateTimeAttr(lvalue.getDateTime(), rvalue.getStr());
return result_;
default:
if (lvalue.isNull() && lvalue.getNull() == NullType::UNKNOWN_PROP) {
// return UNKNOWN_PROP as plain null values, instead of bad type.
return Value::kNullValue;
case Value::Type::NULLVALUE: {
if (lvalue.isBadNull()) {
return Value::kNullBadType;
}
return Value::kNullValue;
}
default:
// Unexpected data types
return Value::kNullBadType;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/expression/MatchPathPatternExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class MatchPathPatternExpression final : public Expression {
return *matchPath_;
}

MatchPath* matchPathPtr() const {
return matchPath_.get();
}

private:
friend ObjectPool;
explicit MatchPathPatternExpression(ObjectPool* pool, std::unique_ptr<MatchPath>&& matchPath)
Expand Down
2 changes: 1 addition & 1 deletion src/common/expression/TextSearchExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TextSearchArgument final {
std::string val_;
std::string op_;
int32_t fuzziness_{-2};
int32_t limit_{-1};
int32_t limit_{10000};
int32_t timeout_{-1};
};

Expand Down
60 changes: 26 additions & 34 deletions src/common/expression/test/AttributeExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
*
* This source code is licensed under Apache 2.0 License.
*/
#include <unordered_map>

#include "common/expression/test/TestBase.h"
#include "graph/util/ExpressionUtils.h"

namespace nebula {

Expand Down Expand Up @@ -96,50 +93,45 @@ TEST_F(AttributeExpressionTest, VertexAttribute) {
{"Tug", "War"},
{"Venus", "RocksShow"},
};
std::unordered_map<std::string, graph::AliasType> aliasTypeMap = {{"v", graph::AliasType::kNode}};
ExpressionContextMock expContext;
expContext.setVar("v", Value(vertex));
{
auto *left = LabelExpression::make(&pool, "v");
auto *right = ConstantExpression::make(&pool, "tag0");
auto *labelAttribute = LabelAttributeExpression::make(&pool, left, right);
auto expr =
AttributeExpression::make(&pool, labelAttribute, ConstantExpression::make(&pool, "Mull"));
auto rewriteExpr =
graph::ExpressionUtils::rewriteAttr2LabelTagProp(expr->clone(), aliasTypeMap);
auto value = Expression::eval(rewriteExpr, expContext);
{
auto expr = AttributeExpression::make(
&pool,
AttributeExpression::make(&pool,
ConstantExpression::make(&pool, Value(vertex)),
ConstantExpression::make(&pool, "tag0")),
ConstantExpression::make(&pool, "Mull"));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isStr());
ASSERT_EQ("Kintyre", value.getStr());
}
{
auto *left = LabelExpression::make(&pool, "v");
auto *right = ConstantExpression::make(&pool, "tag1");
auto *labelAttribute = LabelAttributeExpression::make(&pool, left, right);
auto expr =
AttributeExpression::make(&pool, labelAttribute, ConstantExpression::make(&pool, "Bip"));
auto rewriteExpr =
graph::ExpressionUtils::rewriteAttr2LabelTagProp(expr->clone(), aliasTypeMap);
auto value = Expression::eval(rewriteExpr, expContext);
auto expr = AttributeExpression::make(
&pool,
AttributeExpression::make(&pool,
ConstantExpression::make(&pool, Value(vertex)),
ConstantExpression::make(&pool, "tag1")),
ConstantExpression::make(&pool, "Bip"));
auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isStr());
ASSERT_EQ("Bop", value.getStr());
}
{
auto *left = LabelExpression::make(&pool, "v");
auto *right = ConstantExpression::make(&pool, "tag0");
auto *labelAttribute = LabelAttributeExpression::make(&pool, left, right);
auto expr =
AttributeExpression::make(&pool, labelAttribute, ConstantExpression::make(&pool, "Venus"));
auto rewriteExpr =
graph::ExpressionUtils::rewriteAttr2LabelTagProp(expr->clone(), aliasTypeMap);
auto value = Expression::eval(rewriteExpr, expContext);
ASSERT_TRUE(value.isStr());
ASSERT_EQ("Mars", value.getStr());
auto expr = AttributeExpression::make(
&pool,
AttributeExpression::make(&pool,
ConstantExpression::make(&pool, Value(vertex)),
ConstantExpression::make(&pool, "tag2")),
ConstantExpression::make(&pool, "Venus"));

auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isNull());
}
{
auto *left = ConstantExpression::make(&pool, Value(vertex));
auto *right = LabelExpression::make(&pool, "_vid");
auto expr = AttributeExpression::make(&pool, left, right);
auto value = Expression::eval(expr, expContext);
auto value = Expression::eval(expr, gExpCtxt);
ASSERT_TRUE(value.isStr());
ASSERT_EQ("vid", value.getStr());
}
Expand Down
Loading

0 comments on commit e2835b5

Please sign in to comment.