Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cpp/examples/c_examples/demo_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ERRNO read_tsfile() {
HANDLE_ERROR(code);

if (ret == NULL) {
HANDLE_ERROR(RET_INVALID_QUERY);
HANDLE_ERROR(RET_INVALID_ARG);
}

// Get query result metadata: column name and datatype
Expand Down
54 changes: 19 additions & 35 deletions cpp/src/cwrapper/errno_define_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

#ifndef CWRAPPER_ERRNO_DEFINRET_H
#define CWRAPPER_ERRNO_DEFINRET_H
#ifndef CWRAPPER_ERRNO_DEFINE_H
#define CWRAPPER_ERRNO_DEFINE_H

#define RET_OK 0
#define RET_OOM 1
Expand All @@ -28,49 +28,33 @@
#define RET_OUT_OF_RANGE 5
#define RET_PARTIAL_READ 6
#define RET_INVALID_SCHEMA 8
#define RET_NET_EPOLL_ERR 9
#define RET_NET_EPOLL_WAIT_ERR 10
#define RET_NET_RECV_ERR 11
#define RET_NET_ACCEPT_ERR 12
#define RET_NET_FCNTL_ERR 13
#define RET_NET_LISTEN_ERR 14
#define RET_NET_SEND_ERR 15
#define RET_PIPRET_ERR 16
#define RET_THREAD_CREATRET_ERR 17
#define RET_MUTEX_ERR 18
#define RET_COND_ERR 19
#define RET_OVERFLOW 20
#define RET_NO_MORRET_DATA 21
#define RET_NO_MORE_DATA 21
#define RET_OUT_OF_ORDER 22
#define RET_TSBLOCK_TYPRET_NOT_SUPPORTED 23
#define RET_TSBLOCK_DATA_INCONSISTENCY 24
#define RET_DDL_UNKNOWN_TYPE 25
#define RET_TYPRET_NOT_SUPPORTED 26
#define RET_TYPRET_NOT_MATCH 27
#define RET_FILRET_OPEN_ERR 28
#define RET_FILRET_CLOSRET_ERR 29
#define RET_FILRET_WRITRET_ERR 30
#define RET_FILRET_READ_ERR 31
#define RET_FILRET_SYNC_ERR 32
#define RET_TSFILRET_WRITER_META_ERR 33
#define RET_FILRET_STAT_ERR 34
#define RET_TSFILRET_CORRUPTED 35
#define RET_TYPE_NOT_SUPPORTED 26
#define RET_TYPE_NOT_MATCH 27
#define RET_FILE_OPEN_ERR 28
#define RET_FILE_CLOSE_ERR 29
#define RET_FILE_WRITE_ERR 30
#define RET_FILE_READ_ERR 31
#define RET_FILE_SYNC_ERR 32
#define RET_TSFILE_WRITER_META_ERR 33
#define RET_FILE_STAT_ERR 34
#define RET_TSFILE_CORRUPTED 35
#define RET_BUF_NOT_ENOUGH 36
#define RET_INVALID_PATH 37
#define RET_NOT_MATCH 38
#define RET_JSON_INVALID 39
#define RET_NOT_SUPPORT 40
#define RET_PARSER_ERR 41
#define RET_ANALYZRET_ERR 42
#define RET_INVALID_DATA_POINT 43
#define RET_DEVICRET_NOT_EXIST 44
#define RET_DEVICE_NOT_EXIST 44
#define RET_MEASUREMENT_NOT_EXIST 45
#define RET_INVALID_QUERY 46
#define RET_SDK_QUERY_OPTIMIZRET_ERR 47
#define RET_COMPRESS_ERR 48
#define RET_TABLRET_NOT_EXIST 49
#define RET_TABLE_NOT_EXIST 49
#define RET_COLUMN_NOT_EXIST 50
#define RET_UNSUPPORTED_ORDER 51
#define RET_INVALID_NODRET_TYPE 52
#define RET_INVALID_NODE_TYPE 52
#define RET_ENCODE_ERR 53
#define RET_DECODE_ERR 54

#endif /* CWRAPPER_ERRNO_DEFINRET_H */
#endif /* CWRAPPER_ERRNO_DEFINE_H */
4 changes: 2 additions & 2 deletions cpp/src/file/read_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ using namespace common;
namespace storage {

void ReadFile::close() {
if (fd_ > 0) {
if (fd_ >= 0) {
::close(fd_);
fd_ = -1;
}
Expand All @@ -65,7 +65,7 @@ int ReadFile::open(const std::string& file_path) {
} else if (RET_FAIL(check_file_magic())) {
}
if (IS_FAIL(ret)) {
::close(fd_);
close();
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/reader/tsfile_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int TsFileExecutor::execute(QueryExpression* query_expr, ResultSet*& ret_qds) {
if (query_exprs_->has_filter_) {
regular_expr = query_exprs_->optimize(origin_expr, paths);
if (regular_expr == nullptr) {
return E_SDK_QUERY_OPTIMIZE_ERR;
return E_INVALID_ARG;
}
query_exprs_->set_expression(regular_expr);
}
Expand Down
32 changes: 24 additions & 8 deletions cpp/src/reader/tsfile_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
#include "tsfile_reader.h"

#include <stdexcept>

#include "common/schema.h"
#include "filter/time_operator.h"
#include "tsfile_executor.h"
Expand All @@ -33,6 +35,19 @@ struct DeviceMetaEntry {
int64_t end_offset;
};

int parse_paths(const std::vector<std::string>& path_list,
std::vector<Path>& parsed_paths) {
try {
parsed_paths.reserve(path_list.size());
for (const auto& path : path_list) {
parsed_paths.emplace_back(path, true);
}
} catch (const std::runtime_error&) {
return E_INVALID_PATH;
}
return E_OK;
}

int get_all_device_entries(std::vector<DeviceMetaEntry>& entries,
std::shared_ptr<MetaIndexNode> index_node,
ReadFile* read_file, PageArena& pa) {
Expand Down Expand Up @@ -152,14 +167,15 @@ int TsFileReader::query(QueryExpression* qe, ResultSet*& ret_qds) {

int TsFileReader::query(std::vector<std::string>& path_list, int64_t start_time,
int64_t end_time, ResultSet*& result_set) {
int ret = E_OK;
std::vector<Path> path_list_vec;
int ret = parse_paths(path_list, path_list_vec);
if (ret != E_OK) {
return ret;
}

Filter* time_filter = new TimeBetween(start_time, end_time, false);
Expression* exp =
new storage::Expression(storage::GLOBALTIME_EXPR, time_filter);
std::vector<Path> path_list_vec;
for (const auto& path : path_list) {
path_list_vec.emplace_back(Path(path, true));
}
QueryExpression* query_expression =
QueryExpression::create(path_list_vec, exp);
ret = tsfile_executor_->execute(query_expression, result_set);
Expand Down Expand Up @@ -200,10 +216,10 @@ int TsFileReader::query(const std::string& table_name,

int TsFileReader::queryByRow(std::vector<std::string>& path_list, int offset,
int limit, ResultSet*& result_set) {
int ret = E_OK;
std::vector<Path> path_list_vec;
for (const auto& path : path_list) {
path_list_vec.emplace_back(Path(path, true));
int ret = parse_paths(path_list, path_list_vec);
if (ret != E_OK) {
return ret;
}
QueryExpression* query_expression =
QueryExpression::create(path_list_vec, nullptr);
Expand Down
16 changes: 0 additions & 16 deletions cpp/src/utils/errno_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ const int E_INVALID_ARG = 4;
const int E_OUT_OF_RANGE = 5;
const int E_PARTIAL_READ = 6;
const int E_INVALID_SCHEMA = 8;
const int E_NET_EPOLL_ERR = 9;
const int E_NET_EPOLL_WAIT_ERR = 10;
const int E_NET_RECV_ERR = 11;
const int E_NET_ACCEPT_ERR = 12;
const int E_NET_FCNTL_ERR = 13;
const int E_NET_LISTEN_ERR = 14;
const int E_NET_SEND_ERR = 15;
const int E_PIPE_ERR = 16;
const int E_THREAD_CREATE_ERR = 17;
const int E_MUTEX_ERR = 18;
const int E_COND_ERR = 19;
const int E_OVERFLOW = 20;
const int E_NO_MORE_DATA = 21;
const int E_OUT_OF_ORDER = 22;
Expand All @@ -57,15 +46,10 @@ const int E_TSFILE_CORRUPTED = 35;
const int E_BUF_NOT_ENOUGH = 36;
const int E_INVALID_PATH = 37;
const int E_NOT_MATCH = 38;
const int E_JSON_INVALID = 39;
const int E_NOT_SUPPORT = 40;
const int E_PARSER_ERR = 41;
const int E_ANALYZE_ERR = 42;
const int E_INVALID_DATA_POINT = 43;
const int E_DEVICE_NOT_EXIST = 44;
const int E_MEASUREMENT_NOT_EXIST = 45;
const int E_INVALID_QUERY = 46;
const int E_SDK_QUERY_OPTIMIZE_ERR = 47;
const int E_COMPRESS_ERR = 48;
const int E_TABLE_NOT_EXIST = 49;
const int E_COLUMN_NOT_EXIST = 50;
Expand Down
19 changes: 17 additions & 2 deletions cpp/test/cwrapper/c_release_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#endif
#include <utils/db_utils.h>

#include <cstdio>
#include <cstring>
#include <string>

Expand Down Expand Up @@ -54,13 +55,27 @@ TEST_F(CReleaseTest, TestCreateFile) {
// Folder: rejected either as an open error (POSIX) or as already-existing
// (Windows / filesystems where the directory already exists).
file = write_file_new("test/", &error_no);
ASSERT_TRUE(error_no == RET_FILRET_OPEN_ERR ||
error_no == RET_ALREADY_EXIST);
ASSERT_TRUE(error_no == RET_FILE_OPEN_ERR || error_no == RET_ALREADY_EXIST);

remove("create_file1.tsfile");
free_write_file(&file);
}

TEST_F(CReleaseTest, RejectCorruptedFileWithoutDoubleClosingDescriptor) {
const char* file_name = "corrupted_empty_file.tsfile";
remove(file_name);
FILE* empty_file = fopen(file_name, "wb");
ASSERT_NE(nullptr, empty_file);
ASSERT_EQ(0, fclose(empty_file));

ERRNO error_no = RET_OK;
TsFileReader reader = tsfile_reader_new(file_name, &error_no);
EXPECT_EQ(nullptr, reader);
EXPECT_EQ(RET_TSFILE_CORRUPTED, error_no);

remove(file_name);
}

TEST_F(CReleaseTest, TsFileWriterNew) {
ERRNO error_code = RET_OK;

Expand Down
27 changes: 27 additions & 0 deletions cpp/test/cwrapper/query_by_row_cwrapper_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,33 @@ TEST_F(CWrapperQueryByRowTest, TreeByRowOffsetLimit) {
storage::libtsfile_destroy();
}

TEST_F(CWrapperQueryByRowTest, InvalidTreePathReturnsErrorCode) {
storage::libtsfile_init();

const char* file_name = "cwrapper_invalid_tree_path_test.tsfile";
remove(file_name);
write_tree_tsfile(file_name, {"root.d1"}, {"s1"}, 1);

ERRNO code = RET_OK;
TsFileReader reader = tsfile_reader_new(file_name, &code);
ASSERT_EQ(code, RET_OK);
ASSERT_NE(reader, nullptr);

char device_id[] = "root.d1";
char invalid_measurement[] = "a*%";
char* device_ids[] = {device_id};
char* measurement_ids[] = {invalid_measurement};
ResultSet result = tsfile_reader_query_tree_by_row(
reader, device_ids, 1, measurement_ids, 1, 0, -1, &code);

EXPECT_EQ(code, RET_INVALID_PATH);
EXPECT_EQ(result, nullptr);
EXPECT_EQ(tsfile_reader_close(reader), RET_OK);
remove(file_name);

storage::libtsfile_destroy();
}

TEST_F(CWrapperQueryByRowTest, TableByRowOffsetLimit) {
storage::libtsfile_init();

Expand Down
2 changes: 0 additions & 2 deletions cpp/tools/format/output_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ const char* error_code_message(int code) {
return "table does not exist";
case common::E_COLUMN_NOT_EXIST:
return "column does not exist";
case common::E_INVALID_QUERY:
return "invalid query";
case common::E_TYPE_NOT_SUPPORTED:
return "data type not supported";
case common::E_TYPE_NOT_MATCH:
Expand Down
Loading
Loading