Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions be/src/core/assert_cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@

enum class TypeCheckOnRelease : bool { ENABLE = true, DISABLE = false };

template <typename T>
struct AssertCastNormalizedType {
using no_ref_t = std::remove_reference_t<T>;
using no_cv_t = std::remove_cv_t<no_ref_t>;
using type =
std::conditional_t<std::is_pointer_v<no_cv_t>,
std::add_pointer_t<std::remove_cv_t<std::remove_pointer_t<no_cv_t>>>,
no_cv_t>;
};

template <typename T>
using AssertCastNormalizedType_t = typename AssertCastNormalizedType<T>::type;

/** Perform static_cast in release build when TypeCheckOnRelease is set to DISABLE.
* Checks type by comparing typeid and throw an exception in all the other situations.
* The exact match of the type is checked. That is, cast to the ancestor will be unsuccessful.
*/
template <typename To, TypeCheckOnRelease check = TypeCheckOnRelease::ENABLE, typename From>
PURE To assert_cast(From&& from) {
static_assert(!std::is_same_v<AssertCastNormalizedType_t<To>, AssertCastNormalizedType_t<From>>,
"assert_cast is redundant for the same type after removing cv/ref qualifiers");

// https://godbolt.org/z/nrsx7nYhs
// perform_cast will not be compiled to asm in release build with TypeCheckOnRelease::DISABLE
auto perform_cast = [](auto&& from) -> To {
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/column/column_complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MutableColumnPtr ColumnComplexType<T>::clone_resized(size_t size) const {
auto res = this->create();

if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
auto& new_col = *res;
size_t count = std::min(size, data.size());
new_col.insert_range_from(*this, 0, count);
if (size > count) {
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/column/column_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ MutableColumnPtr ColumnDecimal<T>::clone_resized(size_t size) const {
auto res = this->create(0, scale);

if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
auto& new_col = *res;
new_col.data.resize(size);

size_t count = std::min(this->size(), size);
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/column/column_fixed_length_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ColumnFixedLengthObject final : public COWHelper<IColumn, ColumnFixedLengt
auto res = create(_item_size);

if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
auto& new_col = *res;
new_col.resize(size);
auto* new_data = new_col._data.data();

Expand Down
21 changes: 7 additions & 14 deletions be/src/core/column/column_nullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ void ColumnNullable::update_xxHash_with_value(size_t start, size_t end, uint64_t
if (!has_null(start, end)) {
_nested_column->update_xxHash_with_value(start, end, hash, nullptr);
} else {
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
for (size_t i = start; i < end; ++i) {
if (real_null_data[i] != 0) {
hash = HashUtil::xxHash64NullWithSeed(hash);
Expand All @@ -72,8 +71,7 @@ void ColumnNullable::update_crc_with_value(size_t start, size_t end, uint32_t& h
if (!has_null(start, end)) {
_nested_column->update_crc_with_value(start, end, hash, nullptr);
} else {
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
for (size_t i = start; i < end; ++i) {
if (real_null_data[i] != 0) {
hash = HashUtil::zlib_crc_hash_null(hash);
Expand All @@ -97,8 +95,7 @@ void ColumnNullable::update_crcs_with_value(uint32_t* __restrict hashes, doris::
DCHECK(null_data == nullptr);
auto s = rows;
DCHECK(s == size());
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
if (!has_null()) {
_nested_column->update_crcs_with_value(hashes, type, rows, offset, nullptr);
} else {
Expand All @@ -113,8 +110,7 @@ void ColumnNullable::update_crcs_with_value(uint32_t* __restrict hashes, doris::

void ColumnNullable::update_crc32c_batch(uint32_t* __restrict hashes,
const uint8_t* __restrict /* null_map */) const {
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
if (_nested_column->support_replace_column_null_data()) {
// nullmap process is slow, replace null data to default value to avoid nullmap process
_nested_column->assume_mutable()->replace_column_null_data(real_null_data);
Expand All @@ -132,8 +128,7 @@ void ColumnNullable::update_crc32c_batch(uint32_t* __restrict hashes,

void ColumnNullable::update_crc32c_single(size_t start, size_t end, uint32_t& hash,
const uint8_t* __restrict /* null_map */) const {
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
constexpr int NULL_VALUE = 0;
for (size_t i = start; i < end; ++i) {
if (real_null_data[i] != 0) {
Expand All @@ -147,8 +142,7 @@ void ColumnNullable::update_hashes_with_value(uint64_t* __restrict hashes,
const uint8_t* __restrict null_data) const {
DCHECK(null_data == nullptr);
auto s = size();
const auto* __restrict real_null_data =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict real_null_data = get_null_map_column().get_data().data();
if (!has_null()) {
_nested_column->update_hashes_with_value(hashes, nullptr);
} else {
Expand Down Expand Up @@ -275,8 +269,7 @@ size_t ColumnNullable::serialize_impl(char* pos, const size_t row) const {

void ColumnNullable::serialize(StringRef* keys, size_t num_rows) const {
const bool has_null = simd::contain_one(get_null_map_data().data(), num_rows);
const auto* __restrict null_map =
assert_cast<const ColumnUInt8&>(get_null_map_column()).get_data().data();
const auto* __restrict null_map = get_null_map_column().get_data().data();
_nested_column->serialize_with_nullable(keys, num_rows, has_null, null_map);
}

Expand Down
8 changes: 2 additions & 6 deletions be/src/core/column/column_nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,9 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {

std::string get_name() const override { return "Nullable(" + _nested_column->get_name() + ")"; }
MutableColumnPtr clone_resized(size_t size) const override;
size_t size() const override {
return assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>(get_null_map_column())
.size();
}
size_t size() const override { return get_null_map_column().size(); }
PURE bool is_null_at(size_t n) const override {
return assert_cast<const ColumnUInt8&, TypeCheckOnRelease::DISABLE>(get_null_map_column())
.get_data()[n] != 0;
return get_null_map_column().get_data()[n] != 0;
}
Field operator[](size_t n) const override;
void get(size_t n, Field& res) const override;
Expand Down
7 changes: 3 additions & 4 deletions be/src/core/column/column_varbinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace doris {
MutableColumnPtr ColumnVarbinary::clone_resized(size_t size) const {
auto res = create();
if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
auto& new_col = *res;
size_t count = std::min(this->size(), size);
for (size_t i = 0; i < count; ++i) {
auto value = this->get_data_at(i);
Expand Down Expand Up @@ -108,7 +108,7 @@ ColumnPtr ColumnVarbinary::filter(const IColumn::Filter& filt, ssize_t result_si

size_t ColumnVarbinary::filter(const IColumn::Filter& filter) {
size_t pos = 0;
const Self& src_vec = assert_cast<const Self&>(*this);
const Self& src_vec = *this;
for (size_t i = 0; i < filter.size(); i++) {
if (filter[i]) {
if (src_vec.get_data()[i].isInline()) {
Expand Down Expand Up @@ -225,8 +225,7 @@ void ColumnVarbinary::insert_many_strings_overflow(const StringRef* strings, siz
void ColumnVarbinary::sort_column(const ColumnSorter* sorter, EqualFlags& flags,
IColumn::Permutation& perms, EqualRange& range,
bool last_column) const {
sorter->sort_column(assert_cast<const ColumnVarbinary&>(*this), flags, perms, range,
last_column);
sorter->sort_column(*this, flags, perms, range, last_column);
}

} // namespace doris
2 changes: 1 addition & 1 deletion be/src/core/column/column_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ template <PrimitiveType T>
MutableColumnPtr ColumnVector<T>::clone_resized(size_t size) const {
auto res = this->create();
if (size > 0) {
auto& new_col = assert_cast<Self&>(*res);
auto& new_col = *res;
size_t count = std::min(this->size(), size);
new_col.data.resize(count);
memcpy(new_col.data.data(), data.data(), count * sizeof(data[0]));
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/data_type/data_type_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ template <PrimitiveType T>
void DataTypeDecimal<T>::to_pb_column_meta(PColumnMeta* col_meta) const {
IDataType::to_pb_column_meta(col_meta);
if constexpr (T == TYPE_DECIMALV2) {
const auto* real_type_t = assert_cast<const DataTypeDecimalV2*>(this);
const auto* real_type_t = this;
col_meta->mutable_decimal_param()->set_precision(real_type_t->get_original_precision());
col_meta->mutable_decimal_param()->set_scale(real_type_t->get_original_scale());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Status DataTypeDateSerDe<T>::from_string_batch(
const ColumnString& col_str, ColumnNullable& col_res,
const typename DataTypeNumberSerDe<T>::FormatOptions& options) const {
auto& col_data = assert_cast<ColumnType&>(col_res.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(col_res.get_null_map_column());
auto& col_nullmap = col_res.get_null_map_column();
size_t row = col_str.size();
col_res.resize(row);

Expand Down Expand Up @@ -467,7 +467,7 @@ template <typename IntDataType>
Status DataTypeDateSerDe<T>::from_int_batch(const typename IntDataType::ColumnType& int_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnType&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(int_col.size());
col_nullmap.resize(int_col.size());

Expand Down Expand Up @@ -519,7 +519,7 @@ template <typename FloatDataType>
Status DataTypeDateSerDe<T>::from_float_batch(const typename FloatDataType::ColumnType& float_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnType&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(float_col.size());
col_nullmap.resize(float_col.size());

Expand Down Expand Up @@ -570,7 +570,7 @@ template <typename DecimalDataType>
Status DataTypeDateSerDe<T>::from_decimal_batch(
const typename DecimalDataType::ColumnType& decimal_col, ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnType&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(decimal_col.size());
col_nullmap.resize(decimal_col.size());

Expand Down
8 changes: 4 additions & 4 deletions be/src/core/data_type_serde/data_type_datetimev2_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Status DataTypeDateTimeV2SerDe::from_string_batch(const ColumnString& col_str,
ColumnNullable& col_res,
const FormatOptions& options) const {
auto& col_data = assert_cast<ColumnDateTimeV2&>(col_res.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(col_res.get_null_map_column());
auto& col_nullmap = col_res.get_null_map_column();
size_t row = col_str.size();
col_res.resize(row);

Expand Down Expand Up @@ -170,7 +170,7 @@ template <typename IntDataType>
Status DataTypeDateTimeV2SerDe::from_int_batch(const typename IntDataType::ColumnType& int_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(int_col.size());
col_nullmap.resize(int_col.size());

Expand Down Expand Up @@ -215,7 +215,7 @@ template <typename FloatDataType>
Status DataTypeDateTimeV2SerDe::from_float_batch(
const typename FloatDataType::ColumnType& float_col, ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(float_col.size());
col_nullmap.resize(float_col.size());

Expand Down Expand Up @@ -260,7 +260,7 @@ template <typename DecimalDataType>
Status DataTypeDateTimeV2SerDe::from_decimal_batch(
const typename DecimalDataType::ColumnType& decimal_col, ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(decimal_col.size());
col_nullmap.resize(decimal_col.size());

Expand Down
8 changes: 4 additions & 4 deletions be/src/core/data_type_serde/data_type_datev2_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void DataTypeDateV2SerDe::write_one_cell_to_binary(const IColumn& src_column,
Status DataTypeDateV2SerDe::from_string_batch(const ColumnString& col_str, ColumnNullable& col_res,
const FormatOptions& options) const {
auto& col_data = assert_cast<ColumnDateV2&>(col_res.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(col_res.get_null_map_column());
auto& col_nullmap = col_res.get_null_map_column();
size_t row = col_str.size();
col_res.resize(row);

Expand Down Expand Up @@ -323,7 +323,7 @@ template <typename IntDataType>
Status DataTypeDateV2SerDe::from_int_batch(const typename IntDataType::ColumnType& int_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(int_col.size());
col_nullmap.resize(int_col.size());

Expand Down Expand Up @@ -366,7 +366,7 @@ template <typename FloatDataType>
Status DataTypeDateV2SerDe::from_float_batch(const typename FloatDataType::ColumnType& float_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(float_col.size());
col_nullmap.resize(float_col.size());

Expand Down Expand Up @@ -410,7 +410,7 @@ template <typename DecimalDataType>
Status DataTypeDateV2SerDe::from_decimal_batch(
const typename DecimalDataType::ColumnType& decimal_col, ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnDateV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(decimal_col.size());
col_nullmap.resize(decimal_col.size());

Expand Down
8 changes: 4 additions & 4 deletions be/src/core/data_type_serde/data_type_time_serde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Status DataTypeTimeV2SerDe::write_column_to_mysql_binary(const IColumn& column,
Status DataTypeTimeV2SerDe::from_string_batch(const ColumnString& col_str, ColumnNullable& col_res,
const FormatOptions& options) const {
auto& col_data = assert_cast<ColumnTimeV2&>(col_res.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(col_res.get_null_map_column());
auto& col_nullmap = col_res.get_null_map_column();
size_t row = col_str.size();
col_res.resize(row);

Expand Down Expand Up @@ -149,7 +149,7 @@ template <typename IntDataType>
Status DataTypeTimeV2SerDe::from_int_batch(const typename IntDataType::ColumnType& int_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(int_col.size());
col_nullmap.resize(int_col.size());

Expand Down Expand Up @@ -192,7 +192,7 @@ template <typename FloatDataType>
Status DataTypeTimeV2SerDe::from_float_batch(const typename FloatDataType::ColumnType& float_col,
ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(float_col.size());
col_nullmap.resize(float_col.size());

Expand Down Expand Up @@ -237,7 +237,7 @@ template <typename DecimalDataType>
Status DataTypeTimeV2SerDe::from_decimal_batch(
const typename DecimalDataType::ColumnType& decimal_col, ColumnNullable& target_col) const {
auto& col_data = assert_cast<ColumnTimeV2&>(target_col.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(target_col.get_null_map_column());
auto& col_nullmap = target_col.get_null_map_column();
col_data.resize(decimal_col.size());
col_nullmap.resize(decimal_col.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Status DataTypeTimeStampTzSerDe::from_string_batch(const ColumnString& col_str,
ColumnNullable& col_res,
const FormatOptions& options) const {
auto& col_data = assert_cast<ColumnTimeStampTz&>(col_res.get_nested_column());
auto& col_nullmap = assert_cast<ColumnBool&>(col_res.get_null_map_column());
auto& col_nullmap = col_res.get_null_map_column();
size_t row = col_str.size();
col_res.resize(row);

Expand Down
4 changes: 1 addition & 3 deletions be/src/exec/common/hash_table/hash_map_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,7 @@ struct MethodKeysFixed : public MethodBase<TData> {
// nullable_col is obtained via key_columns and is itself a mutable element. However, when accessed
// through get_raw_data().data, it yields a const char*, necessitating the use of const_cast.
data = const_cast<char*>(nullable_col.get_nested_column().get_raw_data().data);
UInt8* nullmap = assert_cast<ColumnUInt8*>(&nullable_col.get_null_map_column())
->get_data()
.data();
UInt8* nullmap = nullable_col.get_null_map_column().get_data().data();

// The current column is nullable. Check if the value of the
// corresponding key is nullable. Update the null map accordingly.
Expand Down
3 changes: 1 addition & 2 deletions be/src/exec/common/variant_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,8 +1321,7 @@ void VariantCompactionUtil::calculate_variant_stats(const IColumn& encoded_spars
// Get the keys column which contains the paths as strings
const auto& sparse_data_paths =
assert_cast<const ColumnString*>(map_column.get_keys_ptr().get());
const auto& serialized_sparse_column_offsets =
assert_cast<const ColumnArray::Offsets64&>(map_column.get_offsets());
const auto& serialized_sparse_column_offsets = map_column.get_offsets();
auto& count_map = *stats->mutable_sparse_column_non_null_size();
// Iterate through all paths in the sparse column
for (size_t i = row_pos; i != row_pos + num_rows; ++i) {
Expand Down
Loading
Loading