| 316 | } |
| 317 | |
| 318 | Result<std::vector<std::string>> KeyValuePartitioning::FormatPartitionSegments( |
| 319 | const ScalarVector& values) const { |
| 320 | std::vector<std::string> segments(static_cast<size_t>(schema_->num_fields())); |
| 321 | |
| 322 | for (int i = 0; i < schema_->num_fields(); ++i) { |
| 323 | if (values[i] != nullptr && values[i]->is_valid) { |
| 324 | segments[i] = values[i]->ToString(); |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | if (auto illegal_index = NextValid(values, i)) { |
| 329 | // XXX maybe we should just ignore keys provided after the first absent one? |
| 330 | return Status::Invalid("No partition key for ", schema_->field(i)->name(), |
| 331 | " but a key was provided subsequently for ", |
| 332 | schema_->field(*illegal_index)->name(), "."); |
| 333 | } |
| 334 | |
| 335 | // if all subsequent keys are absent we'll just print the available keys |
| 336 | break; |
| 337 | } |
| 338 | return segments; |
| 339 | } |
| 340 | |
| 341 | Result<std::vector<KeyValuePartitioning::Key>> |
| 342 | KeyValuePartitioning::ParsePartitionSegments( |