Skip to content

Commit

Permalink
Remove sscan and sget command in tablet client
Browse files Browse the repository at this point in the history
  • Loading branch information
frazie committed May 25, 2022
1 parent 50d0699 commit cb2e890
Showing 1 changed file with 0 additions and 252 deletions.
252 changes: 0 additions & 252 deletions src/cmd/openmldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3053,10 +3053,6 @@ void HandleClientHelp(const std::vector<std::string> parts, ::openmldb::client::
printf("quit - exit client\n");
printf("recoversnapshot - recover snapshot\n");
printf("screate - create multi dimension table\n");
printf(
"sscan - get records for a period of time from multi dimension "
"table\n");
printf("sget - get only one record from multi dimension table\n");
printf("sendsnapshot - send snapshot to another endpoint\n");
printf("setexpire - enable or disable ttl\n");
printf("showschema - show schema\n");
Expand All @@ -3074,21 +3070,6 @@ void HandleClientHelp(const std::vector<std::string> parts, ::openmldb::client::
printf("desc: drop table\n");
printf("usage: drop tid pid\n");
printf("ex: drop 1 0\n");
} else if (parts[1] == "sscan") {
printf(
"desc: get records for a period of time from multi dimension "
"table\n");
printf(
"usage: sscan tid pid key key_name starttime endtime "
"[limit]\n");
printf("ex: sscan 1 0 card0 card 1528858466000 1528858300000\n");
printf("ex: sscan 1 0 card0 card 1528858466000 1528858300000 10\n");
printf("ex: sscan 1 0 card0 card 0 0 10\n");
} else if (parts[1] == "sget") {
printf("desc: get only one record from multi dimension table\n");
printf("usage: sget tid pid key key_name ts\n");
printf("ex: sget 1 0 card0 card 1528858466000\n");
printf("ex: sget 1 0 card0 card 0\n");
} else if (parts[1] == "delete") {
printf("desc: delete pk\n");
printf("usage: delete tid pid key [key_name]\n");
Expand Down Expand Up @@ -3644,235 +3625,6 @@ void HandleClientShowSchema(const std::vector<std::string>& parts, ::openmldb::c
}
}

void HandleClientSGet(const std::vector<std::string>& parts, ::openmldb::client::TabletClient* client) {
if (parts.size() < 5) {
std::cout << "Bad sget format, eg. sget tid pid key index_name ts | sget "
"table_name=xxx key=xxx index_name=xxx ts=xxx ts_name=xxx"
<< std::endl;
return;
}
std::map<std::string, std::string> parameter_map;
if (!GetParameterMap("tid", parts, "=", parameter_map)) {
std::cout << "sget format erro! eg. sget table_name=xxx key=xxx "
"index_name=xxx ts=xxx ts_name=xxx"
<< std::endl;
return;
}
bool is_pair_format = parameter_map.empty() ? false : true;
uint32_t tid = 0;
uint32_t pid = 0;
std::string key;
std::string index_name;
uint64_t timestamp = 0;
std::string ts_name;
auto iter = parameter_map.begin();
try {
if (is_pair_format) {
iter = parameter_map.find("tid");
if (iter != parameter_map.end()) {
tid = boost::lexical_cast<uint32_t>(iter->second);
} else {
std::cout << "sget format error: tid does not exist!" << std::endl;
return;
}
iter = parameter_map.find("pid");
if (iter != parameter_map.end()) {
pid = boost::lexical_cast<uint32_t>(iter->second);
} else {
std::cout << "sget format error: pid does not exist!" << std::endl;
return;
}
iter = parameter_map.find("key");
if (iter != parameter_map.end()) {
key = iter->second;
} else {
std::cout << "sget format error: key does not exist!" << std::endl;
return;
}
iter = parameter_map.find("index_name");
if (iter != parameter_map.end()) {
index_name = iter->second;
}
iter = parameter_map.find("ts");
if (iter != parameter_map.end()) {
timestamp = boost::lexical_cast<uint64_t>(iter->second);
}
iter = parameter_map.find("ts_name");
if (iter != parameter_map.end()) {
ts_name = iter->second;
}
} else {
tid = boost::lexical_cast<uint32_t>(parts[1]);
pid = boost::lexical_cast<uint32_t>(parts[2]);
key = parts[3];
index_name = parts[4];
if (parts.size() > 5) {
timestamp = boost::lexical_cast<uint64_t>(parts[5]);
}
}
} catch (std::exception const& e) {
std::cout << "Invalid args. tid pid should be uint32_t, ts should be "
"uint64_t, "
<< std::endl;
return;
}
::openmldb::api::TableMeta table_meta;
bool ok = client->GetTableSchema(tid, pid, table_meta);
if (!ok) {
std::cout << "No schema for table ,please use command get" << std::endl;
return;
}
std::string value;
uint64_t ts = 0;
std::string msg;
ok = client->Get(tid, pid, key, timestamp, index_name, ts_name, value, ts, msg);
if (!ok) {
std::cout << "Fail to sget value! error msg: " << msg << std::endl;
return;
}
::openmldb::api::TableStatus table_status;
if (!client->GetTableStatus(tid, pid, table_status)) {
std::cout << "Fail to get table status" << std::endl;
return;
}
::openmldb::type::CompressType compress_type = ::openmldb::type::CompressType::kNoCompress;
if (table_status.compress_type() == ::openmldb::type::CompressType::kSnappy) {
compress_type = ::openmldb::type::CompressType::kSnappy;
}
if (compress_type == ::openmldb::type::CompressType::kSnappy) {
std::string uncompressed;
::snappy::Uncompress(value.c_str(), value.length(), &uncompressed);
value = uncompressed;
}
// TODO(denglong): display schema
/*std::string schema = table_meta.schema();
std::vector<::openmldb::codec::ColumnDesc> raw;
::openmldb::codec::SchemaCodec codec;
codec.Decode(schema, raw);
::baidu::common::TPrinter tp(raw.size() + 2, FLAGS_max_col_display_length);
std::vector<std::string> row;
row.push_back("#");
row.push_back("ts");
for (uint32_t i = 0; i < raw.size(); i++) {
row.push_back(raw[i].name);
}
tp.AddRow(row);
row.clear();
row.push_back("1");
row.push_back(std::to_string(ts));
tp.AddRow(row);
tp.Print(true);*/
}

void HandleClientSScan(const std::vector<std::string>& parts, ::openmldb::client::TabletClient* client) {
if (parts.size() < 7) {
std::cout << "Bad scan format! eg.sscan tid pid key col_name start_time "
"end_time [limit] | sscan table_name=xxx key=xxx index_name=xxx "
"st=xxx et=xxx ts_name=xxx [limit=xxx]"
<< std::endl;
return;
}
std::map<std::string, std::string> parameter_map;
if (!GetParameterMap("tid", parts, "=", parameter_map)) {
std::cout << "scan format erro! eg. sscan table_name=xxx key=xxx "
"index_name=xxx st=xxx et=xxx ts_name=xxx [limit=xxx]"
<< std::endl;
return;
}
bool is_pair_format = parameter_map.empty() ? false : true;
uint32_t tid = 0;
uint32_t pid = 0;
std::string key;
std::string index_name;
uint64_t st = 0;
uint64_t et = 0;
std::string ts_name;
uint32_t limit = 0;
auto iter = parameter_map.begin();
try {
if (is_pair_format) {
iter = parameter_map.find("tid");
if (iter != parameter_map.end()) {
tid = boost::lexical_cast<uint32_t>(iter->second);
} else {
std::cout << "sscan format error: tid does not exist!" << std::endl;
return;
}
iter = parameter_map.find("pid");
if (iter != parameter_map.end()) {
pid = boost::lexical_cast<uint32_t>(iter->second);
} else {
std::cout << "sscan format error: pid does not exist!" << std::endl;
return;
}
iter = parameter_map.find("key");
if (iter != parameter_map.end()) {
key = iter->second;
} else {
std::cout << "sscan format error: key does not exist!" << std::endl;
return;
}
iter = parameter_map.find("index_name");
if (iter != parameter_map.end()) {
index_name = iter->second;
}
iter = parameter_map.find("st");
if (iter != parameter_map.end()) {
st = boost::lexical_cast<uint64_t>(iter->second);
} else {
std::cout << "sscan format error: st does not exist!" << std::endl;
return;
}
iter = parameter_map.find("et");
if (iter != parameter_map.end()) {
et = boost::lexical_cast<uint64_t>(iter->second);
} else {
std::cout << "sscan format error: et does not exist!" << std::endl;
return;
}
iter = parameter_map.find("ts_name");
if (iter != parameter_map.end()) {
ts_name = iter->second;
}
iter = parameter_map.find("limit");
if (iter != parameter_map.end()) {
limit = boost::lexical_cast<uint32_t>(iter->second);
}
} else {
if (parts.size() > 7) {
limit = boost::lexical_cast<uint32_t>(parts[7]);
}
tid = boost::lexical_cast<uint32_t>(parts[1]);
pid = boost::lexical_cast<uint32_t>(parts[2]);
key = parts[3];
index_name = parts[4];
st = boost::lexical_cast<uint64_t>(parts[5]);
et = boost::lexical_cast<uint64_t>(parts[6]);
}
} catch (std::exception const& e) {
std::cout << "Invalid args. tid pid should be uint32_t, st and et "
"should be uint64_t, limit should be uint32"
<< std::endl;
return;
}
std::string msg;
std::shared_ptr<::openmldb::base::KvIterator> it(client->Scan(tid, pid, key, index_name, st, et, limit, msg));
if (!it) {
std::cout << "Fail to scan table. error msg: " << msg << std::endl;
return;
}
::openmldb::api::TableMeta table_meta;
bool ok = client->GetTableSchema(tid, pid, table_meta);
if (!ok) {
std::cout << "table is not exist" << std::endl;
return;
}
std::vector<std::shared_ptr<::openmldb::base::KvIterator>> iter_vec;
iter_vec.push_back(std::move(it));
::openmldb::cmd::SDKIterator sdk_it(iter_vec, limit);
::openmldb::cmd::ShowTableRows(table_meta, &sdk_it);
}

void HandleClientDelete(const std::vector<std::string>& parts, ::openmldb::client::TabletClient* client) {
if (parts.size() < 4) {
std::cout << "Bad delete format" << std::endl;
Expand Down Expand Up @@ -3932,10 +3684,6 @@ void StartClient() {
::openmldb::base::SplitString(buffer, " ", parts);
if (parts.empty()) {
continue;
} else if (parts[0] == "sget") {
HandleClientSGet(parts, &client);
} else if (parts[0] == "sscan") {
HandleClientSScan(parts, &client);
} else if (parts[0] == "delete") {
HandleClientDelete(parts, &client);
} else if (parts[0] == "count") {
Expand Down

0 comments on commit cb2e890

Please sign in to comment.