Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ The root `pom.xml` orchestrates all three via Maven profiles:
- The on-disk TsFile format must also remain consistent with Java for the same file-format version, including encoded/compressed payload structure, page/chunk headers, and metadata. Do not introduce language-specific file-format changes.
- For changes affecting codecs or the on-disk format, add or update regression tests covering codec behavior, boundary values, and block/page boundaries. Verify cross-language compatibility in both directions: Java must read files produced by the changed implementation, and the changed implementation must read Java-generated files.

## Skill Documentation
## CLI and Skill Synchronization

- When SDK functionality is added or changed, review the corresponding CLI integration (`cpp/tools/` and `java/tools/`, as applicable) and synchronize commands, options, defaults, supported types/codecs, and errors in the same change. Reuse SDK capability information where available and add regression tests. If no CLI change is applicable, explain why in the change description.
- When a code change alters behavior, update the affected skill documentation in the same change. This includes API and CLI behavior, defaults, errors, build workflows, and encoding/compression or file-format behavior.
- Review `skills/tsfile/` for SDK and format changes, and `skills/tsfile-cli/` plus `cpp/tools/skills/tsfile-cli/` for CLI changes. Update the relevant `SKILL.md`, references, examples, and helper scripts as needed, keeping duplicated CLI documentation consistent.
- A behavior change is incomplete until the skill instructions and examples describe the resulting behavior accurately.
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/reader/table_result_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void TableResultSet::materialize_current_row() {
uint32_t len = 0;
bool null = false;
row_record_->reset();
// RowRecord owns only the current row; release its previous string copies.
pa_.reset();
for (uint32_t i = 0; i < row_iterator_->get_column_count(); ++i) {
const auto value = row_iterator_->read(i, &len, &null);
if (!null) {
Expand Down
74 changes: 74 additions & 0 deletions cpp/test/reader/block/reusable_tsblock_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <gtest/gtest.h>

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <memory>
Expand All @@ -31,6 +32,7 @@
#include "file/tsfile_io_reader.h"
#include "file/write_file.h"
#include "reader/block/single_device_tsblock_reader.h"
#include "reader/table_result_set.h"
#include "reader/task/device_query_task.h"
#include "writer/tsfile_table_writer.h"

Expand All @@ -48,6 +50,78 @@ TupleDesc MakeDesc(const char* second_name, TSDataType second_type) {
return desc;
}

class SingleBlockReader : public TsBlockReader {
public:
explicit SingleBlockReader(TsBlock* block) : block_(block) {}
int has_next(bool& has_next) override {
has_next = !delivered_;
return E_OK;
}
int next(TsBlock*& block) override {
block = block_;
delivered_ = true;
return E_OK;
}
void close() override {}

private:
TsBlock* block_;
bool delivered_ = false;
};

TEST(TableResultSetMemoryTest, MaterializedStringsReuseRowStorage) {
libtsfile_init();
TupleDesc desc = MakeDesc("s", STRING);
desc.push_back(ColumnSchema("t", TEXT, UNCOMPRESSED, PLAIN));
desc.push_back(ColumnSchema("b", BLOB, UNCOMPRESSED, PLAIN));
const int row_count = 2048;
ReusableTsBlock reusable;
TsBlock* block = reusable.acquire(desc, row_count);
ASSERT_NE(block, nullptr);
RowAppender rows(block);
for (int64_t row = 0; row < row_count; ++row) {
ASSERT_TRUE(rows.add_row());
rows.append(0, reinterpret_cast<const char*>(&row), sizeof(row));
const std::string value(row % 4 == 0 ? 2048 : 128,
static_cast<char>('a' + row % 26));
for (uint32_t col = 1; col <= 3; ++col) {
if (row % 7 == 1)
rows.append_null(col);
else
rows.append(col, value.data(), value.size());
}
}
TableResultSet result(
std::unique_ptr<TsBlockReader>(new SingleBlockReader(block)),
{"s", "t", "b"}, {STRING, TEXT, BLOB});
auto& stats = ModStat::get_instance();
const int64_t baseline = stats.get_stat(MOD_TSFILE_READER);
int64_t peak = baseline;
for (int row = 0; row < row_count; ++row) {
bool has_next = false;
ASSERT_EQ(result.next(has_next), E_OK);
ASSERT_TRUE(has_next);
EXPECT_EQ(result.get_value<int64_t>(1), row);
for (uint32_t col = 2; col <= 4; ++col) {
ASSERT_EQ(result.is_null(col), row % 7 == 1);
if (!result.is_null(col)) {
EXPECT_EQ(result.get_value<String*>(col)->to_std_string(),
std::string(row % 4 == 0 ? 2048 : 128,
static_cast<char>('a' + row % 26)));
}
}
peak = std::max(peak, stats.get_stat(MOD_TSFILE_READER));
}
#ifdef ENABLE_MEM_STAT
// Only the current row's three strings should occupy the materialization
// arena, including oversized allocations; preceding rows must be released.
EXPECT_LE(peak - baseline, 8 * 1024);
#endif
result.close();
result.close();
EXPECT_EQ(stats.get_stat(MOD_TSFILE_READER), baseline);
}

TEST(ReusableTsBlockTest, ReusesTheBlockForTheSameLayout) {
ReusableTsBlock reusable;
TupleDesc desc = MakeDesc("v", INT64);
Expand Down
Loading
Loading