| 670 | |
| 671 | template <TypeKind kind> |
| 672 | void fuzzFlatPrimitiveImpl( |
| 673 | const VectorPtr& vector, |
| 674 | FuzzerGenerator& rng, |
| 675 | const VectorFuzzer::Options& opts) { |
| 676 | using TFlat = typename KindToFlatVector<kind>::type; |
| 677 | using TCpp = typename TypeTraits<kind>::NativeType; |
| 678 | |
| 679 | auto flatVector = vector->as<TFlat>(); |
| 680 | std::string strBuf; |
| 681 | |
| 682 | // Randomly generate a reusable part (substring) to prepare for incremental |
| 683 | // string generation. |
| 684 | size_t reusablePartLength = opts.enableStringIncrementalGeneration |
| 685 | ? rand<uint32_t>(rng) % opts.stringLength |
| 686 | : 0; |
| 687 | std::u32string reusablePartBuffer; |
| 688 | reusablePartBuffer.resize(reusablePartLength); |
| 689 | fillBuffer(reusablePartBuffer, 0, reusablePartLength, rng, opts); |
| 690 | |
| 691 | for (size_t i = 0; i < vector->size(); ++i) { |
| 692 | if constexpr (std::is_same_v<TCpp, StringView>) { |
| 693 | if (opts.genTimestampString) { |
| 694 | auto str = |
| 695 | std::to_string(randTimestamp(rng, opts).toNanos()).substr(0, 10); |
| 696 | for (int j = 0; j < rand<uint>(rng) % 24; ++j) { |
| 697 | str += fmt::format( |
| 698 | ",{}", |
| 699 | std::to_string(randTimestamp(rng, opts).toNanos()).substr(0, 10)); |
| 700 | } |
| 701 | flatVector->set(i, StringView(str)); |
| 702 | } else { |
| 703 | if (i == 0) { |
| 704 | clearInputCorpus(inputCorpus<std::string>); |
| 705 | } |
| 706 | |
| 707 | bool selectFromInputCorpus = rand<bool>(rng); |
| 708 | size_t stringInputCorpusSize = inputCorpus<std::string>.size(); |
| 709 | if (opts.enableDuplicates && selectFromInputCorpus && |
| 710 | stringInputCorpusSize > 0) { |
| 711 | // Reuse an existing string from the corpus as the next input. |
| 712 | auto index = rand<size_t>(rng) % stringInputCorpusSize; |
| 713 | auto selectedStringFromCorpus = |
| 714 | getInputFromInputCorpus(inputCorpus<std::string>, index); |
| 715 | flatVector->set(i, StringView(selectedStringFromCorpus)); |
| 716 | } else { |
| 717 | // Generate a new string as the next input. |
| 718 | bool doStringIncrementalGeneration = |
| 719 | opts.enableStringIncrementalGeneration ? rand<bool>(rng) : false; |
| 720 | |
| 721 | auto newString = randString( |
| 722 | rng, |
| 723 | opts, |
| 724 | strBuf, |
| 725 | doStringIncrementalGeneration, |
| 726 | reusablePartBuffer, |
| 727 | reusablePartLength); |
| 728 | |
| 729 | std::string newStringCopy(newString.data(), newString.size()); |
nothing calls this directly
no test coverage detected