You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/05/11 18:00:13 UTC
[GitHub] [arrow] pitrou opened a new pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
pitrou opened a new pull request #10295:
URL: https://github.com/apache/arrow/pull/10295
Extend the InputStream API to allow reading metadata.
Extend the FileSystem API to allow setting metadata when creating an output stream or file.
Implement metadata reading and writing in the S3 filesystem.
A few metadata keys are supported such as "Content-Type" and "Expires".
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou edited a comment on pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou edited a comment on pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#issuecomment-838955600
There's a weird undefined reference to `std::vector<arrow::io::StreamMetadata::KeyValue, std::allocator<arrow::io::StreamMetadata::KeyValue> >::vector()` in two of the R builds...
Edit: apparently it's a [GCC bug](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68070). Darn.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640795898
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
Review comment:
Hmm, why not.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640796508
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
+ auto push_datetime = [&](std::string k, const Aws::Utils::DateTime& v) {
+ if (v != Aws::Utils::DateTime(0.0)) {
+ push(std::move(k), v.ToGmtString(Aws::Utils::DateFormat::ISO_8601));
+ }
+ };
+
+ keys.push_back("Content-Length");
+ values.push_back(std::to_string(result.GetContentLength()));
+
+ push("Cache-Control", result.GetCacheControl());
+ push("Content-Type", result.GetContentType());
+ push("Content-Language", result.GetContentLanguage());
+ push("ETag", result.GetETag());
+ push("VersionId", result.GetVersionId());
+ push_datetime("Last-Modified", result.GetLastModified());
+ push_datetime("Expires", result.GetExpires());
+ return std::make_shared<const KeyValueMetadata>(std::move(keys), std::move(values));
+}
+
+template <typename ObjectRequest>
+struct ObjectMetadataSetter {
+ ObjectRequest* req;
+
Review comment:
Right :-)
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r630409762
##########
File path: cpp/src/arrow/io/interfaces.h
##########
@@ -49,6 +49,26 @@ struct ReadRange {
}
};
+struct StreamMetadata {
+ struct KeyValue {
+ std::string key;
+ std::string value;
+
+ KeyValue() = default;
+ KeyValue(std::string key, std::string value)
+ : key(std::move(key)), value(std::move(value)) {}
+
+ friend bool operator==(const KeyValue& left, const KeyValue& right) {
+ return (left.key == right.key && left.value == right.value);
+ }
+ friend bool operator!=(const KeyValue& left, const KeyValue& right) {
+ return !(left == right);
+ }
+ };
+
+ std::vector<KeyValue> items;
+};
Review comment:
I'm not sure about this API. Do we want to simplify this to `using StreamMetadata = std::vector<...>`? Do we want to add a `shared_ptr` somewhere to minimize copies (but I don't think this is performance-critical)?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640800919
##########
File path: cpp/src/arrow/io/interfaces.cc
##########
@@ -105,6 +107,22 @@ Result<util::string_view> InputStream::Peek(int64_t ARROW_ARG_UNUSED(nbytes)) {
bool InputStream::supports_zero_copy() const { return false; }
+Result<std::shared_ptr<const KeyValueMetadata>> InputStream::ReadMetadata() {
+ return std::shared_ptr<const KeyValueMetadata>{};
+}
+
+// Default ReadMetadataAsync() implementation: simply issue the read on the context's
+// executor
+Future<std::shared_ptr<const KeyValueMetadata>> InputStream::ReadMetadataAsync(
+ const IOContext& ctx) {
+ auto self = shared_from_this();
+ return DeferNotOk(internal::SubmitIO(ctx, [self] { return self->ReadMetadata(); }));
Review comment:
`IOContext` copies are cheap, so I'm not sure there's a problem here.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640794785
##########
File path: cpp/src/arrow/filesystem/filesystem.h
##########
@@ -283,13 +283,17 @@ class ARROW_EXPORT FileSystem : public std::enable_shared_from_this<FileSystem>
///
/// If the target already exists, existing data is truncated.
virtual Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
- const std::string& path) = 0;
+ const std::string& path,
+ const std::shared_ptr<const KeyValueMetadata>& metadata) = 0;
Review comment:
Not necessarily, the stream may not support it or it may convert the metadata to its own internal format.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640801703
##########
File path: cpp/src/arrow/filesystem/filesystem.h
##########
@@ -283,13 +283,17 @@ class ARROW_EXPORT FileSystem : public std::enable_shared_from_this<FileSystem>
///
/// If the target already exists, existing data is truncated.
virtual Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
- const std::string& path) = 0;
+ const std::string& path,
+ const std::shared_ptr<const KeyValueMetadata>& metadata) = 0;
Review comment:
`KeyValueMetadata` is really just a glorified way of passing a collection of key-value pairs.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#issuecomment-838918771
https://issues.apache.org/jira/browse/ARROW-11161
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640796204
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
+ auto push_datetime = [&](std::string k, const Aws::Utils::DateTime& v) {
+ if (v != Aws::Utils::DateTime(0.0)) {
Review comment:
Well, this is the value returned by the AWS SDK when the information is unavailable, AFAIK.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou closed pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou closed pull request #10295:
URL: https://github.com/apache/arrow/pull/10295
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] bkietz commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
bkietz commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r631232530
##########
File path: cpp/src/arrow/io/interfaces.h
##########
@@ -49,6 +49,26 @@ struct ReadRange {
}
};
+struct StreamMetadata {
+ struct KeyValue {
+ std::string key;
+ std::string value;
+
+ KeyValue() = default;
+ KeyValue(std::string key, std::string value)
+ : key(std::move(key)), value(std::move(value)) {}
+
+ friend bool operator==(const KeyValue& left, const KeyValue& right) {
+ return (left.key == right.key && left.value == right.value);
+ }
+ friend bool operator!=(const KeyValue& left, const KeyValue& right) {
+ return !(left == right);
+ }
+ };
+
+ std::vector<KeyValue> items;
+};
Review comment:
Mostly, I'd like to reuse KeyValueMetadata unless there's a reason not to
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#issuecomment-838955600
There's a weird undefined reference to `std::vector<arrow::io::StreamMetadata::KeyValue, std::allocator<arrow::io::StreamMetadata::KeyValue> >::vector()` in two of the R builds...
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] bkietz commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
bkietz commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r640771854
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
+ auto push_datetime = [&](std::string k, const Aws::Utils::DateTime& v) {
+ if (v != Aws::Utils::DateTime(0.0)) {
Review comment:
I suppose this is unlikely to be a valid "Last-Modified" or "Expires" but it still looks odd
##########
File path: cpp/src/arrow/filesystem/test_util.h
##########
@@ -140,6 +140,8 @@ class ARROW_TESTING_EXPORT GenericFileSystemTest {
virtual bool have_directory_mtimes() const { return true; }
// - Whether some directory tree deletion tests may fail randomly
virtual bool have_flaky_directory_tree_deletion() const { return false; }
+ // - Whether the filesystem stores some metadata along files
Review comment:
```suggestion
// - Whether the filesystem stores some metadata alongside files
```
##########
File path: cpp/src/arrow/filesystem/filesystem.h
##########
@@ -283,13 +283,17 @@ class ARROW_EXPORT FileSystem : public std::enable_shared_from_this<FileSystem>
///
/// If the target already exists, existing data is truncated.
virtual Result<std::shared_ptr<io::OutputStream>> OpenOutputStream(
- const std::string& path) = 0;
+ const std::string& path,
+ const std::shared_ptr<const KeyValueMetadata>& metadata) = 0;
Review comment:
Nit: the produced stream will always take ownership of `metadata`, so this shouldn't be a ref
```suggestion
std::shared_ptr<const KeyValueMetadata> metadata) = 0;
```
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
+ auto push_datetime = [&](std::string k, const Aws::Utils::DateTime& v) {
+ if (v != Aws::Utils::DateTime(0.0)) {
+ push(std::move(k), v.ToGmtString(Aws::Utils::DateFormat::ISO_8601));
+ }
+ };
+
+ keys.push_back("Content-Length");
+ values.push_back(std::to_string(result.GetContentLength()));
+
+ push("Cache-Control", result.GetCacheControl());
+ push("Content-Type", result.GetContentType());
+ push("Content-Language", result.GetContentLanguage());
+ push("ETag", result.GetETag());
+ push("VersionId", result.GetVersionId());
+ push_datetime("Last-Modified", result.GetLastModified());
+ push_datetime("Expires", result.GetExpires());
+ return std::make_shared<const KeyValueMetadata>(std::move(keys), std::move(values));
+}
+
+template <typename ObjectRequest>
+struct ObjectMetadataSetter {
+ ObjectRequest* req;
+
Review comment:
```suggestion
```
##########
File path: cpp/src/arrow/filesystem/s3fs.cc
##########
@@ -684,6 +685,85 @@ Result<S3Model::GetObjectResult> GetObjectRange(Aws::S3::S3Client* client,
return OutcomeToResult(client->GetObject(req));
}
+template <typename ObjectResult>
+std::shared_ptr<const KeyValueMetadata> GetObjectMetadata(const ObjectResult& result) {
+ std::vector<std::string> keys, values;
+
+ auto push = [&](std::string k, const Aws::String& v) {
+ if (!v.empty()) {
+ keys.push_back(std::move(k));
+ values.push_back(FromAwsString(v).to_string());
+ }
+ };
Review comment:
You can create a mutable KeyValueMetadata and return it from this function (`shared_ptr<T>` implicitly converts to `shared_ptr<const T>`)
```suggestion
std::shared_ptr<KeyValueMetadata> metadata;
auto push = [&](std::string k, const Aws::String& v) {
if (!v.empty()) {
metadata->Append(std::move(k), FromAwsString(v).to_string());
}
};
```
##########
File path: cpp/src/arrow/io/interfaces.cc
##########
@@ -105,6 +107,22 @@ Result<util::string_view> InputStream::Peek(int64_t ARROW_ARG_UNUSED(nbytes)) {
bool InputStream::supports_zero_copy() const { return false; }
+Result<std::shared_ptr<const KeyValueMetadata>> InputStream::ReadMetadata() {
+ return std::shared_ptr<const KeyValueMetadata>{};
+}
+
+// Default ReadMetadataAsync() implementation: simply issue the read on the context's
+// executor
+Future<std::shared_ptr<const KeyValueMetadata>> InputStream::ReadMetadataAsync(
+ const IOContext& ctx) {
+ auto self = shared_from_this();
+ return DeferNotOk(internal::SubmitIO(ctx, [self] { return self->ReadMetadata(); }));
Review comment:
Could you clarify ownership of `ctx`? SubmitIO makes a copy but doesn't seem to need it. If the copy is intentional, please unref the `ctx` arg
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] pitrou commented on a change in pull request #10295: ARROW-11161: [C++][Python] Add stream metadata
Posted by GitBox <gi...@apache.org>.
pitrou commented on a change in pull request #10295:
URL: https://github.com/apache/arrow/pull/10295#discussion_r631285489
##########
File path: cpp/src/arrow/io/interfaces.h
##########
@@ -49,6 +49,26 @@ struct ReadRange {
}
};
+struct StreamMetadata {
+ struct KeyValue {
+ std::string key;
+ std::string value;
+
+ KeyValue() = default;
+ KeyValue(std::string key, std::string value)
+ : key(std::move(key)), value(std::move(value)) {}
+
+ friend bool operator==(const KeyValue& left, const KeyValue& right) {
+ return (left.key == right.key && left.value == right.value);
+ }
+ friend bool operator!=(const KeyValue& left, const KeyValue& right) {
+ return !(left == right);
+ }
+ };
+
+ std::vector<KeyValue> items;
+};
Review comment:
Hmm, I had not thought about this. Interesting idea, I'll try it.
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org