From 39161bdc7448458d4d68ac8452bd9c560085247b Mon Sep 17 00:00:00 2001 From: Tishj Date: Fri, 13 Dec 2024 16:12:55 +0100 Subject: [PATCH] add fetch_row test --- .../compression/dictionary/decompression.cpp | 8 +-- .../compression/dictionary_compression.cpp | 2 +- .../compression/dictionary/fetch_row.test | 51 +++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 test/sql/storage/compression/dictionary/fetch_row.test diff --git a/src/storage/compression/dictionary/decompression.cpp b/src/storage/compression/dictionary/decompression.cpp index 360aa8350ce6..a81c0e1221ee 100644 --- a/src/storage/compression/dictionary/decompression.cpp +++ b/src/storage/compression/dictionary/decompression.cpp @@ -42,16 +42,16 @@ void CompressedStringScanState::Initialize(ColumnSegment &segment, bool initiali block_size = segment.GetBlockManager().GetBlockSize(); + dict = DictionaryCompression::GetDictionary(segment, *handle); + dictionary = make_buffer(segment.type, index_buffer_count); + dictionary_size = index_buffer_count; + if (!initialize_dictionary) { // Used by fetch, as fetch will never produce a DictionaryVector return; } - dict = DictionaryCompression::GetDictionary(segment, *handle); - dictionary = make_buffer(segment.type, index_buffer_count); - dictionary_size = index_buffer_count; auto dict_child_data = FlatVector::GetData(*(dictionary)); - for (uint32_t i = 0; i < index_buffer_count; i++) { // NOTE: the passing of dict_child_vector, will not be used, its for big strings uint16_t str_len = GetStringLength(i); diff --git a/src/storage/compression/dictionary_compression.cpp b/src/storage/compression/dictionary_compression.cpp index 9536ccf6c6e6..1ea1bb326184 100644 --- a/src/storage/compression/dictionary_compression.cpp +++ b/src/storage/compression/dictionary_compression.cpp @@ -150,7 +150,7 @@ void DictionaryCompressionStorage::StringFetchRow(ColumnSegment &segment, Column // fetch a single row from the string segment CompressedStringScanState scan_state(state.GetOrInsertHandle(segment)); scan_state.Initialize(segment, false); - scan_state.ScanToFlatVector(result, result_idx, static_cast(row_id), 1); + scan_state.ScanToFlatVector(result, result_idx, NumericCast(row_id), 1); } //===--------------------------------------------------------------------===// diff --git a/test/sql/storage/compression/dictionary/fetch_row.test b/test/sql/storage/compression/dictionary/fetch_row.test new file mode 100644 index 000000000000..34b008fe6e3b --- /dev/null +++ b/test/sql/storage/compression/dictionary/fetch_row.test @@ -0,0 +1,51 @@ +# name: test/sql/storage/compression/dictionary/fetch_row.test +# description: Test storage with Dictionary compression +# group: [dictionary] + +require block_size 262144 + +# load the DB from disk +load __TEST_DIR__/test_dictionary_fetchrow.db + +statement ok +PRAGMA force_compression = 'dictionary' + +statement ok +CREATE TABLE test ( + a INTEGER, + b VARCHAR +); + +statement ok +INSERT INTO test (a, b) +SELECT x AS a, + CASE (x - 1) % 5 + WHEN 0 THEN 'aaaa' + WHEN 1 THEN 'bbbb' + WHEN 2 THEN 'cccc' + WHEN 3 THEN 'dddd' + WHEN 4 THEN NULL + END AS b +FROM range(10_000) t(x); + +statement ok +CHECKPOINT + +restart + +query I +SELECT compression FROM pragma_storage_info('test') WHERE segment_type ILIKE 'VARCHAR' LIMIT 1 +---- +Dictionary + +statement ok +pragma verify_fetch_row; + +query I +select distinct b from test order by a % 5; +---- +NULL +aaaa +bbbb +cccc +dddd