1818#include < iostream>
1919#include < incbin.h>
2020
21+ #include < Columns/ColumnNullable.h>
22+ #include < Columns/ColumnsNumber.h>
2123#include < Disks/DiskLocal.h>
24+ #include < DataTypes/DataTypeNullable.h>
25+ #include < DataTypes/DataTypeString.h>
2226#include < Formats/FormatFactory.h>
2327#include < Interpreters/Context.h>
2428#include < Interpreters/registerInterpreters.h>
@@ -59,6 +63,36 @@ TEST(TESTUtil, TestByteToLong)
5963 ASSERT_EQ (expected, result);
6064}
6165
66+ TEST (BlockUtil, ConvertNullableColumnAsNecessary)
67+ {
68+ auto string_type = std::make_shared<DataTypeString>();
69+ auto nullable_string_type = std::make_shared<DataTypeNullable>(string_type);
70+
71+ auto nested = string_type->createColumn ();
72+ nested->insert (" A" );
73+ nested->insert (" B" );
74+ auto null_map = ColumnUInt8::create (2 , 0 );
75+ ColumnWithTypeAndName nullable_column (
76+ ColumnNullable::create (std::move (nested), std::move (null_map)), nullable_string_type, " col_1" );
77+ ColumnWithTypeAndName sample_column (string_type, " broadcast_right_col_1" );
78+
79+ auto converted = BlockUtil::convertColumnAsNecessary (nullable_column, sample_column);
80+ ASSERT_TRUE (converted.type ->equals (*string_type));
81+ ASSERT_EQ (" broadcast_right_col_1" , converted.name );
82+ ASSERT_FALSE (converted.column ->isNullable ());
83+
84+ auto nested_with_null = string_type->createColumn ();
85+ nested_with_null->insert (" A" );
86+ nested_with_null->insertDefault ();
87+ auto null_map_with_null = ColumnUInt8::create ();
88+ null_map_with_null->insertValue (0 );
89+ null_map_with_null->insertValue (1 );
90+ ColumnWithTypeAndName nullable_column_with_null (
91+ ColumnNullable::create (std::move (nested_with_null), std::move (null_map_with_null)), nullable_string_type, " col_1" );
92+
93+ ASSERT_THROW (BlockUtil::convertColumnAsNecessary (nullable_column_with_null, sample_column), DB ::Exception);
94+ }
95+
6296TEST (ReadBufferFromFile, seekBackwards)
6397{
6498 static constexpr size_t N = 256 ;
@@ -110,4 +144,4 @@ int main(int argc, char ** argv)
110144
111145 ::testing::InitGoogleTest (&argc, argv);
112146 return RUN_ALL_TESTS ();
113- }
147+ }
0 commit comments