From db7734995789c99aafdf9d82a3feddbf1dec24ab Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Thu, 2 Sep 2021 20:43:42 +0300 Subject: [PATCH] add unit test for NestedUtils --- src/DataTypes/tests/gtest_NestedUtils.cpp | 43 +++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/DataTypes/tests/gtest_NestedUtils.cpp diff --git a/src/DataTypes/tests/gtest_NestedUtils.cpp b/src/DataTypes/tests/gtest_NestedUtils.cpp new file mode 100644 index 00000000000..c01758b8f0f --- /dev/null +++ b/src/DataTypes/tests/gtest_NestedUtils.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +using namespace DB; + +GTEST_TEST(NestedUtils, collect) +{ + DataTypePtr uint_type = std::make_shared(); + DataTypePtr array_type = std::make_shared(std::make_shared()); + + const NamesAndTypesList source_columns = + { + {"id", uint_type}, + {"arr1", array_type}, + {"b.id", uint_type}, + {"b.arr1", array_type}, + {"b.arr2", array_type} + }; + + auto nested_type = createNested({uint_type, uint_type}, {"arr1", "arr2"}); + const NamesAndTypesList columns_with_subcolumns = + { + {"id", uint_type}, + {"arr1", array_type}, + {"b.id", uint_type}, + {"b", "arr1", nested_type, array_type}, + {"b", "arr2", nested_type, array_type} + }; + + const NamesAndTypesList columns_with_nested = + { + {"id", uint_type}, + {"arr1", array_type}, + {"b.id", uint_type}, + {"b", nested_type}, + }; + + ASSERT_EQ(Nested::convertToSubcolumns(source_columns).toString(), columns_with_subcolumns.toString()); + ASSERT_EQ(Nested::collect(source_columns).toString(), columns_with_nested.toString()); +}