@@ -98,12 +98,10 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
9898 }
9999
100100 void insert_data (const char * pos, size_t /* length*/ ) override {
101- _codes. push_back (unaligned_load<T>(pos)) ;
101+ LOG ( FATAL ) << " insert_data not supported in ColumnDictionary " ;
102102 }
103103
104- void insert_data (const T value) { _codes.push_back (value); }
105-
106- void insert_default () override { _codes.push_back (T ()); }
104+ void insert_default () override { _codes.push_back (_dict.get_null_code ()); }
107105
108106 void clear () override {
109107 _codes.clear ();
@@ -219,13 +217,12 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
219217 void insert_many_dict_data (const int32_t * data_array, size_t start_index,
220218 const StringRef* dict_array, size_t data_num,
221219 uint32_t dict_num) override {
222- if (! is_dict_inited ()) {
220+ if (_dict. empty ()) {
223221 _dict.reserve (dict_num);
224222 for (uint32_t i = 0 ; i < dict_num; ++i) {
225223 auto value = StringValue (dict_array[i].data , dict_array[i].size );
226224 _dict.insert_value (value);
227225 }
228- _dict_inited = true ;
229226 }
230227
231228 char * end_ptr = (char *)_codes.get_end_ptr ();
@@ -263,8 +260,6 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
263260 return _dict.find_codes (values);
264261 }
265262
266- bool is_dict_inited () const { return _dict_inited; }
267-
268263 bool is_dict_sorted () const { return _dict_sorted; }
269264
270265 bool is_dict_code_converted () const { return _dict_code_converted; }
@@ -301,13 +296,17 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
301296 if (it != _inverted_index.end ()) {
302297 return it->second ;
303298 }
304- return -1 ;
299+ return -2 ; // -1 is null code
305300 }
306301
307- inline StringValue& get_value (T code) { return _dict_data[code]; }
302+ T get_null_code () { return -1 ; }
303+
304+ inline StringValue& get_value (T code) {
305+ return code >= _dict_data.size () ? _null_value : _dict_data[code];
306+ }
308307
309308 inline void generate_hash_values () {
310- if (_hash_values.size () == 0 ) {
309+ if (_hash_values.empty () ) {
311310 _hash_values.resize (_dict_data.size ());
312311 for (size_t i = 0 ; i < _dict_data.size (); i++) {
313312 auto & sv = _dict_data[i];
@@ -380,7 +379,10 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
380379
381380 size_t byte_size () { return _dict_data.size () * sizeof (_dict_data[0 ]); }
382381
382+ bool empty () { return _dict_data.empty (); }
383+
383384 private:
385+ StringValue _null_value = StringValue();
384386 StringValue::Comparator _comparator;
385387 // dict code -> dict value
386388 DictContainer _dict_data;
@@ -398,16 +400,12 @@ class ColumnDictionary final : public COWHelper<IColumn, ColumnDictionary<T>> {
398400
399401private:
400402 size_t _reserve_size;
401- bool _dict_inited = false ;
402403 bool _dict_sorted = false ;
403404 bool _dict_code_converted = false ;
404405 Dictionary _dict;
405406 Container _codes;
406407};
407408
408- template class ColumnDictionary <uint8_t >;
409- template class ColumnDictionary <uint16_t >;
410- template class ColumnDictionary <uint32_t >;
411409template class ColumnDictionary <int32_t >;
412410
413411using ColumnDictI32 = vectorized::ColumnDictionary<doris::vectorized::Int32>;
0 commit comments