| 134 | } |
| 135 | |
| 136 | int SDKCodec::EncodeDimension( |
| 137 | const std::map<std::string, std::string>& raw_data, uint32_t pid_num, |
| 138 | std::map<uint32_t, Dimension>* dimensions) { |
| 139 | uint32_t dimension_idx = 0; |
| 140 | for (const auto& column_key : index_) { |
| 141 | if (column_key.flag() != 0) { |
| 142 | dimension_idx++; |
| 143 | continue; |
| 144 | } |
| 145 | std::string key; |
| 146 | for (const auto& name : column_key.col_name()) { |
| 147 | auto pos = raw_data.find(name); |
| 148 | if (pos == raw_data.end()) { |
| 149 | return -1; |
| 150 | } |
| 151 | if (!key.empty()) { |
| 152 | key += "|"; |
| 153 | } |
| 154 | key += pos->second; |
| 155 | } |
| 156 | if (key.empty()) { |
| 157 | const std::string& index_name = column_key.index_name(); |
| 158 | auto pos = raw_data.find(index_name); |
| 159 | if (pos == raw_data.end()) { |
| 160 | return -1; |
| 161 | } |
| 162 | key = pos->second; |
| 163 | } |
| 164 | uint32_t pid = 0; |
| 165 | if (pid_num > 0) { |
| 166 | pid = (uint32_t)(::fedb::base::hash64(key) % pid_num); |
| 167 | } |
| 168 | auto pair = dimensions->emplace(pid, Dimension()); |
| 169 | pair.first->second.emplace_back(std::move(key), dimension_idx); |
| 170 | dimension_idx++; |
| 171 | } |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int SDKCodec::EncodeDimension(const std::vector<std::string>& raw_data, |
| 176 | uint32_t pid_num, |
no test coverage detected