MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeImpl

Method executeImpl

src/Functions/repeat.cpp:219–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217 bool useDefaultImplementationForConstants() const override { return true; }
218
219 ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t /*input_rows_count*/) const override
220 {
221 const auto & col_str = arguments[0].column;
222 const auto & col_num = arguments[1].column;
223 ColumnPtr res;
224
225 if (const ColumnString * col = checkAndGetColumn<ColumnString>(col_str.get()))
226 {
227 if (const ColumnConst * col_num_const = checkAndGetColumn<ColumnConst>(col_num.get()))
228 {
229 auto col_res = ColumnString::create();
230 auto success = castType(arguments[1].type.get(), [&](const auto & type)
231 {
232 using DataType = std::decay_t<decltype(type)>;
233 using T = typename DataType::FieldType;
234 T times = col_num_const->getValue<T>();
235 RepeatImpl::vectorStrConstRepeat(col->getChars(), col->getOffsets(), col_res->getChars(), col_res->getOffsets(), times);
236 return true;
237 });
238
239 if (!success)
240 throw Exception(ErrorCodes::ILLEGAL_COLUMN, "Illegal column type {} of 'n' of function {}",
241 arguments[1].column->getName(), getName());
242
243 return col_res;
244 }
245 if (castType(
246 arguments[1].type.get(),
247 [&](const auto & type)
248 {
249 using DataType = std::decay_t<decltype(type)>;
250 using T = typename DataType::FieldType;
251 const ColumnVector<T> & column = checkAndGetColumn<ColumnVector<T>>(*col_num);
252 auto col_res = ColumnString::create();
253 RepeatImpl::vectorStrVectorRepeat(
254 col->getChars(), col->getOffsets(), col_res->getChars(), col_res->getOffsets(), column.getData());
255 res = std::move(col_res);
256 return true;
257 }))
258 {
259 return res;
260 }
261 }
262 else if (const ColumnConst * col_const = checkAndGetColumn<ColumnConst>(col_str.get()))
263 {
264 /// Note that const-const case is handled by useDefaultImplementationForConstants.
265
266 std::string_view copy_str = col_const->getDataColumn().getDataAt(0);
267
268 if (castType(arguments[1].type.get(), [&](const auto & type)
269 {
270 using DataType = std::decay_t<decltype(type)>;
271 using T = typename DataType::FieldType;
272 const ColumnVector<T> & column = checkAndGetColumn<ColumnVector<T>>(*col_num);
273 auto col_res = ColumnString::create();
274 RepeatImpl::constStrVectorRepeat(copy_str, col_res->getChars(), col_res->getOffsets(), column.getData());
275 res = std::move(col_res);
276 return true;

Callers

nothing calls this directly

Calls 10

castTypeFunction · 0.85
createFunction · 0.70
getNameFunction · 0.70
ExceptionClass · 0.50
getMethod · 0.45
getCharsMethod · 0.45
getOffsetsMethod · 0.45
getNameMethod · 0.45
getDataMethod · 0.45
getDataAtMethod · 0.45

Tested by

no test coverage detected