diff --git a/clickhouse/columns/lowcardinality.cpp b/clickhouse/columns/lowcardinality.cpp index 0ffef7e0..2269a351 100644 --- a/clickhouse/columns/lowcardinality.cpp +++ b/clickhouse/columns/lowcardinality.cpp @@ -281,7 +281,7 @@ auto Load(ColumnRef new_dictionary_column, InputStream& input, size_t rows) { if (auto nullable = new_dictionary_column->As()) { nullable->Append(true); - for(std::size_t i = 1; i < new_index_column->Size(); i++) { + for(std::size_t i = 1; i < dataColumn->Size(); i++) { nullable->Append(false); } } diff --git a/ut/low_cardinality_nullable_tests.cpp b/ut/low_cardinality_nullable_tests.cpp index 41c0d3c5..8918f251 100644 --- a/ut/low_cardinality_nullable_tests.cpp +++ b/ut/low_cardinality_nullable_tests.cpp @@ -78,6 +78,43 @@ TEST(LowCardinalityOfNullable, InsertAndQuery) { }); } +TEST(LowCardinalityOfNullable, InsertAndQueryOneRow) { + const auto rowsData = std::vector { + "eminem" + }; + + const auto nulls = std::vector { + false + }; + + auto column = buildTestColumn(rowsData, nulls); + + Block block; + block.AppendColumn("words", column); + + Client client(ClientOptions(localHostEndpoint) + .SetBakcwardCompatibilityFeatureLowCardinalityAsWrappedColumn(false) + .SetPingBeforeQuery(true)); + + createTable(client); + + client.Insert("lc_of_nullable", block); + + client.Select("SELECT * FROM lc_of_nullable", [&](const Block& bl) { + for (size_t row = 0; row < bl.GetRowCount(); row++) { + auto lc_col = bl[0]->As(); + auto item = lc_col->GetItem(row); + + if (nulls[row]) { + ASSERT_EQ(Type::Code::Void, item.type); + } else { + ASSERT_EQ(rowsData[row], item.get()); + } + } + }); +} + + TEST(LowCardinalityOfNullable, InsertAndQueryEmpty) { auto column = buildTestColumn({}, {}); @@ -113,4 +150,4 @@ TEST(LowCardinalityOfNullable, ThrowOnBackwardsCompatibleLCColumn) { client.Select("SELECT * FROM lc_of_nullable", [&](const Block& bl) { ASSERT_EQ(bl.GetRowCount(), 0u); }); -} \ No newline at end of file +}