提交 06ab815c 编写于 作者: X Xu Peng

feat(db): add count api


Former-commit-id: 9fb2b765a48d1753ba31a68e7b9b207273adb199
上级 4ce28a1e
......@@ -32,6 +32,8 @@ public:
virtual Status drop_all() = 0;
virtual Status count(const std::string& group_id, long& result) = 0;
DB() = default;
DB(const DB&) = delete;
DB& operator=(const DB&) = delete;
......
......@@ -348,6 +348,10 @@ Status DBImpl::drop_all() {
return _pMeta->drop_all();
}
Status DBImpl::count(const std::string& group_id, long& result) {
return _pMeta->count(group_id, result);
}
DBImpl::~DBImpl() {
{
std::unique_lock<std::mutex> lock(_mutex);
......
......@@ -38,6 +38,8 @@ public:
virtual Status drop_all() override;
virtual Status count(const std::string& group_id, long& result) override;
virtual ~DBImpl();
private:
......
......@@ -427,6 +427,31 @@ Status DBMetaImpl::cleanup() {
return Status::OK();
}
Status DBMetaImpl::count(const std::string& group_id, long& result) {
auto selected = ConnectorPtr->select(columns(&GroupFileSchema::rows,
&GroupFileSchema::date),
where((c(&GroupFileSchema::file_type) == (int)GroupFileSchema::RAW or
c(&GroupFileSchema::file_type) == (int)GroupFileSchema::TO_INDEX or
c(&GroupFileSchema::file_type) == (int)GroupFileSchema::INDEX) and
c(&GroupFileSchema::group_id) == group_id));
GroupSchema group_info;
group_info.group_id = group_id;
auto status = get_group_no_lock(group_info);
if (!status.ok()) {
return status;
}
result = 0;
for (auto& file : selected) {
result += std::get<0>(file);
}
result /= group_info.dimension;
return Status::OK();
}
Status DBMetaImpl::drop_all() {
if (boost::filesystem::is_directory(_options.path)) {
boost::filesystem::remove_all(_options.path);
......
......@@ -50,6 +50,8 @@ public:
virtual Status drop_all() override;
virtual Status count(const std::string& group_id, long& result) override;
virtual ~DBMetaImpl();
private:
......
......@@ -251,6 +251,11 @@ Status LocalMetaImpl::drop_all() {
return Status::OK();
}
Status LocalMetaImpl::count(const std::string& group_id, long& result) {
// PXU TODO
return Status::OK();
}
} // namespace meta
} // namespace engine
} // namespace vecwise
......
......@@ -43,6 +43,8 @@ public:
virtual Status cleanup_ttl_files(uint16_t seconds) override;
virtual Status count(const std::string& group_id, long& result) override;
virtual Status drop_all() override;
private:
......
......@@ -85,6 +85,8 @@ public:
virtual Status drop_all() = 0;
virtual Status count(const std::string& group_id, long& result) = 0;
static DateT GetDate(const std::time_t& t);
static DateT GetDate();
......
......@@ -66,7 +66,7 @@ TEST(DBTest, DB_TEST) {
qxb[d * i] += i / 2000.;
}
int loop = 500000;
int loop = 50000;
for (auto i=0; i<loop; ++i) {
if (i==40) {
......@@ -78,6 +78,10 @@ TEST(DBTest, DB_TEST) {
std::this_thread::sleep_for(std::chrono::seconds(2));
long count = 0;
db->count(group_name, count);
LOG(DEBUG) << "Count=" << count;
engine::QueryResults results;
int k = 10;
LOG(DEBUG) << "PRE";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册