diff --git a/example/mpc_cmp_task_conf.json b/example/mpc_cmp_task_conf.json new file mode 100644 index 00000000..36400a1b --- /dev/null +++ b/example/mpc_cmp_task_conf.json @@ -0,0 +1,47 @@ +{ + "task_type": "ACTOR_TASK", + "task_name": "mpc_cmp", + "task_lang": "proto", + "task_code": { + "code_file_path": "", + "code": "arithmetic" + }, + "params": { + "ResFileName": { + "type": "STRING", + "value": "data/result/mpc_cmp_result.csv" + }, + "Expr": { + "type": "STRING", + "value": "CMP(A, B)" + }, + "RevealToParties": { + "type": "STRING", + "value": "PARTY2" + }, + "Col_And_Owner": { + "type": "STRING", + "value": "A-PARTY0;B-PARTY1" + }, + "Col_And_Dtype": { + "descrtion": "0: int64_t, 1: double", + "type": "STRING", + "value": "A-0;B-0" + }, + "Accuracy": { + "type": "STRING", + "value": "D16" + } + }, + "party_datasets": { + "PARTY0": { + "Data_File": "mpc_arithmetic_0" + }, + "PARTY1": { + "Data_File": "mpc_arithmetic_1" + }, + "PARTY2": { + "Data_File": "FAKE_DATA_PARTY_2" + } + } +} \ No newline at end of file diff --git a/src/primihub/algorithm/arithmetic.cc b/src/primihub/algorithm/arithmetic.cc index 2bb24e26..1ff04fed 100644 --- a/src/primihub/algorithm/arithmetic.cc +++ b/src/primihub/algorithm/arithmetic.cc @@ -94,6 +94,7 @@ int ArithmeticExecutor::loadParams(primihub::rpc::Task &task) { // col_and_owner std::string col_and_owner = param_map["Col_And_Owner"].value_string(); + TrimAll(col_and_owner); std::vector tmp1, tmp2, tmp3; str_split(col_and_owner, &tmp1, ';'); for (auto itr = tmp1.begin(); itr != tmp1.end(); itr++) { @@ -113,6 +114,7 @@ int ArithmeticExecutor::loadParams(primihub::rpc::Task &task) { // LOG(INFO) << col_and_owner; std::string col_and_dtype = param_map["Col_And_Dtype"].value_string(); + TrimAll(col_and_dtype); str_split(col_and_dtype, &tmp2, ';'); for (auto itr = tmp2.begin(); itr != tmp2.end(); itr++) { int pos = itr->find('-'); @@ -124,6 +126,7 @@ int ArithmeticExecutor::loadParams(primihub::rpc::Task &task) { // LOG(INFO) << col_and_dtype; expr_ = param_map["Expr"].value_string(); + TrimAll(expr_); int comma_index = expr_.find(","); cmp_col1 = expr_.substr(4, comma_index - 4); cmp_col2 = expr_.substr(comma_index + 1, expr_.length() - comma_index - 2); diff --git a/src/primihub/util/util.cc b/src/primihub/util/util.cc index 5b6d4ada..2c3e31a1 100755 --- a/src/primihub/util/util.cc +++ b/src/primihub/util/util.cc @@ -226,4 +226,28 @@ std::string buf_to_hex_string(const uint8_t* pdata, size_t size) { return ss.str(); } +void TrimLeft(std::string& str) { + if (str.empty()) { + return; + } + str.erase(str.begin(), + std::find_if(str.begin(), str.end(), [](unsigned char ch) { + return !std::isspace(ch);})); +} + +void TrimRight(std::string& str) { + if (str.empty()) { + return; + } + str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) { + return !std::isspace(ch);}).base(), str.end()); +} + +void TrimAll(std::string& str) { + if (str.empty()) { + return; + } + str.erase(remove_if(str.begin(), str.end(), [](unsigned char ch) { + return std::isspace(ch);}), str.end()); +} } // namespace primihub diff --git a/src/primihub/util/util.h b/src/primihub/util/util.h index c61fd977..bdbadb97 100755 --- a/src/primihub/util/util.h +++ b/src/primihub/util/util.h @@ -36,6 +36,9 @@ retcode pbNode2Node(const primihub::rpc::Node& pb_node, Node* node); retcode node2PbNode(const Node& node, rpc::Node* pb_node); retcode parseToNode(const std::string& node_info, Node* node); retcode parseTopbNode(const std::string& node_info, rpc::Node* node); +void TrimLeft(std::string& str); +void TrimRight(std::string& str); +void TrimAll(std::string& str); class SCopedTimer { public: