Skip to content

fix bug in ColumnLowCardinality::Load #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}
}