-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-filter-expr
- Loading branch information
Showing
28 changed files
with
2,203 additions
and
121 deletions.
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
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
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,125 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "storage/exec/IndexAggregateNode.h" | ||
|
||
namespace nebula { | ||
namespace storage { | ||
|
||
IndexAggregateNode::IndexAggregateNode(const IndexAggregateNode& node) | ||
: IndexNode(node), statInfos_(node.statInfos_), returnColumnsCount_(node.returnColumnsCount_) { | ||
stats_ = node.stats_; | ||
retColMap_ = node.retColMap_; | ||
} | ||
|
||
IndexAggregateNode::IndexAggregateNode( | ||
RuntimeContext* context, | ||
const std::vector<std::pair<std::string, cpp2::StatType>>& statInfos, | ||
size_t returnColumnsCount) | ||
: IndexNode(context, "IndexAggregateNode"), | ||
statInfos_(statInfos), | ||
returnColumnsCount_(returnColumnsCount) {} | ||
|
||
nebula::cpp2::ErrorCode IndexAggregateNode::init(InitContext& ctx) { | ||
DCHECK_EQ(children_.size(), 1); | ||
for (const auto& statInfo : statInfos_) { | ||
ctx.statColumns.insert(statInfo.first); | ||
} | ||
auto ret = children_[0]->init(ctx); | ||
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) { | ||
return ret; | ||
} | ||
initStatValue(); | ||
retColMap_.clear(); | ||
retColMap_ = ctx.retColMap; | ||
return nebula::cpp2::ErrorCode::SUCCEEDED; | ||
} | ||
|
||
void IndexAggregateNode::initStatValue() { | ||
stats_.clear(); | ||
if (statInfos_.size() > 0) { | ||
stats_.reserve(statInfos_.size()); | ||
for (const auto& statInfo : statInfos_) { | ||
stats_.emplace_back(statInfo.second); | ||
} | ||
} | ||
} | ||
|
||
void IndexAggregateNode::addStatValue(const Value& value, ColumnStat* stat) { | ||
switch (stat->statType_) { | ||
case cpp2::StatType::SUM: { | ||
stat->sum_ = stat->sum_ + value; | ||
break; | ||
} | ||
case cpp2::StatType::COUNT: { | ||
stat->count_ = stat->count_ + 1; | ||
break; | ||
} | ||
case cpp2::StatType::MAX: { | ||
stat->max_ = value > stat->max_ ? value : stat->max_; | ||
break; | ||
} | ||
case cpp2::StatType::MIN: { | ||
stat->min_ = value < stat->min_ ? value : stat->min_; | ||
break; | ||
} | ||
default: | ||
LOG(ERROR) << "get invalid stat type"; | ||
return; | ||
} | ||
} | ||
|
||
Row IndexAggregateNode::project(Row&& row) { | ||
Row ret; | ||
ret.reserve(returnColumnsCount_); | ||
for (size_t i = 0; i < returnColumnsCount_; i++) { | ||
ret.emplace_back(std::move(row[i])); | ||
} | ||
return ret; | ||
} | ||
|
||
Row IndexAggregateNode::calculateStats() { | ||
Row result; | ||
result.values.reserve(stats_.size()); | ||
for (const auto& stat : stats_) { | ||
if (stat.statType_ == cpp2::StatType::SUM) { | ||
result.values.emplace_back(stat.sum_); | ||
} else if (stat.statType_ == cpp2::StatType::COUNT) { | ||
result.values.emplace_back(stat.count_); | ||
} else if (stat.statType_ == cpp2::StatType::MAX) { | ||
result.values.emplace_back(stat.max_); | ||
} else if (stat.statType_ == cpp2::StatType::MIN) { | ||
result.values.emplace_back(stat.min_); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
IndexNode::Result IndexAggregateNode::doNext() { | ||
DCHECK_EQ(children_.size(), 1); | ||
auto& child = *children_[0]; | ||
Result result = child.next(); | ||
const auto& row = result.row(); | ||
if (result.hasData()) { | ||
for (size_t i = 0; i < statInfos_.size(); i++) { | ||
const auto& columnName = statInfos_[i].first; | ||
addStatValue(row[retColMap_[columnName]], &stats_[i]); | ||
} | ||
result = Result(project(std::move(result).row())); | ||
} | ||
return result; | ||
} | ||
|
||
std::unique_ptr<IndexNode> IndexAggregateNode::copy() { | ||
return std::make_unique<IndexAggregateNode>(*this); | ||
} | ||
|
||
std::string IndexAggregateNode::identify() { | ||
return ""; | ||
} | ||
|
||
} // namespace storage | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
#pragma once | ||
#include "storage/exec/IndexNode.h" | ||
|
||
namespace nebula { | ||
namespace storage { | ||
|
||
// used to save stat value for each column | ||
struct ColumnStat { | ||
ColumnStat() = default; | ||
|
||
explicit ColumnStat(const cpp2::StatType& statType) : statType_(statType) {} | ||
|
||
cpp2::StatType statType_; | ||
mutable Value sum_ = 0L; | ||
mutable Value count_ = 0L; | ||
mutable Value min_ = std::numeric_limits<int64_t>::max(); | ||
mutable Value max_ = std::numeric_limits<int64_t>::min(); | ||
}; | ||
|
||
class IndexAggregateNode : public IndexNode { | ||
public: | ||
IndexAggregateNode(const IndexAggregateNode& node); | ||
explicit IndexAggregateNode(RuntimeContext* context, | ||
const std::vector<std::pair<std::string, cpp2::StatType>>& statInfos, | ||
size_t returnColumnsCount); | ||
|
||
nebula::cpp2::ErrorCode init(InitContext& ctx) override; | ||
void initStatValue(); | ||
void addStatValue(const Value& value, ColumnStat* stat); | ||
Row project(Row&& row); | ||
Row calculateStats(); | ||
|
||
std::unique_ptr<IndexNode> copy() override; | ||
std::string identify() override; | ||
|
||
private: | ||
Result doNext() override; | ||
std::vector<std::pair<std::string, cpp2::StatType>> statInfos_; | ||
std::vector<ColumnStat> stats_; | ||
Map<std::string, size_t> retColMap_; | ||
size_t returnColumnsCount_; | ||
}; | ||
|
||
} // namespace storage | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
#pragma once | ||
|
||
#include "common/expression/Expression.h" | ||
#include "storage/exec/IndexNode.h" | ||
|
||
namespace nebula { | ||
namespace storage { | ||
|
||
class IndexExprContext : public ExpressionContext { | ||
public: | ||
explicit IndexExprContext(const Map<std::string, size_t> &colPos) : colPos_(colPos) {} | ||
void setRow(const Row &row) { | ||
row_ = &row; | ||
} | ||
|
||
Value getEdgeProp(const std::string &edgeType, const std::string &prop) const override { | ||
UNUSED(edgeType); | ||
DCHECK(row_ != nullptr); | ||
auto iter = colPos_.find(prop); | ||
DCHECK(iter != colPos_.end()); | ||
DCHECK(iter->second < row_->size()); | ||
return (*row_)[iter->second]; | ||
} | ||
|
||
Value getTagProp(const std::string &tag, const std::string &prop) const override { | ||
UNUSED(tag); | ||
DCHECK(row_ != nullptr); | ||
auto iter = colPos_.find(prop); | ||
DCHECK(iter != colPos_.end()); | ||
DCHECK(iter->second < row_->size()); | ||
return (*row_)[iter->second]; | ||
} | ||
|
||
// override | ||
const Value &getVar(const std::string &var) const override { | ||
UNUSED(var); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
const Value &getVersionedVar(const std::string &var, int64_t version) const override { | ||
UNUSED(var), UNUSED(version); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
const Value &getVarProp(const std::string &var, const std::string &prop) const override { | ||
UNUSED(var), UNUSED(prop); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
Value getSrcProp(const std::string &tag, const std::string &prop) const override { | ||
UNUSED(tag), UNUSED(prop); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
const Value &getDstProp(const std::string &tag, const std::string &prop) const override { | ||
UNUSED(tag), UNUSED(prop); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
const Value &getInputProp(const std::string &prop) const override { | ||
UNUSED(prop); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
Value getVertex(const std::string &) const override { | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
Value getEdge() const override { | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
Value getColumn(int32_t index) const override { | ||
UNUSED(index); | ||
return fatal(__FILE__, __LINE__); | ||
} | ||
void setVar(const std::string &var, Value val) override { | ||
UNUSED(var), UNUSED(val); | ||
fatal(__FILE__, __LINE__); | ||
} | ||
|
||
private: | ||
const Map<std::string, size_t> &colPos_; | ||
const Row *row_; | ||
inline const Value &fatal(const std::string &file, int line) const { | ||
LOG(FATAL) << "Unexpect at " << file << ":" << line; | ||
static Value placeholder; | ||
return placeholder; | ||
} | ||
}; | ||
|
||
} // namespace storage | ||
} // 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
Oops, something went wrong.