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

Function homogeneousJSONArray

src/Client/BuzzHouse/Generator/SQLTypes.cpp:2521–2564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2519}
2520
2521static String homogeneousJSONArray(RandomGenerator & rg)
2522{
2523 /// Homogeneous typed array: pick element type once, generate 0-5 elements of that type
2524 String ret;
2525 std::uniform_int_distribution<int> alen(0, 30);
2526 std::uniform_int_distribution<int> atype(1, 9);
2527 const int nelems = alen(rg.generator);
2528 const int elem_type = atype(rg.generator);
2529
2530 for (int j = 0; j < nelems; j++)
2531 {
2532 if (j != 0)
2533 ret += ",";
2534 switch (elem_type)
2535 {
2536 case 1: {
2537 std::uniform_int_distribution<int> numbers(-1000, 1000);
2538 ret += std::to_string(numbers(rg.generator));
2539 break;
2540 }
2541 case 2: ret += std::to_string(rg.nextRandomInt64()); break;
2542 case 3: ret += std::to_string(rg.nextRandomUInt64()); break;
2543 case 4: ret += nextFloatingPoint(rg, true); break;
2544 case 5: ret += rg.nextString("\"", false, rg.nextStrlen()); break;
2545 case 6: ret += rg.nextBool() ? "true" : "false"; break;
2546 case 7: ret += "null"; break;
2547 case 8:
2548 /// Empty string
2549 ret += "\"\"";
2550 break;
2551 case 9: {
2552 /// Decimal
2553 std::uniform_int_distribution<uint32_t> next_dist(0, 76);
2554 const uint32_t left = next_dist(rg.generator);
2555 const uint32_t right = next_dist(rg.generator);
2556
2557 ret += appendDecimal(rg, false, left, right);
2558 }
2559 break;
2560 default: UNREACHABLE();
2561 }
2562 }
2563 return ret;
2564}
2565
2566String strBuildJSONArray(RandomGenerator & rg, const int jdepth, const int jwidth)
2567{

Callers 2

strBuildJSONArrayFunction · 0.85
strBuildJSONElementFunction · 0.85

Calls 8

nextFloatingPointFunction · 0.85
appendDecimalFunction · 0.85
nextRandomInt64Method · 0.80
nextRandomUInt64Method · 0.80
nextStringMethod · 0.80
nextStrlenMethod · 0.80
to_stringFunction · 0.50
nextBoolMethod · 0.45

Tested by

no test coverage detected