From 0595b5c22b98324089633d0d75ad59ebe78ee768 Mon Sep 17 00:00:00 2001 From: Anton Popov Date: Wed, 13 Apr 2022 21:50:57 +0000 Subject: [PATCH] fix reading of empty arrays in reverse order --- .../CompressedReadBufferFromFile.cpp | 2 +- .../02267_empty_arrays_read_reverse.reference | 1 + .../02267_empty_arrays_read_reverse.sql | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02267_empty_arrays_read_reverse.reference create mode 100644 tests/queries/0_stateless/02267_empty_arrays_read_reverse.sql diff --git a/src/Compression/CompressedReadBufferFromFile.cpp b/src/Compression/CompressedReadBufferFromFile.cpp index 9efb3c92cde..a959da2c3ae 100644 --- a/src/Compression/CompressedReadBufferFromFile.cpp +++ b/src/Compression/CompressedReadBufferFromFile.cpp @@ -62,7 +62,7 @@ void CompressedReadBufferFromFile::seek(size_t offset_in_compressed_file, size_t { /// Nothing to do if we already at required position if (!size_compressed && static_cast(file_in.getPosition()) == offset_in_compressed_file && /// correct position in compressed file - (offset() == offset_in_decompressed_block /// correct position in buffer or + ((!buffer().empty() && offset() == offset_in_decompressed_block) /// correct position in buffer or || nextimpl_working_buffer_offset == offset_in_decompressed_block)) /// we will move our position to correct one return; diff --git a/tests/queries/0_stateless/02267_empty_arrays_read_reverse.reference b/tests/queries/0_stateless/02267_empty_arrays_read_reverse.reference new file mode 100644 index 00000000000..cc0cc5714d9 --- /dev/null +++ b/tests/queries/0_stateless/02267_empty_arrays_read_reverse.reference @@ -0,0 +1 @@ +['x'] 0 ['1','2','3','4','5','6'] diff --git a/tests/queries/0_stateless/02267_empty_arrays_read_reverse.sql b/tests/queries/0_stateless/02267_empty_arrays_read_reverse.sql new file mode 100644 index 00000000000..7c1cf47c540 --- /dev/null +++ b/tests/queries/0_stateless/02267_empty_arrays_read_reverse.sql @@ -0,0 +1,22 @@ +DROP TABLE IF EXISTS t_02267; + +CREATE TABLE t_02267 +( + a Array(String), + b UInt32, + c Array(String) +) +ENGINE = MergeTree +ORDER BY b +SETTINGS index_granularity = 500; + +INSERT INTO t_02267 (b, a, c) SELECT 0, ['x'], ['1','2','3','4','5','6'] FROM numbers(1) ; +INSERT INTO t_02267 (b, a, c) SELECT 1, [], ['1','2','3','4','5','6'] FROM numbers(300000); + +OPTIMIZE TABLE t_02267 FINAL; + +SELECT * FROM t_02267 WHERE hasAll(a, ['x']) +ORDER BY b DESC +SETTINGS max_threads=1, max_block_size=1000; + +DROP TABLE IF EXISTS t_02267;