Skip to content

Commit d03dbfe

Browse files
authored
Merge pull request #270 from den818/LC-bug
fix bug in ColumnLowCardinality::Load
2 parents 4251535 + 76cc8ee commit d03dbfe

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

clickhouse/columns/lowcardinality.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ auto Load(ColumnRef new_dictionary_column, InputStream& input, size_t rows) {
281281

282282
if (auto nullable = new_dictionary_column->As<ColumnNullable>()) {
283283
nullable->Append(true);
284-
for(std::size_t i = 1; i < new_index_column->Size(); i++) {
284+
for(std::size_t i = 1; i < dataColumn->Size(); i++) {
285285
nullable->Append(false);
286286
}
287287
}

ut/low_cardinality_nullable_tests.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,43 @@ TEST(LowCardinalityOfNullable, InsertAndQuery) {
7878
});
7979
}
8080

81+
TEST(LowCardinalityOfNullable, InsertAndQueryOneRow) {
82+
const auto rowsData = std::vector<std::string> {
83+
"eminem"
84+
};
85+
86+
const auto nulls = std::vector<uint8_t> {
87+
false
88+
};
89+
90+
auto column = buildTestColumn(rowsData, nulls);
91+
92+
Block block;
93+
block.AppendColumn("words", column);
94+
95+
Client client(ClientOptions(localHostEndpoint)
96+
.SetBakcwardCompatibilityFeatureLowCardinalityAsWrappedColumn(false)
97+
.SetPingBeforeQuery(true));
98+
99+
createTable(client);
100+
101+
client.Insert("lc_of_nullable", block);
102+
103+
client.Select("SELECT * FROM lc_of_nullable", [&](const Block& bl) {
104+
for (size_t row = 0; row < bl.GetRowCount(); row++) {
105+
auto lc_col = bl[0]->As<ColumnLowCardinality>();
106+
auto item = lc_col->GetItem(row);
107+
108+
if (nulls[row]) {
109+
ASSERT_EQ(Type::Code::Void, item.type);
110+
} else {
111+
ASSERT_EQ(rowsData[row], item.get<std::string_view>());
112+
}
113+
}
114+
});
115+
}
116+
117+
81118
TEST(LowCardinalityOfNullable, InsertAndQueryEmpty) {
82119
auto column = buildTestColumn({}, {});
83120

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

0 commit comments

Comments
 (0)