Skip to content

Commit

Permalink
[Refactor](exec) Remove the unless code in BE (#46122)
Browse files Browse the repository at this point in the history
Remove the unless code:
```
OldCount,  TransformerToStringTwoArgument ,  be/src/util/type_traits.h
```
  • Loading branch information
HappenLee authored Dec 28, 2024
1 parent dc6e5fb commit 2b20512
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 178 deletions.
108 changes: 0 additions & 108 deletions be/src/util/counts.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,114 +30,6 @@

namespace doris {

class OldCounts {
public:
OldCounts() = default;

inline void merge(const OldCounts* other) {
if (other == nullptr || other->_counts.empty()) {
return;
}

for (auto& cell : other->_counts) {
increment(cell.first, cell.second);
}
}

void increment(int64_t key, uint32_t i) {
auto item = _counts.find(key);
if (item != _counts.end()) {
item->second += i;
} else {
_counts.emplace(std::make_pair(key, i));
}
}

uint32_t serialized_size() const {
return sizeof(uint32_t) + sizeof(int64_t) * _counts.size() +
sizeof(uint32_t) * _counts.size();
}

void serialize(uint8_t* writer) const {
uint32_t size = _counts.size();
memcpy(writer, &size, sizeof(uint32_t));
writer += sizeof(uint32_t);
for (auto& cell : _counts) {
memcpy(writer, &cell.first, sizeof(int64_t));
writer += sizeof(int64_t);
memcpy(writer, &cell.second, sizeof(uint32_t));
writer += sizeof(uint32_t);
}
}

void unserialize(const uint8_t* type_reader) {
uint32_t size;
memcpy(&size, type_reader, sizeof(uint32_t));
type_reader += sizeof(uint32_t);
for (uint32_t i = 0; i < size; ++i) {
int64_t key;
uint32_t count;
memcpy(&key, type_reader, sizeof(int64_t));
type_reader += sizeof(int64_t);
memcpy(&count, type_reader, sizeof(uint32_t));
type_reader += sizeof(uint32_t);
_counts.emplace(std::make_pair(key, count));
}
}

double get_percentile(std::vector<std::pair<int64_t, uint32_t>>& counts,
double position) const {
long lower = long(std::floor(position));
long higher = long(std::ceil(position));

auto iter = counts.begin();
for (; iter != counts.end() && iter->second < lower + 1; ++iter)
;

int64_t lower_key = iter->first;
if (higher == lower) {
return lower_key;
}

if (iter->second < higher + 1) {
iter++;
}

int64_t higher_key = iter->first;
if (lower_key == higher_key) {
return lower_key;
}

return (higher - position) * lower_key + (position - lower) * higher_key;
}

double terminate(double quantile) const {
if (_counts.empty()) {
// Although set null here, but the value is 0.0 and the call method just
// get val in aggregate_function_percentile_approx.h
return 0.0;
}

std::vector<std::pair<int64_t, uint32_t>> elems(_counts.begin(), _counts.end());
sort(elems.begin(), elems.end(),
[](const std::pair<int64_t, uint32_t> l, const std::pair<int64_t, uint32_t> r) {
return l.first < r.first;
});

long total = 0;
for (auto& cell : elems) {
total += cell.second;
cell.second = total;
}

long max_position = total - 1;
double position = max_position * quantile;
return get_percentile(elems, position);
}

private:
std::unordered_map<int64_t, uint32_t> _counts;
};
template <typename Ty>
class Counts {
public:
Expand Down
40 changes: 0 additions & 40 deletions be/src/util/type_traits.h

This file was deleted.

30 changes: 0 additions & 30 deletions be/src/vec/functions/date_time_transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "runtime/runtime_state.h"
#include "udf/udf.h"
#include "util/binary_cast.hpp"
#include "util/type_traits.h"
#include "vec/columns/column_nullable.h"
#include "vec/columns/column_string.h"
#include "vec/columns/column_vector.h"
Expand Down Expand Up @@ -340,35 +339,6 @@ struct TransformerToStringOneArgument {
}
};

template <typename Transform>
struct TransformerToStringTwoArgument {
static void vector_constant(FunctionContext* context,
const PaddedPODArray<typename Transform::FromType>& ts,
const StringRef& format, ColumnString::Chars& res_data,
ColumnString::Offsets& res_offsets,
PaddedPODArray<UInt8>& null_map) {
auto len = ts.size();
res_offsets.resize(len);
res_data.reserve(len * format.size + len);
null_map.resize_fill(len, false);

size_t offset = 0;
for (int i = 0; i < len; ++i) {
const auto& t = ts[i];
size_t new_offset;
bool is_null;
if constexpr (is_specialization_of_v<Transform, FromUnixTimeImpl>) {
std::tie(new_offset, is_null) = Transform::execute(
t, format, res_data, offset, context->state()->timezone_obj());
} else {
std::tie(new_offset, is_null) = Transform::execute(t, format, res_data, offset);
}
res_offsets[i] = cast_set<UInt32>(new_offset);
null_map[i] = is_null;
}
}
};

template <typename FromType, typename ToType, typename Transform>
struct Transformer {
static void vector(const PaddedPODArray<FromType>& vec_from, PaddedPODArray<ToType>& vec_to,
Expand Down

0 comments on commit 2b20512

Please sign in to comment.