You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tsfile.apache.org by co...@apache.org on 2025/11/29 04:16:02 UTC
(tsfile) 01/01: fix some comment.
This is an automated email from the ASF dual-hosted git repository.
colinlee pushed a commit to branch feature/python-new-datatypes
in repository https://gitbox.apache.org/repos/asf/tsfile.git
commit bc7e1b02065a4650938ea7dcf0ad5ea8c3b9f188
Author: ColinLee <sh...@163.com>
AuthorDate: Sat Nov 29 12:14:22 2025 +0800
fix some comment.
---
cpp/src/common/record.h | 2 +-
cpp/src/cwrapper/tsfile_cwrapper.cc | 11 --------
cpp/src/cwrapper/tsfile_cwrapper.h | 4 +--
cpp/test/cwrapper/cwrapper_test.cc | 29 ++++++++++++----------
.../reader/table_view/tsfile_reader_table_test.cc | 1 +
python/tests/test_write_and_read.py | 1 -
python/tsfile/tsfile_cpp.pxd | 4 ---
python/tsfile/tsfile_py_cpp.pyx | 18 +++++++-------
8 files changed, 28 insertions(+), 42 deletions(-)
diff --git a/cpp/src/common/record.h b/cpp/src/common/record.h
index cbbebbc5..a8449c65 100644
--- a/cpp/src/common/record.h
+++ b/cpp/src/common/record.h
@@ -118,7 +118,7 @@ struct TsRecord {
}
TsRecord(const std::string &device_name, const int64_t ×tamp)
- : device_id_(device_name), timestamp_(timestamp) {
+ : timestamp_(timestamp), device_id_(device_name) {
pa.init(512, common::MOD_TSFILE_READER);
}
diff --git a/cpp/src/cwrapper/tsfile_cwrapper.cc b/cpp/src/cwrapper/tsfile_cwrapper.cc
index 198be3cc..20c60446 100644
--- a/cpp/src/cwrapper/tsfile_cwrapper.cc
+++ b/cpp/src/cwrapper/tsfile_cwrapper.cc
@@ -280,17 +280,6 @@ TsRecord _ts_record_new(const char *device_id, Timestamp timestamp,
return common::E_OK; \
}
-ERRNO _insert_data_into_ts_record_by_name_string(TsRecord data,
- const char *measurement_name,
- const char *value) {
- auto *record = (storage::TsRecord *)data;
- if (record->points_.size() + 1 > record->points_.capacity())
- return common::E_BUF_NOT_ENOUGH;
- std::string str_value(value, strlen(value));
- record->add_point(measurement_name, common::String(str_value, record->pa));
- return common::E_OK;
-}
-
ERRNO _insert_data_into_ts_record_by_name_string_with_len(
TsRecord data, const char *measurement_name, const char *value,
const uint32_t value_len) {
diff --git a/cpp/src/cwrapper/tsfile_cwrapper.h b/cpp/src/cwrapper/tsfile_cwrapper.h
index 83f6536e..d4f5bc1e 100644
--- a/cpp/src/cwrapper/tsfile_cwrapper.h
+++ b/cpp/src/cwrapper/tsfile_cwrapper.h
@@ -625,9 +625,7 @@ INSERT_DATA_INTO_TS_RECORD_BY_NAME(int64_t);
INSERT_DATA_INTO_TS_RECORD_BY_NAME(bool);
INSERT_DATA_INTO_TS_RECORD_BY_NAME(float);
INSERT_DATA_INTO_TS_RECORD_BY_NAME(double);
-ERRNO _insert_data_into_ts_record_by_name_string(TsRecord data,
- const char* measurement_name,
- const char* value);
+
ERRNO _insert_data_into_ts_record_by_name_string_with_len(
TsRecord data, const char* measurement_name, const char* value,
const uint32_t value_len);
diff --git a/cpp/test/cwrapper/cwrapper_test.cc b/cpp/test/cwrapper/cwrapper_test.cc
index 0196625b..625e24ef 100644
--- a/cpp/test/cwrapper/cwrapper_test.cc
+++ b/cpp/test/cwrapper/cwrapper_test.cc
@@ -48,15 +48,14 @@ class CWrapperTest : public testing::Test {
TEST_F(CWrapperTest, TestForPythonInterfaceInsert) {
ERRNO code = 0;
- const int column_num = 10;
- char* filename = "cwrapper_for_python.tsfile";
+ const char* filename = "cwrapper_for_python.tsfile";
remove(filename); // Clean up any existing file
// Device and measurement definitions
- char* device_id = "root.device1";
- char* str_measurement_id = "str_measurement";
- char* text_measurement_id = "text_measurement";
- char* date_measurement_id = "date_measurement";
+ char* device_id = strdup("root.device1");
+ char* str_measurement_id = strdup("str_measurement");
+ char* text_measurement_id = strdup("text_measurement");
+ char* date_measurement_id = strdup("date_measurement");
// Define time series schemas for different data types
timeseries_schema str_measurement;
@@ -99,15 +98,15 @@ TEST_F(CWrapperTest, TestForPythonInterfaceInsert) {
auto* record = (storage::TsRecord*)_ts_record_new(device_id, 0, 3);
// Insert string data
- char* test_str = "test_string";
- ASSERT_OK(_insert_data_into_ts_record_by_name_string(
- record, str_measurement_id, test_str),
+ const char* test_str = "test_string";
+ ASSERT_OK(_insert_data_into_ts_record_by_name_string_with_len(
+ record, str_measurement_id, test_str, strlen(test_str)),
"insert data failed");
// Insert text data
- char* test_text = "test_text";
- ASSERT_OK(_insert_data_into_ts_record_by_name_string(
- record, text_measurement_id, test_text),
+ const char* test_text = "test_text";
+ ASSERT_OK(_insert_data_into_ts_record_by_name_string_with_len(
+ record, text_measurement_id, test_text, strlen(test_text)),
"insert data failed");
// Insert date data - NOTE: There's a bug here, should use
@@ -137,7 +136,7 @@ TEST_F(CWrapperTest, TestForPythonInterfaceInsert) {
// Verify the retrieved data matches what we inserted
bool has_next = false;
int row_count = 0;
- while (!result->next(has_next) && has_next) {
+ while (result->next(has_next) == common::E_OK && has_next) {
// Verify timestamp
EXPECT_EQ(result->get_value<int64_t>(1), row_count);
@@ -164,6 +163,10 @@ TEST_F(CWrapperTest, TestForPythonInterfaceInsert) {
}
ASSERT_OK(reader->close(), "close reader failed");
+ delete device_id;
+ delete str_measurement_id;
+ delete text_measurement_id;
+ delete date_measurement_id;
}
TEST_F(CWrapperTest, WriterFlushTabletAndReadData) {
diff --git a/cpp/test/reader/table_view/tsfile_reader_table_test.cc b/cpp/test/reader/table_view/tsfile_reader_table_test.cc
index 02398c68..c672a806 100644
--- a/cpp/test/reader/table_view/tsfile_reader_table_test.cc
+++ b/cpp/test/reader/table_view/tsfile_reader_table_test.cc
@@ -452,6 +452,7 @@ TEST_F(TsFileTableReaderTest, TestDecoder) {
ResultSet* ret = nullptr;
int ret_value =
reader.query("test_table", columns, INT64_MIN, INT64_MAX, ret);
+ ASSERT_EQ(ret_value, E_OK);
auto* table_result_set = (storage::TableResultSet*)ret;
bool has_next = false;
int cur_lin = 0;
diff --git a/python/tests/test_write_and_read.py b/python/tests/test_write_and_read.py
index ab916f21..665fcc2d 100644
--- a/python/tests/test_write_and_read.py
+++ b/python/tests/test_write_and_read.py
@@ -88,7 +88,6 @@ def test_row_record_write_and_read():
os.remove("record_write_and_read.tsfile")
-@pytest.mark.skip(reason="API not match")
def test_tablet_write_and_read():
try:
if os.path.exists("record_write_and_read.tsfile"):
diff --git a/python/tsfile/tsfile_cpp.pxd b/python/tsfile/tsfile_cpp.pxd
index 7a1fa567..8e5f9913 100644
--- a/python/tsfile/tsfile_cpp.pxd
+++ b/python/tsfile/tsfile_cpp.pxd
@@ -161,13 +161,9 @@ cdef extern from "./tsfile_cwrapper.h":
ErrorCode _insert_data_into_ts_record_by_name_double(TsRecord data, const char *measurement_name,
const double value);
ErrorCode _insert_data_into_ts_record_by_name_bool(TsRecord data, const char *measurement_name, const bint value);
- ErrorCode _insert_data_into_ts_record_by_name_string(TsRecord data, const char *measurement_name,
- const char *value);
ErrorCode _insert_data_into_ts_record_by_name_string_with_len(TsRecord data, const char *measurement_name,
const char *value,
const uint32_t value_len);
- #ErrorCode _insert_data_into_ts_record_by_name_blob(record, PyUnicode_AsUTF8(field.get_field_name()), field.get_bytes_value())
-
void _free_tsfile_ts_record(TsRecord * record);
# resulSet : query data from tsfile reader
diff --git a/python/tsfile/tsfile_py_cpp.pyx b/python/tsfile/tsfile_py_cpp.pyx
index 5016ad74..5e6b4d89 100644
--- a/python/tsfile/tsfile_py_cpp.pyx
+++ b/python/tsfile/tsfile_py_cpp.pyx
@@ -24,7 +24,7 @@ from libc.stdlib cimport free
from libc.stdlib cimport malloc
from libc.string cimport strdup
from cpython.exc cimport PyErr_SetObject
-from cpython.unicode cimport PyUnicode_AsUTF8String, PyUnicode_AsUTF8
+from cpython.unicode cimport PyUnicode_AsUTF8String, PyUnicode_AsUTF8, PyUnicode_AsUTF8AndSize
from cpython.bytes cimport PyBytes_AsString, PyBytes_AsStringAndSize
from tsfile.exceptions import ERROR_MAPPING
@@ -268,7 +268,7 @@ cdef Tablet to_c_tablet(object tablet):
if value[row] is not None:
tablet_add_value_by_index_double(ctablet, row, col, value[row])
- # STRING or TEXT
+ # STRING or TEXT or BLOB
elif data_type == TS_DATATYPE_STRING or data_type == TS_DATATYPE_TEXT or data_type == TS_DATATYPE_BLOB:
for row in range(max_row_num):
if value[row] is not None:
@@ -286,8 +286,9 @@ cdef TsRecord to_c_record(object row_record):
cdef int64_t timestamp = <int64_t>row_record.get_timestamp()
cdef bytes device_id_bytes = PyUnicode_AsUTF8String(row_record.get_device_id())
cdef const char* device_id = device_id_bytes
+ cdef const char* str_ptr
cdef char* blob_ptr
- cdef Py_ssize_t blob_len
+ cdef Py_ssize_t str_len
cdef TsRecord record
cdef int i
cdef TSDataType data_type
@@ -306,14 +307,13 @@ cdef TsRecord to_c_record(object row_record):
elif data_type == TS_DATATYPE_FLOAT:
_insert_data_into_ts_record_by_name_float(record, PyUnicode_AsUTF8(field.get_field_name()), field.get_float_value())
elif data_type == TS_DATATYPE_TEXT or data_type == TS_DATATYPE_STRING:
- _insert_data_into_ts_record_by_name_string(record, PyUnicode_AsUTF8(field.get_field_name()), PyUnicode_AsUTF8(field.get_string_value()))
- elif data_type == TS_DATATYPE_BLOB:
- if PyBytes_AsStringAndSize(field.get_string_value(), &blob_ptr, &blob_len) < 0:
+ str_ptr = PyUnicode_AsUTF8AndSize(field.get_string_value(), &str_len)
+ _insert_data_into_ts_record_by_name_string_with_len(record, PyUnicode_AsUTF8(field.get_field_name()), str_ptr, str_len)
+ elif data_type == TS_DATATYPE_BLOB or data_type == TS_DATATYPE_TEXT or data_type == TS_DATATYPE_STRING:
+ if PyBytes_AsStringAndSize(field.get_string_value(), &blob_ptr, &str_len) < 0:
raise ValueError("blob not legal")
_insert_data_into_ts_record_by_name_string_with_len(record, PyUnicode_AsUTF8(field.get_field_name()),
- <const char*> blob_ptr, <uint32_t>blob_len)
-
-
+ <const char*> blob_ptr, <uint32_t>str_len)
return record
# Free c structs' space