This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new cbcb81f3813 [FIX](complextype)fix compare_at base function support nested types (#29297) cbcb81f3813 is described below commit cbcb81f3813934e72f4fe949f3d026429a216821 Author: amory <amorywang...@gmail.com> AuthorDate: Sat Jan 6 12:05:43 2024 +0800 [FIX](complextype)fix compare_at base function support nested types (#29297) --- be/src/vec/columns/column.h | 1 + be/src/vec/columns/column_array.cpp | 20 ++++++++++++++++++++ be/src/vec/columns/column_array.h | 7 ++----- be/src/vec/columns/column_map.cpp | 29 +++++++++++++++++++++++++++++ be/src/vec/columns/column_map.h | 7 ++----- be/src/vec/columns/column_struct.cpp | 15 +++++++++++++++ be/src/vec/columns/column_struct.h | 6 +----- 7 files changed, 70 insertions(+), 15 deletions(-) diff --git a/be/src/vec/columns/column.h b/be/src/vec/columns/column.h index 25ad1145fc8..d67ad3e206b 100644 --- a/be/src/vec/columns/column.h +++ b/be/src/vec/columns/column.h @@ -453,6 +453,7 @@ public: * For example, if nan_direction_hint == -1 is used by descending sorting, NaNs will be at the end. * * For non Nullable and non floating point types, nan_direction_hint is ignored. + * For array/map/struct types, we compare with nested column element and offsets size */ virtual int compare_at(size_t n, size_t m, const IColumn& rhs, int nan_direction_hint) const = 0; diff --git a/be/src/vec/columns/column_array.cpp b/be/src/vec/columns/column_array.cpp index 0c926c0f31e..866a55c447f 100644 --- a/be/src/vec/columns/column_array.cpp +++ b/be/src/vec/columns/column_array.cpp @@ -254,6 +254,26 @@ StringRef ColumnArray::serialize_value_into_arena(size_t n, Arena& arena, return res; } +int ColumnArray::compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const { + // since column type is complex, we can't use this function + const auto& rhs = assert_cast<const ColumnArray&>(rhs_); + + size_t lhs_size = size_at(n); + size_t rhs_size = rhs.size_at(m); + size_t min_size = std::min(lhs_size, rhs_size); + for (size_t i = 0; i < min_size; ++i) { + if (int res = get_data().compare_at(offset_at(n) + i, rhs.offset_at(m) + i, *rhs.data.get(), + nan_direction_hint); + res) { + // if res != 0 , here is something different ,just return + return res; + } + } + + // then we check size of array + return lhs_size < rhs_size ? -1 : (lhs_size == rhs_size ? 0 : 1); +} + const char* ColumnArray::deserialize_and_insert_from_arena(const char* pos) { size_t array_size = unaligned_load<size_t>(pos); pos += sizeof(array_size); diff --git a/be/src/vec/columns/column_array.h b/be/src/vec/columns/column_array.h index ad8edbf7565..f2f187a7236 100644 --- a/be/src/vec/columns/column_array.h +++ b/be/src/vec/columns/column_array.h @@ -163,11 +163,8 @@ public: //ColumnPtr index(const IColumn & indexes, size_t limit) const; template <typename Type> ColumnPtr index_impl(const PaddedPODArray<Type>& indexes, size_t limit) const; - [[noreturn]] int compare_at(size_t n, size_t m, const IColumn& rhs_, - int nan_direction_hint) const override { - LOG(FATAL) << "compare_at not implemented"; - __builtin_unreachable(); - } + int compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const override; + [[noreturn]] void get_permutation(bool reverse, size_t limit, int nan_direction_hint, Permutation& res) const override { LOG(FATAL) << "get_permutation not implemented"; diff --git a/be/src/vec/columns/column_map.cpp b/be/src/vec/columns/column_map.cpp index 6981c25fc23..e46ea7fe683 100644 --- a/be/src/vec/columns/column_map.cpp +++ b/be/src/vec/columns/column_map.cpp @@ -231,6 +231,35 @@ const char* ColumnMap::deserialize_and_insert_from_arena(const char* pos) { return pos; } +int ColumnMap::compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const { + const auto& rhs = assert_cast<const ColumnMap&>(rhs_); + + size_t lhs_size = size_at(n); + size_t rhs_size = rhs.size_at(m); + + size_t lhs_offset = offset_at(n); + size_t rhs_offset = rhs.offset_at(m); + + size_t min_size = std::min(lhs_size, rhs_size); + + for (size_t i = 0; i < min_size; ++i) { + // if any value in key not equal, just return + if (int res = get_keys().compare_at(lhs_offset + i, rhs_offset + i, rhs.get_keys(), + nan_direction_hint); + res) { + return res; + } + // // if any value in value not equal, just return + if (int res = get_values().compare_at(lhs_offset + i, rhs_offset + i, rhs.get_values(), + nan_direction_hint); + res) { + return res; + } + } + + return lhs_size < rhs_size ? -1 : (lhs_size == rhs_size ? 0 : 1); +} + void ColumnMap::update_hash_with_value(size_t n, SipHash& hash) const { size_t kv_size = size_at(n); size_t offset = offset_at(n); diff --git a/be/src/vec/columns/column_map.h b/be/src/vec/columns/column_map.h index 59725111d73..45cedeb0d94 100644 --- a/be/src/vec/columns/column_map.h +++ b/be/src/vec/columns/column_map.h @@ -119,11 +119,8 @@ public: return scatter_impl<ColumnMap>(num_columns, selector); } - [[noreturn]] int compare_at(size_t n, size_t m, const IColumn& rhs_, - int nan_direction_hint) const override { - LOG(FATAL) << "compare_at not implemented"; - __builtin_unreachable(); - } + int compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const override; + void get_permutation(bool reverse, size_t limit, int nan_direction_hint, Permutation& res) const override { LOG(FATAL) << "get_permutation not implemented"; diff --git a/be/src/vec/columns/column_struct.cpp b/be/src/vec/columns/column_struct.cpp index 5a89b5d754c..4e69db0a545 100644 --- a/be/src/vec/columns/column_struct.cpp +++ b/be/src/vec/columns/column_struct.cpp @@ -185,6 +185,21 @@ const char* ColumnStruct::deserialize_and_insert_from_arena(const char* pos) { return pos; } +int ColumnStruct::compare_at(size_t n, size_t m, const IColumn& rhs_, + int nan_direction_hint) const { + const ColumnStruct& rhs = assert_cast<const ColumnStruct&>(rhs_); + + const size_t lhs_tuple_size = columns.size(); + const size_t rhs_tuple_size = rhs.tuple_size(); + const size_t min_size = std::min(lhs_tuple_size, rhs_tuple_size); + for (size_t i = 0; i < min_size; ++i) { + if (int res = columns[i]->compare_at(n, m, *rhs.columns[i], nan_direction_hint); res) { + return res; + } + } + return lhs_tuple_size > rhs_tuple_size ? 1 : (lhs_tuple_size < rhs_tuple_size ? -1 : 0); +} + void ColumnStruct::update_hash_with_value(size_t n, SipHash& hash) const { for (const auto& column : columns) { column->update_hash_with_value(n, hash); diff --git a/be/src/vec/columns/column_struct.h b/be/src/vec/columns/column_struct.h index a3141521e50..73f40713729 100644 --- a/be/src/vec/columns/column_struct.h +++ b/be/src/vec/columns/column_struct.h @@ -158,11 +158,7 @@ public: MutableColumns scatter(ColumnIndex num_columns, const Selector& selector) const override; // ColumnPtr index(const IColumn & indexes, size_t limit) const override; - [[noreturn]] int compare_at(size_t n, size_t m, const IColumn& rhs_, - int nan_direction_hint) const override { - LOG(FATAL) << "compare_at not implemented"; - __builtin_unreachable(); - } + int compare_at(size_t n, size_t m, const IColumn& rhs_, int nan_direction_hint) const override; MutableColumnPtr get_shrinked_column() override; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org