From eff434dca70aeb47b343af758b7ba2e4f3f8fbf0 Mon Sep 17 00:00:00 2001 From: amorynan Date: Mon, 2 Dec 2024 16:29:34 +0800 Subject: [PATCH] fix some code --- be/test/vec/columns/column_ip_test.cpp | 17 +----- be/test/vec/columns/common_column_test.h | 76 +++--------------------- 2 files changed, 9 insertions(+), 84 deletions(-) diff --git a/be/test/vec/columns/column_ip_test.cpp b/be/test/vec/columns/column_ip_test.cpp index 4049a63884ef26..a3167d16d3726a 100644 --- a/be/test/vec/columns/column_ip_test.cpp +++ b/be/test/vec/columns/column_ip_test.cpp @@ -277,29 +277,14 @@ TEST_F(ColumnIPTest, AppendDataBySelectorTest) { check_data(ip_cols, serde, ';', {1, 2}, data_files[0], assert_append_data_by_selector_callback); } -struct IndexInRangeUInt32Transform { - Field operator()(size_t range_index, size_t index_in_range) const { - return Field(static_cast(range_index * index_in_range)); - } -}; - -struct IndexInRangeUInt64Transform { - Field operator()(size_t range_index, size_t index_in_range) const { - return Field(static_cast(range_index * index_in_range)); - } -}; - TEST_F(ColumnIPTest, PermutationAndSortTest) { // insert from data csv and assert insert result MutableColumns ip_cols; ip_cols.push_back(column_ipv4->get_ptr()); ip_cols.push_back(column_ipv6->get_ptr()); - load_data_from_csv(serde, ip_cols, data_files[0], ';', {1, 2}); - // this function will make res not equal ?! + load_data_from_csv(serde, ip_cols, data_files[1], ';', {1, 2}); assertColumnPermutations(column_ipv4->assume_mutable_ref(), dt_ipv4); assertColumnPermutations(column_ipv6->assume_mutable_ref(), dt_ipv6); - // assertColumnPermutations(column_ipv4->assume_mutable_ref(), IndexInRangeUInt32Transform()); - // assertColumnPermutations(column_ipv6->assume_mutable_ref(), IndexInRangeUInt64Transform()); } TEST_F(ColumnIPTest, FilterTest) { diff --git a/be/test/vec/columns/common_column_test.h b/be/test/vec/columns/common_column_test.h index 6002c35f07f3ae..0dc4d2ba6cc5ad 100644 --- a/be/test/vec/columns/common_column_test.h +++ b/be/test/vec/columns/common_column_test.h @@ -1661,22 +1661,24 @@ class CommonColumnTest : public ::testing::Test { // check append_data_by_selector with different selector std::vector> res; auto option = DataTypeSerDe::FormatOptions(); - // selector is range for the column, contain values from 0 to num_columns - 1. - const ColumnArray::Selector selector = {0, 1, 2, 3}; for (size_t i = 0; i < load_cols.size(); ++i) { auto& source_column = load_cols[i]; MutableColumnPtr res_col = source_column->clone_empty(); + // selector is range for the column, contain values from 0 to num_columns - 1. + // selector size should bigger than begin and end , + // because selector[i], i in range(begin,end), Make a DCHECK for this + const ColumnArray::Selector selector = {1, 2, 3, 0}; std::cout << "now we are in append_data_by_selector column : " << load_cols[i]->get_name() << " for column size : " << source_column->size() - << "with selector: " << *selector.data() << std::endl; - source_column->append_data_by_selector(res_col, selector, 0, source_column->size()); + << " with selector size: " << selector.size() << std::endl; + source_column->append_data_by_selector(res_col, selector, 0, 4); // check after append_data_by_selector: 1 in selector present the load cols data is selected and data should be default value auto ser_col = ColumnString::create(); ser_col->reserve(res_col->size()); VectorBufferWriter buffer_writer(*ser_col.get()); std::vector data; data.push_back("column: " + source_column->get_name() + - " with selector: " + std::to_string(*selector.data()) + + " with selector size : " + std::to_string(selector.size()) + " with ptr: " + std::to_string(res_col->size())); for (size_t j = 0; j < res_col->size(); ++j) { if (auto st = serders[i]->serialize_one_cell_to_json(*res_col, j, buffer_writer, @@ -2156,38 +2158,6 @@ class CommonColumnTest : public ::testing::Test { } } - // this function is common function to produce column, according to ColumnValueGetter - // this range_size can be set, and it is helpfully make common column data which can be inserted into columns. - template - void generateRanges(std::vector>& ranges, size_t range_size, - ColumnValueGetter getter) { - for (auto& range : ranges) { - range.clear(); - } - - size_t ranges_size = ranges.size(); - - for (size_t range_index = 0; range_index < ranges_size; ++range_index) { - for (size_t index_in_range = 0; index_in_range < range_size; ++index_in_range) { - auto value = getter(range_index, index_in_range); - ranges[range_index].emplace_back(value); - } - } - } - - void insertRangesIntoColumn(std::vector>& ranges, - const std::vector& ranges_permutations, - vectorized::IColumn& column) { - for (const auto& range_permutation : ranges_permutations) { - auto& range = ranges[range_permutation]; - std::cout << "insert value: " << range_permutation << "range size" << range.size() - << std::endl; - for (auto& value : range) { - column.insert(value); - } - } - } - // this function helps to check sort permutation behavior for column void stableGetColumnPermutation(const IColumn& column, bool ascending, size_t limit, int nan_direction_hint, IColumn::Permutation& out_permutation) { @@ -2256,7 +2226,7 @@ class CommonColumnTest : public ::testing::Test { std::cout << "expected_permutation: " << expected_permutation[i] << std::endl; } // step2. get permutation by column - column.get_permutation(ascending, limit, nan_direction_hint, actual_permutation); + column.get_permutation(!ascending, limit, nan_direction_hint, actual_permutation); std::cout << "actual_permutation size: " << actual_permutation.size() << std::endl; for (size_t i = 0; i < actual_permutation.size(); i++) { @@ -2286,36 +2256,6 @@ class CommonColumnTest : public ::testing::Test { EXPECT_EQ(col->size(), res_rows); } } - - // sort_column - // 1/ sort_column (called in sort_block to sort the column by given permutation) - void assertSortColumn(IColumn& column, IColumn::Permutation& permutation, size_t num_rows) { - // just make a simple sort function to sort the column - std::vector res_sorted; - // SortColumnDescription: - // Column number; - // int direction; /// 1 - ascending, -1 - descending. - // int nulls_direction; /// 1 - NULLs and NaNs are greater, -1 - less. - std::vector sort_desc; - SortColumnDescription _column_with_descend_null_greater = {1, -1, 1}; - SortColumnDescription _column_with_descend_null_less = {1, -1, -1}; - SortColumnDescription _column_with_ascend_null_greater = {1, 1, 1}; - SortColumnDescription _column_with_ascend_null_less = {1, 1, -1}; - sort_desc.emplace_back(_column_with_descend_null_greater); - sort_desc.emplace_back(_column_with_descend_null_less); - sort_desc.emplace_back(_column_with_ascend_null_greater); - sort_desc.emplace_back(_column_with_ascend_null_less); - EqualFlags flags(num_rows, 1); - EqualRange range {0, num_rows}; - for (auto& column_with_sort_desc : sort_desc) { - ColumnSorter sorter({&column, column_with_sort_desc}, 0); - column.sort_column(&sorter, flags, permutation, range, num_rows); - }; - // check the sort result for flags and ranges - for (size_t i = 0; i < num_rows; i++) { - std::cout << "i: " << i << " " << flags[i] << std::endl; - } - } }; } // namespace doris::vectorized \ No newline at end of file