From 6b8e2795777cb4b3846a9f6314adf80b2d0d5741 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 31 Oct 2025 14:25:33 +0800 Subject: [PATCH 1/2] fix ts2diff. --- cpp/src/encoding/ts2diff_decoder.h | 14 +++++++----- cpp/test/encoding/ts2diff_codec_test.cc | 29 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/cpp/src/encoding/ts2diff_decoder.h b/cpp/src/encoding/ts2diff_decoder.h index a19e61635..c1e102700 100644 --- a/cpp/src/encoding/ts2diff_decoder.h +++ b/cpp/src/encoding/ts2diff_decoder.h @@ -135,13 +135,14 @@ inline int32_t TS2DIFFDecoder::decode(common::ByteStream &in) { } return ret_value; } - if (current_index_++ >= write_index_) { - current_index_ = 0; - } // although it seems we are reading an int64, bit_width_ guarantees // that it does not overflow int32 stored_value_ = read_long(bit_width_, in); ret_value = stored_value_ + first_value_ + delta_min_; + if (current_index_++ >= write_index_) { + current_index_ = 0; + bits_left_ = 0; + } first_value_ = ret_value; return ret_value; } @@ -161,12 +162,13 @@ inline int64_t TS2DIFFDecoder::decode(common::ByteStream &in) { } return ret_value; } - if (current_index_++ >= write_index_) { - current_index_ = 0; - } stored_value_ = (int64_t)read_long(bit_width_, in); ret_value = stored_value_ + first_value_ + delta_min_; first_value_ = ret_value; + if (current_index_++ >= write_index_) { + current_index_ = 0; + bits_left_ = 0; + } return ret_value; } diff --git a/cpp/test/encoding/ts2diff_codec_test.cc b/cpp/test/encoding/ts2diff_codec_test.cc index f0f5b1e58..240a33e0a 100644 --- a/cpp/test/encoding/ts2diff_codec_test.cc +++ b/cpp/test/encoding/ts2diff_codec_test.cc @@ -206,4 +206,33 @@ TEST_F(TS2DIFFCodecTest, LargeDataTest) { std::cout << "Decode time: " << decode_duration.count() << "ms\n"; } +TEST_F(TS2DIFFCodecTest, TestEncodingLast) { + common::ByteStream out_stream(1024, common::MOD_TS2DIFF_OBJ, false); + common::ByteStream out_stream_int32(1024, common::MOD_TS2DIFF_OBJ, false); + const int row_num = 6; + int64_t data[row_num]; + memset(data, 0, sizeof(int64_t) * row_num); + for (int i = 0; i < row_num; i++) { + data[i] = i * i; + } + + for (int i = 0; i < row_num; i++) { + EXPECT_EQ(encoder_long_->encode(data[i], out_stream), common::E_OK); + EXPECT_EQ(encoder_int_->encode((int32_t)data[i], out_stream_int32), common::E_OK); + } + EXPECT_EQ(encoder_long_->flush(out_stream), common::E_OK); + EXPECT_EQ(encoder_int_->flush(out_stream_int32), common::E_OK); + + int64_t x; + int32_t y; + for (int i = 0; i < row_num; i++) { + EXPECT_EQ(decoder_long_->read_int64(x, out_stream), common::E_OK); + EXPECT_EQ(x, data[i]); + EXPECT_EQ(decoder_int_->read_int32(y, out_stream_int32), common::E_OK); + EXPECT_EQ(y, data[i]); + } + EXPECT_FALSE(decoder_long_->has_remaining(out_stream)); + EXPECT_FALSE(decoder_int_->has_remaining(out_stream_int32)); +} + } // namespace storage From 9cd756925eecc02a64dbe50ec7834163ba6f7a44 Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 31 Oct 2025 14:45:08 +0800 Subject: [PATCH 2/2] fix fmt. --- cpp/test/encoding/ts2diff_codec_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/test/encoding/ts2diff_codec_test.cc b/cpp/test/encoding/ts2diff_codec_test.cc index 240a33e0a..be16d4af2 100644 --- a/cpp/test/encoding/ts2diff_codec_test.cc +++ b/cpp/test/encoding/ts2diff_codec_test.cc @@ -218,7 +218,8 @@ TEST_F(TS2DIFFCodecTest, TestEncodingLast) { for (int i = 0; i < row_num; i++) { EXPECT_EQ(encoder_long_->encode(data[i], out_stream), common::E_OK); - EXPECT_EQ(encoder_int_->encode((int32_t)data[i], out_stream_int32), common::E_OK); + EXPECT_EQ(encoder_int_->encode((int32_t)data[i], out_stream_int32), + common::E_OK); } EXPECT_EQ(encoder_long_->flush(out_stream), common::E_OK); EXPECT_EQ(encoder_int_->flush(out_stream_int32), common::E_OK);