From dff1bf335867c0e49d4e681ca80eb319a93f7760 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 3 Mar 2024 17:17:49 +0100 Subject: [PATCH] Remove unit test for ColumnObject --- src/Columns/tests/gtest_column_object.cpp | 157 ---------------------- 1 file changed, 157 deletions(-) delete mode 100644 src/Columns/tests/gtest_column_object.cpp diff --git a/src/Columns/tests/gtest_column_object.cpp b/src/Columns/tests/gtest_column_object.cpp deleted file mode 100644 index bef16e4fb56..00000000000 --- a/src/Columns/tests/gtest_column_object.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace DB; - -static pcg64 rng(randomSeed()); - -Field getRandomField(size_t type) -{ - switch (type) - { - case 0: - return rng(); - case 1: - return std::uniform_real_distribution<>(0.0, 1.0)(rng); - case 2: - return std::string(rng() % 10, 'a' + rng() % 26); - default: - return Field(); - } -} - -std::pair> generate(size_t size) -{ - bool has_defaults = rng() % 3 == 0; - size_t num_defaults = has_defaults ? rng() % size : 0; - - ColumnObject::Subcolumn subcolumn(num_defaults, false); - std::vector fields; - - while (subcolumn.size() < size) - { - size_t part_size = rng() % (size - subcolumn.size()) + 1; - size_t field_type = rng() % 3; - - for (size_t i = 0; i < part_size; ++i) - { - fields.push_back(getRandomField(field_type)); - subcolumn.insert(fields.back()); - } - } - - std::vector result_fields; - for (size_t i = 0; i < num_defaults; ++i) - result_fields.emplace_back(); - - result_fields.insert(result_fields.end(), fields.begin(), fields.end()); - return {std::move(subcolumn), std::move(result_fields)}; -} - -void checkFieldsAreEqual(ColumnObject::Subcolumn subcolumn, const std::vector & fields) -{ - ASSERT_EQ(subcolumn.size(), fields.size()); - for (size_t i = 0; i < subcolumn.size(); ++i) - { - Field field; - subcolumn.get(i, field); // Also check 'get' method. - if (!applyVisitor(FieldVisitorAccurateEquals(), field, fields[i])) - { - std::cerr << fmt::format("Wrong value at position {}, expected {}, got {}", - i, applyVisitor(FieldVisitorToString(), fields[i]), applyVisitor(FieldVisitorToString(), field)); - ASSERT_TRUE(false); - } - } -} - -constexpr size_t T = 1000; -constexpr size_t N = 1000; - -TEST(ColumnObject, InsertRangeFrom) -{ - for (size_t t = 0; t < T; ++t) - { - auto [subcolumn_dst, fields_dst] = generate(N); - auto [subcolumn_src, fields_src] = generate(N); - - ASSERT_EQ(subcolumn_dst.size(), fields_dst.size()); - ASSERT_EQ(subcolumn_src.size(), fields_src.size()); - - const auto & type_dst = subcolumn_dst.getLeastCommonType(); - const auto & type_src = subcolumn_src.getLeastCommonType(); - auto type_res = getLeastSupertypeOrString(DataTypes{type_dst, type_src}); - - size_t from = rng() % subcolumn_src.size(); - size_t to = rng() % subcolumn_src.size(); - if (from > to) - std::swap(from, to); - ++to; - - for (auto & field : fields_dst) - { - if (field.isNull()) - field = type_res->getDefault(); - else - field = convertFieldToTypeOrThrow(field, *type_res); - } - - for (size_t i = from; i < to; ++i) - { - if (fields_src[i].isNull()) - fields_dst.push_back(type_res->getDefault()); - else - fields_dst.push_back(convertFieldToTypeOrThrow(fields_src[i], *type_res)); - - } - - subcolumn_dst.insertRangeFrom(subcolumn_src, from, to - from); - checkFieldsAreEqual(subcolumn_dst, fields_dst); - } -} - -TEST(ColumnObject, Unflatten) -{ - auto check_empty_tuple = [](const auto & type, const auto & column) - { - const auto & type_tuple = assert_cast(*type); - const auto & column_tuple = assert_cast(*column); - - ASSERT_EQ(type_tuple.getElements().size(), 1); - ASSERT_EQ(type_tuple.getElements()[0]->getName(), "UInt8"); - ASSERT_EQ(type_tuple.getElementNames()[0], ColumnObject::COLUMN_NAME_DUMMY); - - ASSERT_EQ(column_tuple.getColumns().size(), 1); - ASSERT_EQ(column_tuple.getColumns()[0]->getName(), "UInt8"); - }; - - { - auto column_object = ColumnObject::create(false); - auto [column, type] = unflattenObjectToTuple(*column_object); - - check_empty_tuple(type, column); - ASSERT_EQ(column->size(), 0); - } - - { - auto column_object = ColumnObject::create(false); - column_object->insertManyDefaults(5); - auto [column, type] = unflattenObjectToTuple(*column_object); - - check_empty_tuple(type, column); - ASSERT_EQ(column->size(), 5); - } -}