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

Method nextString

src/Client/BuzzHouse/Generator/RandomGenerator.cpp:355–434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

353}
354
355String RandomGenerator::nextString(const String & delimiter, const bool allow_nasty, const uint32_t limit)
356{
357 String ret;
358 bool use_bad_utf8 = false;
359
360 if (delimiter == "'" && this->nextMediumNumber() < 4)
361 {
362 ret += "x";
363 use_bad_utf8 = true;
364 }
365 ret += delimiter;
366 /* A few times generate empty strings */
367 if (this->nextMediumNumber() > 2)
368 {
369 if (use_bad_utf8 && this->nextBool())
370 {
371 /// Random hex bytes: variable length from 1 to limit bytes
372 const uint32_t max_bytes = std::min(limit, this->nextBool() ? UINT32_C(64) : UINT32_C(4096));
373 if (max_bytes > 0)
374 ret += nextHexBytes(this->randomInt<uint32_t>(1, max_bytes));
375 }
376 /// ~3% chance: repeated single character (stresses compression, string functions like repeat/position/like)
377 else if (!use_bad_utf8 && this->nextMediumNumber() < 4)
378 {
379 static const std::vector<char> repeat_chars = {'a', '0', ' ', '\t', '%', '_', '\\', '"', '/', '-'};
380 char c = this->pickRandomly(repeat_chars);
381
382 if (delimiter.size() == 1 && c == delimiter[0])
383 c = delimiter[0] == 'a' ? 'b' : 'a';
384 ret += String(this->randomInt<uint32_t>(0, std::min(limit, UINT32_C(65536))), c);
385 }
386 else
387 {
388 const String & pick = pickRandomly(
389 use_bad_utf8
390 ? bad_utf8
391 : (allow_nasty && this->nextSmallNumber() < 3 ? nasty_strings : (this->nextBool() ? common_english : common_chinese)));
392 if ((pick.length() >> (use_bad_utf8 ? 1 : 0)) < limit)
393 {
394 ret += pick;
395 /// A few times, generate a large string
396 if (this->nextMediumNumber() < 16)
397 {
398 uint32_t i = 0;
399 uint32_t len = static_cast<uint32_t>(pick.size());
400 const bool use_space = this->nextBool();
401 const uint32_t max_iterations = this->nextBool() ? 10000 : this->nextMediumNumber();
402
403 while (i < max_iterations)
404 {
405 const String & npick = pickRandomly(
406 use_bad_utf8
407 ? bad_utf8
408 : (allow_nasty && this->nextSmallNumber() < 3 ? nasty_strings
409 : (this->nextBool() ? common_english : common_chinese)));
410
411 len += (((use_space && !use_bad_utf8) ? 1 : 0) + (npick.length() >> (use_bad_utf8 ? 1 : 0)));
412 if (len < limit)

Callers 8

nextCommentMethod · 0.80
appendRandomRawValueMethod · 0.80
insertNumberEntryMethod · 0.80
homogeneousJSONArrayFunction · 0.80
strBuildJSONElementFunction · 0.80
getTablePathMethod · 0.80

Calls 7

nextMediumNumberMethod · 0.95
nextBoolMethod · 0.95
nextSmallNumberMethod · 0.95
minFunction · 0.50
StringClass · 0.50
sizeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected