Skip to content

Commit

Permalink
Conds uniion and intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Dec 25, 2020
1 parent b71b313 commit 1faa8fd
Show file tree
Hide file tree
Showing 17 changed files with 897 additions and 109 deletions.
2 changes: 1 addition & 1 deletion be/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ set(BUILD_SHARED_LIBS OFF)

if (${MAKE_TEST} STREQUAL "ON")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -DGTEST_USE_OWN_TR1_TUPLE=0")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
add_definitions(-DBE_TEST)
endif ()

Expand Down
30 changes: 30 additions & 0 deletions be/src/olap/delete_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <vector>

#include "common/logging.h"
#include "gen_cpp/olap_file.pb.h"
#include "olap/olap_common.h"
#include "olap/olap_cond.h"
Expand Down Expand Up @@ -224,11 +225,25 @@ bool DeleteHandler::_parse_condition(const std::string& condition_str, TConditio
return true;
}

void DeleteHandler::_merge_del_conds() {
_merged_del_conds.filter_version = _version;
_merged_del_conds.del_cond = new(std::nothrow) Conditions();
CHECK(_merged_del_conds.del_cond != nullptr) << "fail to malloc Conditions. size=" << sizeof(Conditions);
_merged_del_conds.del_cond->set_tablet_schema(_schema);

for (const auto& del_cond : _del_conds) {
DCHECK_LE(del_cond.filter_version, _version);
_merged_del_conds.del_cond->merge_condition(del_cond.del_cond->sorted_conds());
}
}

OLAPStatus DeleteHandler::init(const TabletSchema& schema,
const DelPredicateArray& delete_conditions, int64_t version) {
DCHECK(!_is_inited) << "reinitialize delete handler.";
DCHECK(version >= 0) << "invalid parameters. version=" << version;

_version = version;
_schema = &schema;
for (const auto& delete_condition : delete_conditions) {
// 跳过版本号大于version的过滤条件
if (delete_condition.version() > version) {
Expand Down Expand Up @@ -279,6 +294,19 @@ OLAPStatus DeleteHandler::init(const TabletSchema& schema,
_del_conds.push_back(temp);
}

for (auto& del_cond : _del_conds) {
del_cond.del_cond->normalize();
}

// Do lower cost evaluation at first.
std::sort(_del_conds.begin(), _del_conds.end(),
[] (const DeleteConditions& left,
const DeleteConditions& right) {
return left.del_cond->eval_cost() < right.del_cond->eval_cost();
});

// _merge_del_conds();

_is_inited = true;

return OLAP_SUCCESS;
Expand Down Expand Up @@ -309,11 +337,13 @@ void DeleteHandler::finalize() {
return;
}

delete _merged_del_conds.del_cond;
for (auto& cond : _del_conds) {
cond.del_cond->finalize();
delete cond.del_cond;
}
_del_conds.clear();

_is_inited = false;
}

Expand Down
5 changes: 5 additions & 0 deletions be/src/olap/delete_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ class DeleteHandler {
// Use regular expression to extract 'column_name', 'op' and 'operands'
bool _parse_condition(const std::string& condition_str, TCondition* condition);

void _merge_del_conds();

bool _is_inited = false;
int64_t _version = 0;
const TabletSchema* _schema = nullptr;
// DeleteConditions in _del_conds are in 'OR' relationship
std::vector<DeleteConditions> _del_conds;
DeleteConditions _merged_del_conds;

DISALLOW_COPY_AND_ASSIGN(DeleteHandler);
};
Expand Down
Loading

0 comments on commit 1faa8fd

Please sign in to comment.