Skip to content

Commit

Permalink
Merge pull request #270 from den818/LC-bug
Browse files Browse the repository at this point in the history
fix bug in ColumnLowCardinality::Load
  • Loading branch information
Enmk authored Dec 19, 2022
2 parents 4251535 + 76cc8ee commit d03dbfe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clickhouse/columns/lowcardinality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ auto Load(ColumnRef new_dictionary_column, InputStream& input, size_t rows) {

if (auto nullable = new_dictionary_column->As<ColumnNullable>()) {
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);
}
}
Expand Down
39 changes: 38 additions & 1 deletion ut/low_cardinality_nullable_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,43 @@ TEST(LowCardinalityOfNullable, InsertAndQuery) {
});
}

TEST(LowCardinalityOfNullable, InsertAndQueryOneRow) {
const auto rowsData = std::vector<std::string> {
"eminem"
};

const auto nulls = std::vector<uint8_t> {
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<ColumnLowCardinality>();
auto item = lc_col->GetItem(row);

if (nulls[row]) {
ASSERT_EQ(Type::Code::Void, item.type);
} else {
ASSERT_EQ(rowsData[row], item.get<std::string_view>());
}
}
});
}


TEST(LowCardinalityOfNullable, InsertAndQueryEmpty) {
auto column = buildTestColumn({}, {});

Expand Down Expand Up @@ -113,4 +150,4 @@ TEST(LowCardinalityOfNullable, ThrowOnBackwardsCompatibleLCColumn) {
client.Select("SELECT * FROM lc_of_nullable", [&](const Block& bl) {
ASSERT_EQ(bl.GetRowCount(), 0u);
});
}
}

0 comments on commit d03dbfe

Please sign in to comment.