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
35 changes: 35 additions & 0 deletions cpp/test/tools/command_e2e_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,41 @@ TEST(CliE2E, MetaReportsFileSummary) {
EXPECT_NE(out.str().find("\ttable\t"), std::string::npos);
}

TEST(CliE2E, SketchPrintsHumanReadableLayout) {
Fixture f;
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"sketch", f.path}, out, err);
EXPECT_EQ(code, 0) << err.str();
EXPECT_TRUE(err.str().empty());
EXPECT_NE(out.str().find("TsFile Sketch"), std::string::npos);
EXPECT_NE(out.str().find("POSITION|\tCONTENT"), std::string::npos);
EXPECT_NE(out.str().find("[magic head] TsFile"), std::string::npos);
EXPECT_NE(out.str().find("[ChunkGroup]"), std::string::npos);
EXPECT_NE(out.str().find("[Chunk Header]"), std::string::npos);
EXPECT_NE(out.str().find("[Page Header]"), std::string::npos);
EXPECT_NE(out.str().find("[TimeseriesMetadata]"), std::string::npos);
EXPECT_NE(out.str().find("[ChunkMetadata]"), std::string::npos);
EXPECT_NE(out.str().find("[TsFileMetadata]"), std::string::npos);
EXPECT_NE(out.str().find("[Bloom Filter Size]"), std::string::npos);
EXPECT_NE(out.str().find("[Bloom Filter]"), std::string::npos);
EXPECT_NE(out.str().find("END of TsFile"), std::string::npos);
EXPECT_EQ(out.str().find("[TsFileProperties]"), std::string::npos);
EXPECT_NE(out.str().find("IndexOfTimerseriesIndex Tree"),
std::string::npos);
}

TEST(CliE2E, SketchRejectsFormatFlag) {
Fixture f;
std::ostringstream out;
std::ostringstream err;
int code = tsfile_cli::run_cli({"sketch", "-f", "json", f.path}, out, err);
EXPECT_EQ(code, 1);
EXPECT_NE(err.str().find("-f/--format is not valid for sketch"),
std::string::npos)
<< err.str();
}

TEST(CliE2E, CountReportsSeriesCountsAndTotal) {
Fixture f;
std::ostringstream out;
Expand Down
41 changes: 36 additions & 5 deletions cpp/tools/cli/run_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void print_usage(std::ostream& os) {
" cat all rows of a device/table\n"
" count number of rows (per series, plus a total)\n"
" sample deterministic sample rows (use -n and --seed)\n"
" sketch human-readable file layout/self-check view\n"
" write import CSV/TSV rows into a new table tsfile "
"(--table, --columns, -o)\n"
"Options:\n"
Expand Down Expand Up @@ -89,9 +90,9 @@ void print_usage(std::ostream& os) {
}

bool is_known_command(const std::string& c) {
static const std::set<std::string> kCmds = {"ls", "schema", "meta",
"stats", "head", "cat",
"count", "sample", "write"};
static const std::set<std::string> kCmds = {
"ls", "schema", "meta", "stats", "head",
"cat", "count", "sample", "write", "sketch"};
return kCmds.find(c) != kCmds.end();
}

Expand Down Expand Up @@ -188,8 +189,34 @@ bool validate_write_flags(const ParsedArgs& p, std::ostream& err) {
bool validate_read_flag_applicability(const ParsedArgs& p, std::ostream& err) {
const std::string& c = p.command;
const bool is_row = (c == "head" || c == "cat" || c == "sample");
const bool scoped =
is_row || c == "schema" || c == "stats" || c == "count";
const bool scoped = is_row || c == "schema" || c == "stats" || c == "count";

if (c == "sketch") {
if (p.format != ParsedArgs::Format::kAuto) {
err << "Error: -f/--format is not valid for sketch\n";
return false;
}
if (!p.device.empty()) {
err << "Error: -d/--device is not valid for sketch\n";
return false;
}
if (!p.table.empty()) {
err << "Error: -t/--table is not valid for sketch\n";
return false;
}
if (!p.measurements.empty()) {
err << "Error: -m/--measurements is not valid for sketch\n";
return false;
}
if (p.no_header) {
err << "Error: --no-header is not valid for sketch\n";
return false;
}
if (!p.model.empty()) {
err << "Error: --model is not valid for sketch\n";
return false;
}
}

if (!p.output.empty()) {
err << "Error: -o/--output is only valid for write\n";
Expand Down Expand Up @@ -299,6 +326,10 @@ int run_cli(const std::vector<std::string>& args, std::ostream& out,
}

storage::libtsfile_init();
if (p.command == "sketch") {
return cmd_sketch(p, out, err);
}

storage::TsFileReader reader;
int open_ret = reader.open(p.file);
if (open_ret != 0) {
Expand Down
Loading
Loading