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
27 changes: 27 additions & 0 deletions cpp/test/tools/command_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,33 @@ TEST(CliE2E, TreeCountAndStatsUseDeviceTimestampUnion) {
<< stats_out.str();
}

TEST(CliE2E, TreeHeadWithoutDeviceUsesBareMeasurementNames) {
// A single-device tree file queried without -d resolves the only device
// implicitly. Result columns must still be bare measurement names (FIELD),
// not "device.measurement" (TsFile-143 / requirement 3.1.4.2 examples).
SparseTreeFixture f;

std::ostringstream ndjson_out;
std::ostringstream ndjson_err;
EXPECT_EQ(tsfile_cli::run_cli(
{"head", "-m", "left", "-n", "1", "-f", "ndjson", f.path},
ndjson_out, ndjson_err),
0)
<< ndjson_err.str();
EXPECT_EQ(ndjson_out.str(), "{\"time\":\"0\",\"left\":10}\n");

std::ostringstream csv_out;
std::ostringstream csv_err;
EXPECT_EQ(
tsfile_cli::run_cli({"head", "-f", "csv", f.path}, csv_out, csv_err), 0)
<< csv_err.str();
EXPECT_EQ(csv_out.str(),
"time,left,right\n"
"0,10,\\N\n"
"1,\\N,true\n"
"2,20,false\n");
}

TEST(CliE2E, MetadataTableFilterIsCaseInsensitive) {
Fixture f;

Expand Down
2 changes: 1 addition & 1 deletion cpp/test/tools/golden/tree_cat_csv.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time,root.test.d1.m1,root.test.d1.m2,root.test.d1.m3,root.test.d1.m4,root.test.d1.m5
time,m1,m2,m3,m4,m5
0,0,0.5,value_0,0,100.5
1,1,1.5,value_1,2,101.5
4 changes: 2 additions & 2 deletions cpp/test/tools/golden/tree_cat_ndjson.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"time":"0","root.test.d1.m1":0,"root.test.d1.m2":0.5,"root.test.d1.m3":"value_0","root.test.d1.m4":0,"root.test.d1.m5":100.5}
{"time":"1","root.test.d1.m1":1,"root.test.d1.m2":1.5,"root.test.d1.m3":"value_1","root.test.d1.m4":2,"root.test.d1.m5":101.5}
{"time":"0","m1":0,"m2":0.5,"m3":"value_0","m4":0,"m5":100.5}
{"time":"1","m1":1,"m2":1.5,"m3":"value_1","m4":2,"m5":101.5}
6 changes: 3 additions & 3 deletions cpp/test/tools/golden/tree_cat_table.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time root.test.d1.m1 root.test.d1.m2 root.test.d1.m3 root.test.d1.m4 root.test.d1.m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
time m1 m2 m3 m4 m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
2 changes: 1 addition & 1 deletion cpp/test/tools/golden/tree_export_csv.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
time,root.test.d1.m1,root.test.d1.m2,root.test.d1.m3,root.test.d1.m4,root.test.d1.m5
time,m1,m2,m3,m4,m5
0,0,0.5,value_0,0,100.5
1,1,1.5,value_1,2,101.5
2,2,2.5,value_2,4,102.5
Expand Down
40 changes: 20 additions & 20 deletions cpp/test/tools/golden/tree_export_ndjson.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{"time":"0","root.test.d1.m1":0,"root.test.d1.m2":0.5,"root.test.d1.m3":"value_0","root.test.d1.m4":0,"root.test.d1.m5":100.5}
{"time":"1","root.test.d1.m1":1,"root.test.d1.m2":1.5,"root.test.d1.m3":"value_1","root.test.d1.m4":2,"root.test.d1.m5":101.5}
{"time":"2","root.test.d1.m1":2,"root.test.d1.m2":2.5,"root.test.d1.m3":"value_2","root.test.d1.m4":4,"root.test.d1.m5":102.5}
{"time":"3","root.test.d1.m1":3,"root.test.d1.m2":3.5,"root.test.d1.m3":"value_3","root.test.d1.m4":6,"root.test.d1.m5":103.5}
{"time":"4","root.test.d1.m1":4,"root.test.d1.m2":4.5,"root.test.d1.m3":"value_4","root.test.d1.m4":8,"root.test.d1.m5":104.5}
{"time":"5","root.test.d1.m1":5,"root.test.d1.m2":5.5,"root.test.d1.m3":"value_5","root.test.d1.m4":10,"root.test.d1.m5":105.5}
{"time":"6","root.test.d1.m1":6,"root.test.d1.m2":6.5,"root.test.d1.m3":"value_6","root.test.d1.m4":12,"root.test.d1.m5":106.5}
{"time":"7","root.test.d1.m1":7,"root.test.d1.m2":7.5,"root.test.d1.m3":"value_7","root.test.d1.m4":14,"root.test.d1.m5":107.5}
{"time":"8","root.test.d1.m1":8,"root.test.d1.m2":8.5,"root.test.d1.m3":"value_8","root.test.d1.m4":16,"root.test.d1.m5":108.5}
{"time":"9","root.test.d1.m1":9,"root.test.d1.m2":9.5,"root.test.d1.m3":"value_9","root.test.d1.m4":18,"root.test.d1.m5":109.5}
{"time":"10","root.test.d1.m1":10,"root.test.d1.m2":10.5,"root.test.d1.m3":"value_10","root.test.d1.m4":20,"root.test.d1.m5":110.5}
{"time":"11","root.test.d1.m1":11,"root.test.d1.m2":11.5,"root.test.d1.m3":"value_11","root.test.d1.m4":22,"root.test.d1.m5":111.5}
{"time":"12","root.test.d1.m1":12,"root.test.d1.m2":12.5,"root.test.d1.m3":"value_12","root.test.d1.m4":24,"root.test.d1.m5":112.5}
{"time":"13","root.test.d1.m1":13,"root.test.d1.m2":13.5,"root.test.d1.m3":"value_13","root.test.d1.m4":26,"root.test.d1.m5":113.5}
{"time":"14","root.test.d1.m1":14,"root.test.d1.m2":14.5,"root.test.d1.m3":"value_14","root.test.d1.m4":28,"root.test.d1.m5":114.5}
{"time":"15","root.test.d1.m1":15,"root.test.d1.m2":15.5,"root.test.d1.m3":"value_15","root.test.d1.m4":30,"root.test.d1.m5":115.5}
{"time":"16","root.test.d1.m1":16,"root.test.d1.m2":16.5,"root.test.d1.m3":"value_16","root.test.d1.m4":32,"root.test.d1.m5":116.5}
{"time":"17","root.test.d1.m1":17,"root.test.d1.m2":17.5,"root.test.d1.m3":"value_17","root.test.d1.m4":34,"root.test.d1.m5":117.5}
{"time":"18","root.test.d1.m1":18,"root.test.d1.m2":18.5,"root.test.d1.m3":"value_18","root.test.d1.m4":36,"root.test.d1.m5":118.5}
{"time":"19","root.test.d1.m1":19,"root.test.d1.m2":19.5,"root.test.d1.m3":"value_19","root.test.d1.m4":38,"root.test.d1.m5":119.5}
{"time":"0","m1":0,"m2":0.5,"m3":"value_0","m4":0,"m5":100.5}
{"time":"1","m1":1,"m2":1.5,"m3":"value_1","m4":2,"m5":101.5}
{"time":"2","m1":2,"m2":2.5,"m3":"value_2","m4":4,"m5":102.5}
{"time":"3","m1":3,"m2":3.5,"m3":"value_3","m4":6,"m5":103.5}
{"time":"4","m1":4,"m2":4.5,"m3":"value_4","m4":8,"m5":104.5}
{"time":"5","m1":5,"m2":5.5,"m3":"value_5","m4":10,"m5":105.5}
{"time":"6","m1":6,"m2":6.5,"m3":"value_6","m4":12,"m5":106.5}
{"time":"7","m1":7,"m2":7.5,"m3":"value_7","m4":14,"m5":107.5}
{"time":"8","m1":8,"m2":8.5,"m3":"value_8","m4":16,"m5":108.5}
{"time":"9","m1":9,"m2":9.5,"m3":"value_9","m4":18,"m5":109.5}
{"time":"10","m1":10,"m2":10.5,"m3":"value_10","m4":20,"m5":110.5}
{"time":"11","m1":11,"m2":11.5,"m3":"value_11","m4":22,"m5":111.5}
{"time":"12","m1":12,"m2":12.5,"m3":"value_12","m4":24,"m5":112.5}
{"time":"13","m1":13,"m2":13.5,"m3":"value_13","m4":26,"m5":113.5}
{"time":"14","m1":14,"m2":14.5,"m3":"value_14","m4":28,"m5":114.5}
{"time":"15","m1":15,"m2":15.5,"m3":"value_15","m4":30,"m5":115.5}
{"time":"16","m1":16,"m2":16.5,"m3":"value_16","m4":32,"m5":116.5}
{"time":"17","m1":17,"m2":17.5,"m3":"value_17","m4":34,"m5":117.5}
{"time":"18","m1":18,"m2":18.5,"m3":"value_18","m4":36,"m5":118.5}
{"time":"19","m1":19,"m2":19.5,"m3":"value_19","m4":38,"m5":119.5}
42 changes: 21 additions & 21 deletions cpp/test/tools/golden/tree_export_table.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
time root.test.d1.m1 root.test.d1.m2 root.test.d1.m3 root.test.d1.m4 root.test.d1.m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
2 2 2.5 value_2 4 102.5
3 3 3.5 value_3 6 103.5
4 4 4.5 value_4 8 104.5
5 5 5.5 value_5 10 105.5
6 6 6.5 value_6 12 106.5
7 7 7.5 value_7 14 107.5
8 8 8.5 value_8 16 108.5
9 9 9.5 value_9 18 109.5
10 10 10.5 value_10 20 110.5
11 11 11.5 value_11 22 111.5
12 12 12.5 value_12 24 112.5
13 13 13.5 value_13 26 113.5
14 14 14.5 value_14 28 114.5
15 15 15.5 value_15 30 115.5
16 16 16.5 value_16 32 116.5
17 17 17.5 value_17 34 117.5
18 18 18.5 value_18 36 118.5
19 19 19.5 value_19 38 119.5
time m1 m2 m3 m4 m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
2 2 2.5 value_2 4 102.5
3 3 3.5 value_3 6 103.5
4 4 4.5 value_4 8 104.5
5 5 5.5 value_5 10 105.5
6 6 6.5 value_6 12 106.5
7 7 7.5 value_7 14 107.5
8 8 8.5 value_8 16 108.5
9 9 9.5 value_9 18 109.5
10 10 10.5 value_10 20 110.5
11 11 11.5 value_11 22 111.5
12 12 12.5 value_12 24 112.5
13 13 13.5 value_13 26 113.5
14 14 14.5 value_14 28 114.5
15 15 15.5 value_15 30 115.5
16 16 16.5 value_16 32 116.5
17 17 17.5 value_17 34 117.5
18 18 18.5 value_18 36 118.5
19 19 19.5 value_19 38 119.5
2 changes: 1 addition & 1 deletion cpp/test/tools/golden/tree_head_csv.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time,root.test.d1.m1,root.test.d1.m2,root.test.d1.m3,root.test.d1.m4,root.test.d1.m5
time,m1,m2,m3,m4,m5
0,0,0.5,value_0,0,100.5
1,1,1.5,value_1,2,101.5
4 changes: 2 additions & 2 deletions cpp/test/tools/golden/tree_head_ndjson.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"time":"0","root.test.d1.m1":0,"root.test.d1.m2":0.5,"root.test.d1.m3":"value_0","root.test.d1.m4":0,"root.test.d1.m5":100.5}
{"time":"1","root.test.d1.m1":1,"root.test.d1.m2":1.5,"root.test.d1.m3":"value_1","root.test.d1.m4":2,"root.test.d1.m5":101.5}
{"time":"0","m1":0,"m2":0.5,"m3":"value_0","m4":0,"m5":100.5}
{"time":"1","m1":1,"m2":1.5,"m3":"value_1","m4":2,"m5":101.5}
6 changes: 3 additions & 3 deletions cpp/test/tools/golden/tree_head_table.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
time root.test.d1.m1 root.test.d1.m2 root.test.d1.m3 root.test.d1.m4 root.test.d1.m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
time m1 m2 m3 m4 m5
0 0 0.5 value_0 0 100.5
1 1 1.5 value_1 2 101.5
3 changes: 1 addition & 2 deletions cpp/test/tools/model_format_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ TEST(ComplexTreeFixture, CsvAnswersMatchByteForByte) {
const std::string path = tsfile_cli_test::write_complex_tree_fixture();
expect_cli_exact(
{"head", "-d", "root.test.d1", "-n", "2", "-f", "csv", path}, 0,
"time,root.test.d1.m1,root.test.d1.m2,root.test.d1.m3,"
"root.test.d1.m4,root.test.d1.m5\n"
"time,m1,m2,m3,m4,m5\n"
"0,0,0.5,value_0,0,100.5\n"
"1,1,1.5,value_1,2,101.5\n",
"");
Expand Down
13 changes: 8 additions & 5 deletions cpp/tools/commands/row_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ int run_row_query(const ParsedArgs& args, storage::TsFileReader& reader,
int qret = 0;
const bool push_down = can_push_down_row_window(args, offset, limit);
std::unique_ptr<storage::Filter> tag_filter;
std::string tree_device_prefix;

if (is_table_model(args, reader)) {
std::string table_name = args.table;
Expand Down Expand Up @@ -333,6 +334,7 @@ int run_row_query(const ParsedArgs& args, storage::TsFileReader& reader,
}
effective_args.device = devices[0]->get_device_name();
}
tree_device_prefix = effective_args.device;
std::vector<std::string> paths;
int selection_ret =
resolve_tree_paths(effective_args, reader, paths, err);
Expand Down Expand Up @@ -362,11 +364,12 @@ int run_row_query(const ParsedArgs& args, storage::TsFileReader& reader,
// still checked separately so stdout errors remain runtime failures.
std::ostringstream staged;
std::string output_error;
int wret = push_down
? emit_result_set(rs, fmt, args.no_header, staged, 0, -1,
emitted_rows, &output_error)
: emit_result_set(rs, fmt, args.no_header, staged, offset,
limit, emitted_rows, &output_error);
int wret =
push_down
? emit_result_set(rs, fmt, args.no_header, staged, 0, -1,
emitted_rows, &output_error, tree_device_prefix)
: emit_result_set(rs, fmt, args.no_header, staged, offset, limit,
emitted_rows, &output_error, tree_device_prefix);
reader.destroy_query_data_set(rs);
if (!output_error.empty()) {
err << "Error: " << output_error << "\n";
Expand Down
12 changes: 10 additions & 2 deletions cpp/tools/format/result_set_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,26 @@ std::string cell_to_string(storage::ResultSet* rs, uint32_t i,

int emit_result_set(storage::ResultSet* rs, OutputFormat fmt, bool no_header,
std::ostream& out, long long offset, long long limit,
long long* emitted_rows, std::string* output_error) {
long long* emitted_rows, std::string* output_error,
const std::string& strip_device_prefix) {
if (output_error != nullptr) {
output_error->clear();
}
auto meta = rs->get_metadata();
const uint32_t ncol = meta->get_column_count();
const std::string device_prefix =
strip_device_prefix.empty() ? std::string() : strip_device_prefix + ".";
Comment on lines +84 to +85
std::vector<std::string> header;
std::vector<common::TSDataType> types;
header.reserve(ncol);
types.reserve(ncol);
for (uint32_t i = 1; i <= ncol; ++i) {
header.push_back(meta->get_column_name(i));
std::string name = meta->get_column_name(i);
if (!device_prefix.empty() && name.size() > device_prefix.size() &&
name.compare(0, device_prefix.size(), device_prefix) == 0) {
name = name.substr(device_prefix.size());
}
header.push_back(std::move(name));
Comment on lines +91 to +96
types.push_back(meta->get_column_type(i));
}

Expand Down
3 changes: 2 additions & 1 deletion cpp/tools/format/result_set_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ std::string cell_to_string(storage::ResultSet* rs, uint32_t col_index,
int emit_result_set(storage::ResultSet* rs, OutputFormat fmt, bool no_header,
std::ostream& out, long long offset = 0,
long long limit = -1, long long* emitted_rows = nullptr,
std::string* output_error = nullptr);
std::string* output_error = nullptr,
const std::string& strip_device_prefix = "");

int emit_result_set_sampled(storage::ResultSet* rs, OutputFormat fmt,
bool no_header, std::ostream& out, long long limit,
Expand Down
Loading