Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f9bdb02
docs: add design spec for TsFile Unix-philosophy C++ CLI
SpriCoder Jun 1, 2026
f9d2d84
docs: add implementation plan for TsFile Unix CLI; refine spec
SpriCoder Jun 1, 2026
91baa30
Update TsFile CLI redesign spec
SpriCoder Jun 2, 2026
758d7e5
Add TsFile CLI redesign implementation plan
SpriCoder Jun 2, 2026
a392a56
Update tsfile CLI command surface
SpriCoder Jun 2, 2026
45b6aa3
Route ReadFile::open errors to stderr
SpriCoder Jun 2, 2026
9355288
Add tsfile CLI commands, formatters, build, and tests
SpriCoder Jun 2, 2026
59d6e4b
Consolidate TsFile CLI spec and plan
SpriCoder Jun 2, 2026
e3b4ce5
Extend tsfile stats with value summaries and shared stat helpers
SpriCoder Jun 2, 2026
8810f70
Add tsfile meta command
SpriCoder Jun 2, 2026
9e6ec59
Add tsfile count command
SpriCoder Jun 2, 2026
b3292b4
Add deterministic tsfile sample command
SpriCoder Jun 2, 2026
fdec8ee
Format tsfile CLI sources with clang-format
SpriCoder Jun 2, 2026
cd4efe2
Document CMake 4.x/ANTLR4 build constraint in CLI plan
SpriCoder Jun 2, 2026
e9738aa
Simplify sampled writer: trust caller-normalized limit
SpriCoder Jun 2, 2026
f16d969
Add tsfile-cli usage skill for inspecting .tsfile from the CLI
SpriCoder Jun 2, 2026
6bb1d9c
Rename CLI binary from tsfile to tsfile-cli
SpriCoder Jun 3, 2026
751daa9
Add tsfile CLI write (CSV/TSV import) design spec
SpriCoder Jun 3, 2026
0a698c6
Refine write spec: silent-by-default (-v summary) and opt-in --header…
SpriCoder Jun 3, 2026
9baaa22
Add tsfile CLI write implementation plan
SpriCoder Jun 3, 2026
dcef828
Add tsfile CLI input_format parsing layer
SpriCoder Jun 3, 2026
a151e65
Add tsfile CLI write argument parsing
SpriCoder Jun 3, 2026
591f3bb
Add tsfile CLI write command (CSV/TSV import)
SpriCoder Jun 3, 2026
9116ac4
Treat '-' as stdin positional, not an unknown flag
SpriCoder Jun 3, 2026
a575292
Format tsfile CLI write sources with clang-format
SpriCoder Jun 3, 2026
f41ccab
Update tsfile-cli skill to document the write command
SpriCoder Jun 3, 2026
9cee6c5
Condense tsfile-cli skill with formal notation
SpriCoder Jun 3, 2026
3ce68cc
Ignore .codegraph and cpp/root test-run artifacts
SpriCoder Jun 3, 2026
49b8cb3
Add QA learning log for tsfile CLI work
SpriCoder Jun 3, 2026
80ea038
Move tsfile-cli skill to cpp/tools/skills; stop tracking .claude
SpriCoder Jun 3, 2026
604dcc7
Stop tracking docs/superpowers and QA_Log.md (keep local, out of PR)
SpriCoder Jun 3, 2026
e3c0b5a
Add Apache license header to tsfile-cli skill doc (fix RAT check)
SpriCoder Jun 3, 2026
e47b151
Fix CLI test race: unique per-process temp filenames for parallel ctest
SpriCoder Jun 3, 2026
43f1a73
Simplify CLI test fixture: drop unused path param and atomic counter
SpriCoder Jun 3, 2026
4e1ffac
Add tsfile-cli tool README
SpriCoder Jun 3, 2026
d41cede
Expand tsfile-cli README: build-from-source and skill install
SpriCoder Jun 4, 2026
7bb6b62
Address PR #829 review feedback for tsfile-cli
SpriCoder Jun 5, 2026
0375385
Merge branch 'develop' into feat/tsfile-cli
SpriCoder Jun 5, 2026
57392f0
Harden tsfile-cli writes, errors, and input validation
SpriCoder Jun 5, 2026
7878aa2
Rename tsfile-cli stat_table.{h,cc} to statistics.{h,cc}
SpriCoder Jun 5, 2026
5509515
Add tests for tsfile-cli review hardening
SpriCoder Jun 5, 2026
a480e0f
Simplify scoped-command check in tsfile-cli flag validation
SpriCoder Jun 6, 2026
a8c38e3
Address PR #829 round 2 review feedback for tsfile-cli
SpriCoder Jun 8, 2026
032a574
Address PR #829 round 3 review feedback for tsfile-cli
SpriCoder Jun 8, 2026
6d30a8c
Show short-flag aliases in tsfile-cli write/validation error messages
SpriCoder Jun 8, 2026
02377a9
Clarify intent of RowWriter::emits_json_bare predicate
SpriCoder Jun 8, 2026
fda4ab0
Avoid per-cell copies in tsfile-cli write import hot loop
SpriCoder Jun 8, 2026
3249010
Strengthen tsfile-cli write tests; reject impossible DATE cells
SpriCoder Jun 8, 2026
7bedf88
Filter single-device tree query paths through the device schema
SpriCoder Jun 9, 2026
e11c1c6
Use set::find for the known-command membership check
SpriCoder Jun 9, 2026
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
21 changes: 16 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ build/*
cpp/third_party/zlib-1.3.1/treebuild.xml
cpp/third_party/zlib-1.3.1/zlib-1.3.1/treebuild.xml

# Claude Code
.claude/settings.local.json
.claude/todos/
.claude/worktrees/
.claude/scheduled_tasks.json
# Claude Code (local AI tooling — not uploaded; skill lives in cpp/tools/skills)
.claude/

# CodeGraph local index
.codegraph/

# Test-run artifacts (temp .tsfile/.dat written to the working dir or repo root)
cpp/cwrapper_*.tsfile
cpp/tsfile_writer_*.tsfile
cpp/*.dat
/*.tsfile
/*.dat

# AI workflow artifacts (kept local, not uploaded)
docs/superpowers/
/QA_Log.md
7 changes: 6 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ endif ()
option(BUILD_TEST "Build tests" ON)
message("cmake using: BUILD_TEST=${BUILD_TEST}")

option(BUILD_TOOLS "Build the tsfile command-line tools" ON)
message("cmake using: BUILD_TOOLS=${BUILD_TOOLS}")

option(ENABLE_ANTLR4 "Enable ANTLR4 runtime" ON)
message("cmake using: ENABLE_ANTLR4=${ENABLE_ANTLR4}")

Expand Down Expand Up @@ -262,6 +265,9 @@ endif ()
add_subdirectory(third_party)

add_subdirectory(src)
if (BUILD_TOOLS)
add_subdirectory(tools)
endif ()
if (BUILD_TEST)
add_subdirectory(test)
if (TESTS_ENABLED)
Expand All @@ -272,4 +278,3 @@ else()
endif ()

add_subdirectory(examples)

86 changes: 86 additions & 0 deletions cpp/src/common/csv_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "common/csv_utils.h"

namespace common {

std::vector<std::string> split_csv_line(const std::string& line, char delim,
bool csv_quotes) {
std::vector<std::string> out;
std::string field;
if (!csv_quotes) {
for (char c : line) {
if (c == delim) {
out.push_back(field);
field.clear();
} else {
field += c;
}
}
out.push_back(field);
return out;
}
bool in_quotes = false;
for (size_t i = 0; i < line.size(); ++i) {
char c = line[i];
if (in_quotes) {
if (c == '"') {
if (i + 1 < line.size() && line[i + 1] == '"') {
field += '"';
++i;
} else {
in_quotes = false;
}
} else {
field += c;
}
} else if (c == '"') {
in_quotes = true;
} else if (c == delim) {
out.push_back(field);
field.clear();
} else {
field += c;
}
}
out.push_back(field);
return out;
}

std::string csv_escape(const std::string& field, char delim) {
const char triggers[] = {delim, '"', '\n', '\r'};
bool needs_quote =
field.find_first_of(triggers, 0, sizeof(triggers)) != std::string::npos;
if (!needs_quote) {
return field;
}
std::string out = "\"";
for (char c : field) {
if (c == '"') {
out += "\"\"";
} else {
out += c;
}
}
out += "\"";
return out;
}

} // namespace common
44 changes: 44 additions & 0 deletions cpp/src/common/csv_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef COMMON_CSV_UTILS_H
#define COMMON_CSV_UTILS_H

#include <string>
#include <vector>

namespace common {

// Split a single logical line on `delim`. When `csv_quotes` is true the
// splitter is RFC 4180 aware: a field may be wrapped in double quotes, the
// delimiter is literal inside quotes, and a doubled quote ("") inside a quoted
// field is an escaped quote. When `csv_quotes` is false a quote is treated as
// ordinary data (suitable for TSV).
std::vector<std::string> split_csv_line(const std::string& line, char delim,
bool csv_quotes);

// Quote/escape a field for RFC 4180 CSV output: wrap in double quotes and
// double any embedded quote, but only when the field contains a delimiter,
// quote, or newline. The delimiter that triggers quoting is `delim` (default
// comma).
std::string csv_escape(const std::string& field, char delim = ',');

} // namespace common

#endif // COMMON_CSV_UTILS_H
38 changes: 38 additions & 0 deletions cpp/src/common/db_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#ifndef COMMON_DB_COMMON_H
#define COMMON_DB_COMMON_H

#include <cctype>
#include <functional>
#include <iostream>
#include <string>
#include <type_traits>
#include <unordered_set>

Expand Down Expand Up @@ -115,6 +117,42 @@ FORCE_INLINE const char* get_data_type_name(TSDataType type) {
return s_data_type_names[type];
}

// Parse a case-insensitive type name (e.g. "int32", "TIMESTAMP") into its
// TSDataType. Covers every named scalar type, not just the subset in
// s_data_type_names, so callers such as the CLI importer can accept the full
// set. Returns false for unrecognized names.
FORCE_INLINE bool parse_data_type_name(const std::string& s, TSDataType& out) {
std::string u;
u.reserve(s.size());
for (char c : s) {
u += static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
}
if (u == "BOOLEAN") {
out = BOOLEAN;
} else if (u == "INT32") {
out = INT32;
} else if (u == "INT64") {
out = INT64;
} else if (u == "FLOAT") {
out = FLOAT;
} else if (u == "DOUBLE") {
out = DOUBLE;
} else if (u == "TEXT") {
out = TEXT;
} else if (u == "STRING") {
out = STRING;
} else if (u == "TIMESTAMP") {
out = TIMESTAMP;
} else if (u == "DATE") {
out = DATE;
} else if (u == "BLOB") {
out = BLOB;
} else {
return false;
}
return true;
}

FORCE_INLINE const char* get_encoding_name(TSEncoding encoding) {
ASSERT(encoding >= PLAIN && encoding <= FREQ);
return s_encoding_names[encoding];
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/common/tablet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ template int Tablet::add_value(uint32_t row_index,
const std::string& measurement_name, double val);
template int Tablet::add_value(uint32_t row_index,
const std::string& measurement_name, String val);
template int Tablet::add_value(uint32_t row_index,
const std::string& measurement_name,
std::tm val);

void Tablet::set_column_categories(
const std::vector<ColumnCategory>& column_categories) {
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/file/read_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <fcntl.h>
#include <sys/stat.h>

#include <iostream>
#ifdef _WIN32
#include <io.h>
#include <windows.h>
Expand Down Expand Up @@ -49,10 +51,8 @@ int ReadFile::open(const std::string& file_path) {
file_path_ = file_path;
fd_ = ::open(file_path_.c_str(), O_RDONLY);
if (fd_ < 0) {
std::cout << "open file " << file_path << " error :" << fd_
<< std::endl;
std::cout << "open error" << errno << " " << strerror(errno)
<< std::endl;
std::cerr << "open file " << file_path << " error: " << strerror(errno)
<< " (errno " << errno << ")" << std::endl;
return E_FILE_OPEN_ERR;
}

Expand Down
49 changes: 48 additions & 1 deletion cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ if (${DOWNLOADED})
endif ()
add_subdirectory("${GTEST_SRC_ROOT}" "${CMAKE_BINARY_DIR}/googletest-build"
EXCLUDE_FROM_ALL)
# AppleClang searches /usr/local/include before CMake's generated -isystem
# paths, so a system-installed GTest can shadow the vendored headers. Force
# the vendored include dirs ahead for GTest's own sources here; the same is
# done for the consuming TsFile_Test target below (where header resolution
# actually matters for the test code).
foreach (GTEST_TARGET gtest gtest_main gmock gmock_main)
if (TARGET ${GTEST_TARGET})
target_include_directories(${GTEST_TARGET} BEFORE PRIVATE
${GTEST_SRC_ROOT}/googletest/include
${GTEST_SRC_ROOT}/googletest
${GTEST_SRC_ROOT}/googlemock/include
${GTEST_SRC_ROOT}/googlemock)
if (APPLE AND NOT MSVC)
target_compile_options(${GTEST_TARGET} BEFORE PRIVATE
-iquote${GTEST_SRC_ROOT}/googletest/include
-iquote${GTEST_SRC_ROOT}/googletest
-I${GTEST_SRC_ROOT}/googletest/include
-I${GTEST_SRC_ROOT}/googletest
-std=c++14)
endif ()
endif ()
endforeach ()
# Remember the vendored GTest header roots so they can be forced ahead of any
# system installation when compiling TsFile_Test itself.
set(VENDORED_GTEST_INCLUDE_DIRS
${GTEST_SRC_ROOT}/googletest/include
${GTEST_SRC_ROOT}/googlemock/include)
set(TESTS_ENABLED ON PARENT_SCOPE)
else ()
message(WARNING "Failed to download googletest from all provided URLs, setting TESTS_ENABLED to OFF")
Expand Down Expand Up @@ -186,6 +213,11 @@ if (ENABLE_ZLIB)
list(APPEND TEST_SRCS ${ZLIB_TEST_SRCS})
endif()

if (BUILD_TOOLS)
file(GLOB_RECURSE TOOLS_TEST_SRCS "tools/*_test.cc")
list(APPEND TEST_SRCS ${TOOLS_TEST_SRCS})
endif ()

if (${COV_ENABLED})
message("Enable code cov...")
add_compile_options(-fprofile-arcs -ftest-coverage)
Expand All @@ -197,12 +229,27 @@ if (ENABLE_ANTLR4)
endif()

add_executable(TsFile_Test ${TEST_SRCS})
# Force the vendored GTest headers ahead of any system installation so the test
# code reliably compiles against the vendored 1.12.1 headers.
if (VENDORED_GTEST_INCLUDE_DIRS)
target_include_directories(TsFile_Test BEFORE PRIVATE
${VENDORED_GTEST_INCLUDE_DIRS})
endif ()
if (BUILD_TOOLS)
target_include_directories(TsFile_Test PRIVATE ${CMAKE_SOURCE_DIR}/tools)
endif ()
if (APPLE AND NOT MSVC)
target_compile_options(TsFile_Test PRIVATE -std=c++14)
endif ()
target_link_libraries(
TsFile_Test
GTest::gtest_main
GTest::gmock
tsfile
)
if (BUILD_TOOLS)
target_link_libraries(TsFile_Test tsfile_cli_obj)
endif ()

set_target_properties(TsFile_Test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${LIB_TSFILE_SDK_DIR})

Expand Down Expand Up @@ -232,4 +279,4 @@ if(WIN32)
gtest_discover_tests(TsFile_Test DISCOVERY_MODE PRE_TEST DISCOVERY_TIMEOUT 120)
else()
gtest_discover_tests(TsFile_Test)
endif()
endif()
Loading
Loading