Skip to content
Merged
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
105 changes: 2 additions & 103 deletions src/cmd/openmldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3355,109 +3355,8 @@ void HandleClientChangeRole(const std::vector<std::string> parts, ::openmldb::cl
}

void HandleClientPreview(const std::vector<std::string>& parts, ::openmldb::client::TabletClient* client) {
if (parts.size() < 3) {
std::cout << "preview format error. eg: preview tid pid [limit]" << std::endl;
return;
}
uint32_t limit = FLAGS_preview_default_limit;
uint32_t tid = 0;
if (auto ret = std::from_chars(parts[1].data(), parts[1].data() + parts[1].size(), tid); ret.ec != std::errc()) {
std::cout << "Invalid args, tid should be uint32_t" << std::endl;
return;
}
uint32_t pid = 0;
if (auto ret = std::from_chars(parts[2].data(), parts[2].data() + parts[2].size(), pid); ret.ec != std::errc()) {
std::cout << "Invalid args, pid should be uint32_t" << std::endl;
return;
}
if (parts.size() > 3) {
if (auto ret = std::from_chars(parts[3].data(), parts[3].data() + parts[3].size(), limit);
ret.ec != std::errc()) {
std::cout << "Invalid args, limit should be uint32_t" << std::endl;
return;
}
if (limit > FLAGS_preview_limit_max_num) {
printf("preview error. limit is greater than the max num %u\n", FLAGS_preview_limit_max_num);
return;
} else if (limit == 0) {
printf("preview error. limit must be greater than zero\n");
return;
}
}
::openmldb::api::TableStatus table_status;
if (auto st = client->GetTableStatus(tid, pid, true, table_status); !st.OK()) {
std::cout << "Fail to get table status, error msg: " << st.GetMsg() << std::endl;
return;
}
/*std::string schema = table_status.schema();
std::vector<::openmldb::codec::ColumnDesc> columns;
if (!schema.empty()) {
::openmldb::codec::SchemaCodec codec;
codec.Decode(schema, columns);
}
uint32_t column_num = columns.empty() ? 4 : columns.size() + 2;
::baidu::common::TPrinter tp(column_num, FLAGS_max_col_display_length);
std::vector<std::string> row;
if (schema.empty()) {
row.push_back("#");
row.push_back("key");
row.push_back("ts");
row.push_back("data");
} else {
row.push_back("#");
row.push_back("ts");
for (uint32_t i = 0; i < columns.size(); i++) {
row.push_back(columns[i].name);
}
}
tp.AddRow(row);
uint32_t index = 1;
uint32_t count = 0;
::openmldb::base::KvIterator* it =
client->Traverse(tid, pid, "", "", 0, limit, count);
if (it == NULL) {
std::cout << "Fail to preview table" << std::endl;
return;
}
while (it->Valid()) {
row.clear();
row.push_back(std::to_string(index));
if (schema.empty()) {
std::string value = it->GetValue().ToString();
if (table_status.compress_type() ==
::openmldb::type::CompressType::kSnappy) {
std::string uncompressed;
::snappy::Uncompress(value.c_str(), value.length(),
&uncompressed);
value = uncompressed;
}
row.push_back(it->GetPK());
row.push_back(std::to_string(it->GetKey()));
row.push_back(value);
} else {
row.push_back(std::to_string(it->GetKey()));
::openmldb::api::TableMeta table_meta;
bool ok = client->GetTableSchema(tid, pid, table_meta);
if (!ok) {
std::cout << "No schema for table, please use command scan"
<< std::endl;
delete it;
return;
}
std::string value;
if (table_meta.compress_type() == ::openmldb::type::CompressType::kSnappy) {
::snappy::Uncompress(it->GetValue().data(),
it->GetValue().size(), &value);
} else {
value.assign(it->GetValue().data(), it->GetValue().size());
}
}
tp.AddRow(row);
index++;
it->Next();
}
delete it;
tp.Print(true);*/
std::cout << "unsupport preview" << std::endl;
return;
}

void HandleClientGetFollower(const std::vector<std::string>& parts, ::openmldb::client::TabletClient* client) {
Expand Down
Loading