Skip to content

Commit

Permalink
add fetch_row test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tishj committed Dec 13, 2024
1 parent 76ea2f4 commit 39161bd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/storage/compression/dictionary/decompression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ void CompressedStringScanState::Initialize(ColumnSegment &segment, bool initiali

block_size = segment.GetBlockManager().GetBlockSize();

dict = DictionaryCompression::GetDictionary(segment, *handle);
dictionary = make_buffer<Vector>(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<Vector>(segment.type, index_buffer_count);
dictionary_size = index_buffer_count;
auto dict_child_data = FlatVector::GetData<string_t>(*(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);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/compression/dictionary_compression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<idx_t>(row_id), 1);
scan_state.ScanToFlatVector(result, result_idx, NumericCast<idx_t>(row_id), 1);
}

//===--------------------------------------------------------------------===//
Expand Down
51 changes: 51 additions & 0 deletions test/sql/storage/compression/dictionary/fetch_row.test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 39161bd

Please sign in to comment.