Skip to content

Commit 5bc1985

Browse files
authored
Merge pull request #272 from den818/LC-bug2
fix bug with load/save Array with empty arrays
2 parents d03dbfe + ef2b908 commit 5bc1985

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

clickhouse/columns/array.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ bool ColumnArray::LoadBody(InputStream* input, size_t rows) {
8484
if (!offsets_->LoadBody(input, rows)) {
8585
return false;
8686
}
87-
if (!data_->LoadBody(input, (*offsets_)[rows - 1])) {
87+
const auto nested_rows = (*offsets_)[rows - 1];
88+
if (nested_rows == 0) {
89+
return true;
90+
}
91+
if (!data_->LoadBody(input, nested_rows)) {
8892
return false;
8993
}
9094
return true;
@@ -96,7 +100,9 @@ void ColumnArray::SavePrefix(OutputStream* output) {
96100

97101
void ColumnArray::SaveBody(OutputStream* output) {
98102
offsets_->SaveBody(output);
99-
data_->SaveBody(output);
103+
if (data_->Size() > 0) {
104+
data_->SaveBody(output);
105+
}
100106
}
101107

102108
void ColumnArray::Clear() {

ut/client_ut.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,31 @@ TEST_P(ClientCase, RoundtripArrayTString) {
10371037
EXPECT_TRUE(CompareRecursive(*array, *result_typed));
10381038
}
10391039

1040+
TEST_P(ClientCase, RoundtripArrayLowCardinalityTString) {
1041+
// TODO replase by Roundtrip test
1042+
using TestColumn = ColumnArrayT<ColumnLowCardinalityT<ColumnString>>;
1043+
1044+
Block block;
1045+
auto array = createTableWithOneColumn<TestColumn>(block);
1046+
array->Append(std::vector<std::string>{});
1047+
array->Append(std::vector<std::string>{});
1048+
1049+
block.RefreshRowCount();
1050+
client_->Insert(table_name, block);
1051+
1052+
size_t total_rows = 0;
1053+
client_->Select(getOneColumnSelectQuery(),
1054+
[&total_rows](const Block& block) {
1055+
total_rows += block.GetRowCount();
1056+
if (block.GetRowCount() == 0) {
1057+
return;
1058+
}
1059+
}
1060+
);
1061+
1062+
ASSERT_EQ(total_rows, 2u);
1063+
}
1064+
10401065
TEST_P(ClientCase, RoundtripMapTUint64String) {
10411066
using Map = ColumnMapT<ColumnUInt64, ColumnString>;
10421067
auto map = std::make_shared<Map>(std::make_shared<ColumnUInt64>(), std::make_shared<ColumnString>());

0 commit comments

Comments
 (0)