@@ -122,22 +122,19 @@ inline auto GetNullItemForDictionary(const ColumnRef dictionary) {
122
122
namespace clickhouse {
123
123
ColumnLowCardinality::ColumnLowCardinality (ColumnRef dictionary_column)
124
124
: Column(Type::CreateLowCardinality(dictionary_column->Type ())),
125
- dictionary_column_(dictionary_column),
125
+ dictionary_column_(dictionary_column-> Slice ( 0 , 0 )), // safe way to get an column of the same type.
126
126
index_column_(std::make_shared<ColumnUInt32>())
127
127
{
128
- if (dictionary_column_->Size () != 0 ) {
129
- // When dictionary column was constructed with values, re-add values by copying to update index and unique_items_map.
130
- // TODO: eliminate data copying by coming with better solution than doing AppendUnsafe() N times.
131
-
132
- // Steal values into temporary column.
133
- auto values = dictionary_column_->Slice (0 , 0 );
134
- values->Swap (*dictionary_column_);
135
-
128
+ if (dictionary_column->Size () != 0 ) {
136
129
AppendNullItemToEmptyColumn ();
137
130
138
- // Re-add values, updating index and unique_items_map.
139
- for (size_t i = 0 ; i < values->Size (); ++i)
140
- AppendUnsafe (values->GetItem (i));
131
+ // Add values, updating index_column_ and unique_items_map_.
132
+ for (size_t i = 0 ; i < dictionary_column->Size (); ++i) {
133
+ // TODO: it would be possible to eliminate copying
134
+ // by adding InsertUnsafe(pos, ItemView) method to a Column,
135
+ // but that is too much work for now.
136
+ AppendUnsafe (dictionary_column->GetItem (i));
137
+ }
141
138
} else {
142
139
AppendNullItemToEmptyColumn ();
143
140
}
@@ -304,8 +301,7 @@ ColumnRef ColumnLowCardinality::Slice(size_t begin, size_t len) {
304
301
begin = std::min (begin, Size ());
305
302
len = std::min (len, Size () - begin);
306
303
307
- ColumnRef new_dictionary = dictionary_column_->Slice (0 , 0 );
308
- auto result = std::make_shared<ColumnLowCardinality>(new_dictionary);
304
+ auto result = std::make_shared<ColumnLowCardinality>(dictionary_column_->Slice (0 , 0 ));
309
305
310
306
for (size_t i = begin; i < begin + len; ++i)
311
307
result->AppendUnsafe (this ->GetItem (i));
0 commit comments