Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions be/src/core/column/column_decimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ class ColumnDecimal final : public COWHelper<IColumn, ColumnDecimal<T>> {
memset(data.data() + old_size, 0, length * sizeof(data[0]));
}

Status filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) override {
Self* output = assert_cast<Self*>(col_ptr);
auto& res_data = output->get_data();
DCHECK(res_data.empty())
<< "filter_by_selector requires the destination column to be empty";
res_data.reserve(sel_size);
auto* dst = reinterpret_cast<value_type*>(res_data.get_end_ptr());
for (size_t i = 0; i < sel_size; i++) {
dst[i] = data[sel[i]];
}
res_data.resize(sel_size);
return Status::OK();
}

void insert_many_from(const IColumn& src, size_t position, size_t length) override;

void pop_back(size_t n) override { data.resize_assume_reserved(data.size() - n); }
Expand Down
12 changes: 1 addition & 11 deletions be/src/core/column/column_dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "core/column/column.h"
#include "core/column/column_string.h"
#include "core/column/predicate_column.h"
#include "core/pod_array.h"
#include "core/string_ref.h"
#include "core/types.h"
Expand Down Expand Up @@ -256,16 +255,7 @@ class ColumnDictI32 final : public COWHelper<IColumn, ColumnDictI32> {
if (is_dict_sorted() && !is_dict_code_converted()) {
convert_dict_codes_if_necessary();
}
// if type is OLAP_FIELD_TYPE_CHAR, we need to construct TYPE_CHAR PredicateColumnType,
// because the string length will different from varchar and string which needed to be processed after.
auto create_column = [this]() -> MutableColumnPtr {
if (_type == FieldType::OLAP_FIELD_TYPE_CHAR) {
return PredicateColumnType<TYPE_CHAR>::create();
}
return PredicateColumnType<TYPE_STRING>::create();
};

auto res = create_column();
auto res = ColumnString::create();
res->reserve(_codes.capacity());
for (int code : _codes) {
auto value = _dict.get_value(code);
Expand Down
48 changes: 40 additions & 8 deletions be/src/core/column/column_execute_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
// under the License.

#pragma once
#include <concepts>
#include <tuple>
#include <type_traits>
#include <variant>
#include <vector>

#include "core/block/column_with_type_and_name.h"
#include "core/column/column.h"
#include "core/column/column_const.h"
#include "core/column/column_nullable.h"
#include "core/column/column_string.h"
#include "core/column/column_vector.h"
#include "core/data_type/define_primitive_type.h"
#include "core/data_type/primitive_type.h"
Expand All @@ -32,27 +36,55 @@ namespace doris {

// Utility tools for convenient column execution

// ColumnElementView is used to distinguish between scalar columns and string columns
// Per-row read view over a column. The pointer returned by ptr_at on the
// string specialization is valid only until the next ptr_at call.
namespace detail {

template <PrimitiveType PType>
struct ColumnElementView {
struct NumericElementView {
using ColumnType = typename PrimitiveTypeTraits<PType>::ColumnType;
using ElementType = typename ColumnType::value_type;
const typename ColumnType::Container& data;
ElementType get_element(size_t idx) const { return data[idx]; }
const ElementType* get_data() const { return data.data(); }

ColumnElementView(const IColumn& column)
NumericElementView(const IColumn& column)
: data(assert_cast<const ColumnType&>(column).get_data()) {}

ElementType get_element(size_t idx) const { return data[idx]; }
const ElementType* get_data() const { return data.data(); }
ElementType operator[](size_t idx) const { return data[idx]; }
const ElementType* ptr_at(size_t idx) const { return data.data() + idx; }
size_t size() const { return data.size(); }
};

template <>
struct ColumnElementView<TYPE_STRING> {
struct StringElementView {
using ColumnType = ColumnString;
using ElementType = StringRef;
const ColumnString& string_column;
ColumnElementView(const IColumn& column)
mutable StringRef _cell {}; // staging for ptr_at

StringElementView(const IColumn& column)
: string_column(assert_cast<const ColumnString&>(column)) {}

StringRef get_element(size_t idx) const { return string_column.get_data_at(idx); }
StringRef operator[](size_t idx) const { return string_column.get_data_at(idx); }
const StringRef* ptr_at(size_t idx) const {
_cell = string_column.get_data_at(idx);
return &_cell;
}
size_t size() const { return string_column.size(); }
};

} // namespace detail

template <PrimitiveType PType>
using ColumnElementView = std::conditional_t<is_string_type(PType), detail::StringElementView,
detail::NumericElementView<PType>>;

template <typename T>
concept ColumnElementSubscriptable = requires(const T& v, size_t i) {
typename T::ElementType;
{ v[i] } -> std::convertible_to<typename T::ElementType>;
{ v.size() } -> std::convertible_to<size_t>;
};

// ColumnView is used to handle the nullable and const properties of a column.
Expand Down
14 changes: 14 additions & 0 deletions be/src/core/column/column_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ class ColumnVector final : public COWHelper<IColumn, ColumnVector<T>> {

void insert_value(const value_type value) { data.push_back(value); }

Status filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) override {
Self* output = assert_cast<Self*>(col_ptr);
auto& res_data = output->get_data();
DCHECK(res_data.empty())
<< "filter_by_selector requires the destination column to be empty";
res_data.reserve(sel_size);
auto* dst = reinterpret_cast<value_type*>(res_data.get_end_ptr());
for (size_t i = 0; i < sel_size; i++) {
dst[i] = data[sel[i]];
}
res_data.resize(sel_size);
return Status::OK();
}

/// This method implemented in header because it could be possibly devirtualized.
int compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const override {
return Compare::compare(
Expand Down
Loading
Loading