Copilot commented on code in PR #634:
URL: https://github.com/apache/tsfile/pull/634#discussion_r2494384642
##########
cpp/test/reader/table_view/tsfile_reader_table_test.cc:
##########
@@ -421,3 +421,45 @@ TEST_F(TsFileTableReaderTest, ReadNonExistColumn) {
reader.close();
delete table_schema;
}
+
+TEST_F(TsFileTableReaderTest, TestDecoder) {
+ std::vector<ColumnSchema> column_schema;
+ column_schema.emplace_back("value1", TSDataType::INT32);
+ auto* schema = new TableSchema("test_table", column_schema);
+ auto tsfile_table_writer_ =
+ std::make_shared<TsFileTableWriter>(&write_file_, schema);
+ std::vector<std::string> columns = {"value1"};
+ std::vector<TSDataType> datatypes = {TSDataType::INT32};
+ storage::Tablet tablet("test_table", &columns, &datatypes, 5000);
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ std::uniform_int_distribution<> dis(1, 200);
+ int64_t timestamp = 0;
+ for (int i = 0; i < 5000; i++) {
+ // Time will bigger than value after encoding and compression.
+ timestamp += dis(gen);
+ tablet.add_timestamp(i, timestamp);
+ tablet.add_value(i, 0, (int32_t)i);
+ }
+ int ret_ = tsfile_table_writer_->write_table(tablet);
+ ret_ = tsfile_table_writer_->flush();
+ ret_ = tsfile_table_writer_->close();
Review Comment:
The return values from `write_table()`, `flush()`, and `close()` are stored
in `ret_` but never checked. These operations can fail and should be validated
with assertions like `ASSERT_EQ(ret_, common::E_OK);` to ensure proper error
handling in the test.
```suggestion
int ret_ = tsfile_table_writer_->write_table(tablet);
ASSERT_EQ(ret_, common::E_OK);
ret_ = tsfile_table_writer_->flush();
ASSERT_EQ(ret_, common::E_OK);
ret_ = tsfile_table_writer_->close();
ASSERT_EQ(ret_, common::E_OK);
```
##########
cpp/test/reader/table_view/tsfile_reader_table_test.cc:
##########
@@ -421,3 +421,45 @@ TEST_F(TsFileTableReaderTest, ReadNonExistColumn) {
reader.close();
delete table_schema;
}
+
+TEST_F(TsFileTableReaderTest, TestDecoder) {
+ std::vector<ColumnSchema> column_schema;
+ column_schema.emplace_back("value1", TSDataType::INT32);
+ auto* schema = new TableSchema("test_table", column_schema);
+ auto tsfile_table_writer_ =
+ std::make_shared<TsFileTableWriter>(&write_file_, schema);
+ std::vector<std::string> columns = {"value1"};
+ std::vector<TSDataType> datatypes = {TSDataType::INT32};
+ storage::Tablet tablet("test_table", &columns, &datatypes, 5000);
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ std::uniform_int_distribution<> dis(1, 200);
+ int64_t timestamp = 0;
+ for (int i = 0; i < 5000; i++) {
+ // Time will bigger than value after encoding and compression.
+ timestamp += dis(gen);
+ tablet.add_timestamp(i, timestamp);
+ tablet.add_value(i, 0, (int32_t)i);
+ }
+ int ret_ = tsfile_table_writer_->write_table(tablet);
+ ret_ = tsfile_table_writer_->flush();
+ ret_ = tsfile_table_writer_->close();
+ TsFileReader reader = TsFileReader();
+ reader.open(write_file_.get_file_path());
+ ResultSet* ret = nullptr;
+ int ret_value =
+ reader.query("test_table", columns, INT64_MIN, INT64_MAX, ret);
+ auto* table_result_set = (storage::TableResultSet*)ret;
+ bool has_next = false;
+ int cur_lin = 0;
+ int64_t time = 0;
+ while (IS_SUCC(table_result_set->next(has_next)) && has_next) {
+ auto t = table_result_set->get_value<int64_t>(1);
+ ASSERT_TRUE(t - time <= 200);
+ time += t;
Review Comment:
The assertion logic is incorrect. Line 458 checks if `t - time <= 200`
(where t is the current timestamp and time is accumulated), then line 459 adds
`t` to `time`. This should be checking if the difference between consecutive
timestamps is <= 200. The correct logic should be: `ASSERT_TRUE(t <= 200);`
followed by `time += t;`, or check `(t + time) - time <= 200` before the
addition, or store the previous timestamp and compare.
```suggestion
int64_t prev_time = 0;
while (IS_SUCC(table_result_set->next(has_next)) && has_next) {
auto t = table_result_set->get_value<int64_t>(1);
ASSERT_TRUE(t - prev_time <= 200);
prev_time = t;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]