The string doesn't fit, there are no strings left in the encoding buffer that could potentially
398740 {
398741 auto strings = UnifiedVectorFormat::GetData<string_t>(vector_format);
398743
398745
398746 const bool recalculate_indices_space =
398747 append_state == DictionaryAppendState::ENCODED_ALL_UNIQUE
398748 ? false
398749 : ((tuple_count % BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE) == 0);
398750
398751 if (append_state == DictionaryAppendState::ENCODED_ALL_UNIQUE || is_null) {
398752 lookup = 0;
398753 } else {
398756 }
398757
398758 switch (append_state) {
398759 case DictionaryAppendState::NOT_ENCODED:
398760 case DictionaryAppendState::REGULAR: {
398761 if (append_state == DictionaryAppendState::REGULAR) {
398763 return AddLookup<DictionaryAppendState::REGULAR>(*this, lookup, recalculate_indices_space,
398764 fail_on_no_space);
398765 } else {
398767 return AddToDictionary<DictionaryAppendState::REGULAR>(*this, str, recalculate_indices_space,
398768 fail_on_no_space);
398769 }
398770 } else {
398772 return AddLookup<DictionaryAppendState::NOT_ENCODED>(*this, lookup, recalculate_indices_space,
398773 fail_on_no_space);
398774 } else {
398776 return AddToDictionary<DictionaryAppendState::NOT_ENCODED>(*this, str, recalculate_indices_space,
398777 fail_on_no_space);
398778 }
398779 }
398780 }
398781 case DictionaryAppendState::ENCODED: {
398782
398783
398784
398785
398786 bool fits;
398788 fits =
398789 AddLookup<DictionaryAppendState::ENCODED>(*this, lookup, recalculate_indices_space, fail_on_no_space);
398790 } else {
398792 fits = AddToDictionary<DictionaryAppendState::ENCODED>(*this, str, recalculate_indices_space,
398793 fail_on_no_space);
398794 }
398795 if (fits) {
398796 return fits;
398797 }
398800
398801 return false;
398802 }
398803
398804
398805
398808 return AddLookup<DictionaryAppendState::ENCODED>(*this, lookup, recalculate_indices_space,
398809 fail_on_no_space);
398810 } else {
398812 return AddToDictionary<DictionaryAppendState::ENCODED>(*this, str, recalculate_indices_space,
398813 fail_on_no_space);
398814 }
398815 }
398816 case DictionaryAppendState::ENCODED_ALL_UNIQUE: {
398817
398818
398819
398820#ifdef DEBUG
398821 auto temp_decoder = alloca(sizeof(duckdb_fsst_decoder_t));
398822 duckdb_fsst_import(reinterpret_cast<duckdb_fsst_decoder_t *>(temp_decoder), fsst_serialized_symbol_table.get());
398823 vector<unsigned char> decompress_buffer;
398824#endif
398825
398826 if (encoded_input.data.empty()) {
398827 encoded_input.offset = i;
398828 vector<unsigned char *> input_string_ptrs;
398829 vector<size_t> input_string_lengths;
398830 idx_t total_size = 0;
398831 for (
idx_t j = i; j < count; j++) {
398832 auto index = vector_format.sel->get_index(j);
398833#ifdef DEBUG
398835 D_ASSERT(vector_format.validity.RowIsValid(index));
398836#endif
398837 auto &to_encode = strings[
index];
398838 input_string_ptrs.push_back((unsigned char *)to_encode.GetData());
398839 input_string_lengths.push_back(to_encode.GetSize());
398840 total_size += to_encode.GetSize();
398841 }
398842
398843 size_t output_buffer_size = 7 + (2 * total_size);
398844 auto compressed_ptrs = vector<unsigned char *>(input_string_lengths.size(), nullptr);
398845 auto compressed_sizes = vector<size_t>(input_string_lengths.size(), 0);
398846 if (output_buffer_size > encoding_buffer_size) {
398847 encoding_buffer = make_unsafe_uniq_array_uninitialized<unsigned char>(output_buffer_size);
398848 encoding_buffer_size = output_buffer_size;
398849 }
398850
398851
398852
398853
398854
398855
398856
398857
398858
398859 auto fsst_encoder = reinterpret_cast<duckdb_fsst_encoder_t *>(encoder);
398860 auto res = duckdb_fsst_compress(fsst_encoder, input_string_lengths.size(), input_string_lengths.data(),
398861 input_string_ptrs.data(), output_buffer_size,
encoding_buffer.get(),
398862 compressed_sizes.data(), compressed_ptrs.data());
398863 if (res != input_string_lengths.size()) {
398864 throw FatalException("FSST compression failed to compress all input strings");
398865 }
398866
398867 for (
idx_t j = 0; j < input_string_lengths.size(); j++) {
398868 uint32_t size = UnsafeNumericCast<uint32_t>(compressed_sizes[j]);
398869 string_t encoded_string((const char *)compressed_ptrs[j], size);
398870
398871#ifdef DEBUG
398873 auto &uncompressed_str = strings[encoded_input.offset + j];
398874 decompress_buffer.resize(uncompressed_str.GetSize() + 1 + 100);
398875 auto decoded_std_string = FSSTPrimitives::DecompressValue(
398876 (void *)temp_decoder, reinterpret_cast<const char *>(compressed_ptrs[j]),
398877 (
idx_t)compressed_sizes[j], decompress_buffer);
398878
398879 D_ASSERT(decoded_std_string.size() == uncompressed_str.GetSize());
398880 string_t decompressed_string(reinterpret_cast<const char *>(decompress_buffer.data()),
398881 UnsafeNumericCast<uint32_t>(uncompressed_str.GetSize()));
398882 D_ASSERT(decompressed_string == uncompressed_str);
398883#endif
398884
398885 encoded_input.data.push_back(encoded_string);
398886 }
398887 }
398888
398889#ifdef DEBUG
398891 for (
idx_t j = encoded_input.offset; j < count; j++) {
398892 auto &uncompressed_string = strings[j];
398893 auto &compressed_string = encoded_input.data[j - encoded_input.offset];
398894
398895 decompress_buffer.resize(uncompressed_string.GetSize() + 1 + 100);
398896 auto decoded_std_string =
398897 FSSTPrimitives::DecompressValue((void *)temp_decoder, (const char *)compressed_string.GetData(),
398898 compressed_string.GetSize(), decompress_buffer);
398899
398900 D_ASSERT(decoded_std_string.size() == uncompressed_string.GetSize());
398901 string_t decompressed_string(reinterpret_cast<const char *>(decompress_buffer.data()),
398902 UnsafeNumericCast<uint32_t>(uncompressed_string.GetSize()));
398903 D_ASSERT(decompressed_string == uncompressed_string);
398904 }
398905
398906#endif
398907 auto &string = encoded_input.data[i - encoded_input.offset];
398908 return AddToDictionary<DictionaryAppendState::ENCODED_ALL_UNIQUE>(*this, string, recalculate_indices_space,
398909 fail_on_no_space);
398910 }
398911 };
398912 throw InternalException("Unreachable");
398913}
void FlushEncodingBuffer()
Definition duckdb.cpp:398409
unsafe_unique_array< unsigned char > encoding_buffer
This is used for FSST_ONLY, to store the memory of the encoded input.
Definition duckdb.cpp:398241