Skip to content

Commit 3157fad

Browse files
Some minor fix (#4609)
* reserve enough space when merge storage executor's result * make filter logic same as ent version * address @SuperYoko's comments Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
1 parent 7b9fc17 commit 3157fad

7 files changed

+60
-10
lines changed

src/storage/exec/GetPropNode.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,13 @@ class GetTagPropNode : public QueryNode<VertexID> {
9494
return ret;
9595
}
9696
}
97-
if (filter_ == nullptr || (QueryUtils::vTrue(filter_->eval(*expCtx_)))) {
97+
if (filter_ == nullptr) {
9898
resultDataSet_->rows.emplace_back(std::move(row));
99+
} else {
100+
auto result = QueryUtils::vTrue(filter_->eval(*expCtx_));
101+
if (result.ok() && result.value()) {
102+
resultDataSet_->rows.emplace_back(std::move(row));
103+
}
99104
}
100105
if (expCtx_ != nullptr) {
101106
expCtx_->clear();
@@ -172,8 +177,13 @@ class GetEdgePropNode : public QueryNode<cpp2::EdgeKey> {
172177
return ret;
173178
}
174179
}
175-
if (filter_ == nullptr || (QueryUtils::vTrue(filter_->eval(*expCtx_)))) {
180+
if (filter_ == nullptr) {
176181
resultDataSet_->rows.emplace_back(std::move(row));
182+
} else {
183+
auto result = QueryUtils::vTrue(filter_->eval(*expCtx_));
184+
if (result.ok() && result.value()) {
185+
resultDataSet_->rows.emplace_back(std::move(row));
186+
}
177187
}
178188
if (expCtx_ != nullptr) {
179189
expCtx_->clear();

src/storage/exec/QueryUtils.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@ namespace storage {
1818

1919
class QueryUtils final {
2020
public:
21-
static inline bool vTrue(const Value& v) {
22-
return v.isBool() && v.getBool();
21+
// The behavior keep same with filter executor
22+
static inline StatusOr<bool> vTrue(const Value& val) {
23+
if (val.isBadNull() || (!val.empty() && !val.isBool() && !val.isNull())) {
24+
return Status::Error("Wrong type result, the type should be NULL, EMPTY or BOOL");
25+
}
26+
if (val.empty() || val.isNull() || !val.getBool()) {
27+
return false;
28+
} else {
29+
return true;
30+
}
2331
}
2432

2533
enum class ReturnColType : uint16_t {

src/storage/exec/ScanNode.h

+18-6
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,15 @@ class ScanVertexPropNode : public QueryNode<Cursor> {
171171
break;
172172
}
173173
}
174-
if (ret == nebula::cpp2::ErrorCode::SUCCEEDED &&
175-
(filter_ == nullptr || QueryUtils::vTrue(filter_->eval(*expCtx_)))) {
176-
resultDataSet_->rows.emplace_back(std::move(row));
174+
if (ret == nebula::cpp2::ErrorCode::SUCCEEDED) {
175+
if (filter_ == nullptr) {
176+
resultDataSet_->rows.emplace_back(std::move(row));
177+
} else {
178+
auto result = QueryUtils::vTrue(filter_->eval(*expCtx_));
179+
if (result.ok() && result.value()) {
180+
resultDataSet_->rows.emplace_back(std::move(row));
181+
}
182+
}
177183
}
178184
expCtx_->clear();
179185
for (auto& tagNode : tagNodes_) {
@@ -323,9 +329,15 @@ class ScanEdgePropNode : public QueryNode<Cursor> {
323329
break;
324330
}
325331
}
326-
if (ret == nebula::cpp2::ErrorCode::SUCCEEDED &&
327-
(filter_ == nullptr || QueryUtils::vTrue(filter_->eval(*expCtx_)))) {
328-
resultDataSet_->rows.emplace_back(std::move(row));
332+
if (ret == nebula::cpp2::ErrorCode::SUCCEEDED) {
333+
if (filter_ == nullptr) {
334+
resultDataSet_->rows.emplace_back(std::move(row));
335+
} else {
336+
auto result = QueryUtils::vTrue(filter_->eval(*expCtx_));
337+
if (result.ok() && result.value()) {
338+
resultDataSet_->rows.emplace_back(std::move(row));
339+
}
340+
}
329341
}
330342
expCtx_->clear();
331343
for (auto& edgeNode : edgeNodes_) {

src/storage/query/GetNeighborsProcessor.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ void GetNeighborsProcessor::runInMultipleThread(const cpp2::GetNeighborsRequest&
130130
folly::collectAll(futures).via(executor_).thenTry([this](auto&& t) mutable {
131131
CHECK(!t.hasException());
132132
const auto& tries = t.value();
133+
size_t sum = 0;
133134
for (size_t j = 0; j < tries.size(); j++) {
134135
CHECK(!tries[j].hasException());
136+
sum += results_[j].size();
137+
}
138+
resultDataSet_.rows.reserve(sum);
139+
for (size_t j = 0; j < tries.size(); j++) {
135140
const auto& [code, partId] = tries[j].value();
136141
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
137142
handleErrorCode(code, spaceId_, partId);

src/storage/query/GetPropProcessor.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ void GetPropProcessor::runInMultipleThread(const cpp2::GetPropRequest& req) {
129129
folly::collectAll(futures).via(executor_).thenTry([this](auto&& t) mutable {
130130
CHECK(!t.hasException());
131131
const auto& tries = t.value();
132+
size_t sum = 0;
132133
for (size_t j = 0; j < tries.size(); j++) {
133134
CHECK(!tries[j].hasException());
135+
sum += results_[j].size();
136+
}
137+
resultDataSet_.rows.reserve(sum);
138+
for (size_t j = 0; j < tries.size(); j++) {
134139
const auto& [code, partId] = tries[j].value();
135140
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
136141
handleErrorCode(code, spaceId_, partId);

src/storage/query/ScanEdgeProcessor.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ void ScanEdgeProcessor::runInMultipleThread(const cpp2::ScanEdgeRequest& req) {
179179
folly::collectAll(futures).via(executor_).thenTry([this](auto&& t) mutable {
180180
CHECK(!t.hasException());
181181
const auto& tries = t.value();
182+
size_t sum = 0;
182183
for (size_t j = 0; j < tries.size(); j++) {
183184
CHECK(!tries[j].hasException());
185+
sum += results_[j].size();
186+
}
187+
resultDataSet_.rows.reserve(sum);
188+
for (size_t j = 0; j < tries.size(); j++) {
184189
const auto& [code, partId] = tries[j].value();
185190
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
186191
handleErrorCode(code, spaceId_, partId);

src/storage/query/ScanVertexProcessor.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,13 @@ void ScanVertexProcessor::runInMultipleThread(const cpp2::ScanVertexRequest& req
184184
folly::collectAll(futures).via(executor_).thenTry([this](auto&& t) mutable {
185185
CHECK(!t.hasException());
186186
const auto& tries = t.value();
187+
size_t sum = 0;
187188
for (size_t j = 0; j < tries.size(); j++) {
188189
CHECK(!tries[j].hasException());
190+
sum += results_[j].size();
191+
}
192+
resultDataSet_.rows.reserve(sum);
193+
for (size_t j = 0; j < tries.size(); j++) {
189194
const auto& [code, partId] = tries[j].value();
190195
if (code != nebula::cpp2::ErrorCode::SUCCEEDED) {
191196
handleErrorCode(code, spaceId_, partId);

0 commit comments

Comments
 (0)