westonpace commented on a change in pull request #12530:
URL: https://github.com/apache/arrow/pull/12530#discussion_r831708034



##########
File path: cpp/src/arrow/dataset/partition.cc
##########
@@ -61,6 +61,16 @@ Result<std::string> SafeUriUnescape(util::string_view 
encoded) {
   }
   return decoded;
 }
+
+std::string StripNonPrefix(const std::string& path) {
+  std::string v;
+  auto non_prefix_index = path.rfind(kFilenamePartitionSep);
+  if (path.length() > 0 && non_prefix_index != std::string::npos) {

Review comment:
       ```suggestion
     if (non_prefix_index != std::string::npos) {
   ```
   Minor nit: If `length() <= 0` then `non_prefix_index != std::string::npos` 
will always be false so you can do away with the first check.

##########
File path: cpp/src/arrow/dataset/partition.cc
##########
@@ -361,7 +411,32 @@ Result<std::string> DirectoryPartitioning::FormatValues(
     break;
   }
 
-  return fs::internal::JoinAbstractPath(std::move(segments));
+  return std::make_pair(fs::internal::JoinAbstractPath(std::move(segments)), 
"");
+}
+
+Result<std::pair<std::string, std::string>> FilenamePartitioning::FormatValues(
+    const ScalarVector& values) const {
+  std::vector<std::string> 
segments(static_cast<size_t>(schema_->num_fields()));
+
+  for (int i = 0; i < schema_->num_fields(); ++i) {
+    if (values[i] != nullptr && values[i]->is_valid) {
+      segments[i] = values[i]->ToString();
+      continue;
+    }
+
+    if (auto illegal_index = NextValid(values, i)) {
+      // XXX maybe we should just ignore keys provided after the first absent 
one?
+      return Status::Invalid("No partition key for ", 
schema_->field(i)->name(),
+                             " but a key was provided subsequently for ",
+                             schema_->field(*illegal_index)->name(), ".");
+    }
+
+    // if all subsequent keys are absent we'll just print the available keys
+    break;

Review comment:
       That should be fine for this case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to