| 81 | |
| 82 | |
| 83 | ColumnPtr fillColumnWithRandomData( |
| 84 | const DataTypePtr type, |
| 85 | UInt64 limit, |
| 86 | UInt64 max_array_length, |
| 87 | UInt64 max_string_length, |
| 88 | pcg64 & rng, |
| 89 | ContextPtr context) |
| 90 | { |
| 91 | TypeIndex idx = type->getTypeId(); |
| 92 | |
| 93 | switch (idx) |
| 94 | { |
| 95 | case TypeIndex::String: |
| 96 | { |
| 97 | /// Mostly the same as the implementation of randomPrintableASCII function. |
| 98 | |
| 99 | auto column = ColumnString::create(); |
| 100 | ColumnString::Chars & data_to = column->getChars(); |
| 101 | ColumnString::Offsets & offsets_to = column->getOffsets(); |
| 102 | offsets_to.resize(limit); |
| 103 | |
| 104 | IColumn::Offset offset = 0; |
| 105 | for (size_t row_num = 0; row_num < limit; ++row_num) |
| 106 | { |
| 107 | size_t length = rng() % (max_string_length + 1); /// Slow |
| 108 | |
| 109 | IColumn::Offset next_offset = offset + length + 1; |
| 110 | data_to.resize(next_offset); |
| 111 | offsets_to[row_num] = next_offset; |
| 112 | |
| 113 | auto * data_to_ptr = data_to.data(); /// avoid assert on array indexing after end |
| 114 | for (size_t pos = offset, end = offset + length; pos < end; pos += 4) /// We have padding in column buffers that we can overwrite. |
| 115 | { |
| 116 | UInt64 rand = rng(); |
| 117 | |
| 118 | UInt16 rand1 = rand; |
| 119 | UInt16 rand2 = rand >> 16; |
| 120 | UInt16 rand3 = rand >> 32; |
| 121 | UInt16 rand4 = rand >> 48; |
| 122 | |
| 123 | /// Printable characters are from range [32; 126]. |
| 124 | /// https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ |
| 125 | |
| 126 | data_to_ptr[pos + 0] = 32 + ((rand1 * 95) >> 16); |
| 127 | data_to_ptr[pos + 1] = 32 + ((rand2 * 95) >> 16); |
| 128 | data_to_ptr[pos + 2] = 32 + ((rand3 * 95) >> 16); |
| 129 | data_to_ptr[pos + 3] = 32 + ((rand4 * 95) >> 16); |
| 130 | |
| 131 | /// NOTE gcc failed to vectorize this code (aliasing of char?) |
| 132 | /// TODO Implement SIMD optimizations from Danila Kutenin. |
| 133 | } |
| 134 | |
| 135 | data_to[offset + length] = 0; |
| 136 | |
| 137 | offset = next_offset; |
| 138 | } |
| 139 | |
| 140 | return column; |
no test coverage detected