| 4756 | } |
| 4757 | |
| 4758 | void HandleClientSPut(const std::vector<std::string>& parts, |
| 4759 | ::fedb::client::TabletClient* client) { |
| 4760 | if (parts.size() < 5) { |
| 4761 | std::cout << "Bad put format, eg put tid pid time value" << std::endl; |
| 4762 | return; |
| 4763 | } |
| 4764 | try { |
| 4765 | uint32_t tid = boost::lexical_cast<uint32_t>(parts[1]); |
| 4766 | uint32_t pid = boost::lexical_cast<uint32_t>(parts[2]); |
| 4767 | ::fedb::api::TableMeta table_meta; |
| 4768 | bool ok = client->GetTableSchema(tid, pid, table_meta); |
| 4769 | if (!ok) { |
| 4770 | std::cout << "Fail to get table schema" << std::endl; |
| 4771 | return; |
| 4772 | } |
| 4773 | ::fedb::codec::SDKCodec codec(table_meta); |
| 4774 | std::vector<std::string> input_value(parts.begin() + 4, parts.end()); |
| 4775 | std::map<uint32_t, ::fedb::codec::Dimension> dimensions; |
| 4776 | if (codec.EncodeDimension(input_value, 0, &dimensions) < 0) { |
| 4777 | std::cout << "Encode dimension error" << std::endl; |
| 4778 | return; |
| 4779 | } |
| 4780 | std::string value; |
| 4781 | if (codec.EncodeRow(input_value, &value) < 0) { |
| 4782 | std::cout << "Encode data error" << std::endl; |
| 4783 | return; |
| 4784 | } |
| 4785 | |
| 4786 | if (table_meta.compress_type() == ::fedb::type::CompressType::kSnappy) { |
| 4787 | std::string compressed; |
| 4788 | ::snappy::Compress(value.c_str(), value.length(), &compressed); |
| 4789 | value.swap(compressed); |
| 4790 | } |
| 4791 | ok = client->Put(boost::lexical_cast<uint32_t>(parts[1]), |
| 4792 | boost::lexical_cast<uint32_t>(parts[2]), |
| 4793 | boost::lexical_cast<uint64_t>(parts[3]), value, |
| 4794 | dimensions[0]); |
| 4795 | if (ok) { |
| 4796 | std::cout << "Put ok" << std::endl; |
| 4797 | } else { |
| 4798 | std::cout << "Put failed" << std::endl; |
| 4799 | } |
| 4800 | } catch (std::exception const& e) { |
| 4801 | std::cout << e.what() << std::endl; |
| 4802 | } |
| 4803 | } |
| 4804 | |
| 4805 | void HandleClientDelete(const std::vector<std::string>& parts, |
| 4806 | ::fedb::client::TabletClient* client) { |
no test coverage detected