You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by sh...@apache.org on 2020/05/18 00:24:23 UTC
[arrow] branch master updated: ARROW-8830: [GLib] Add support for
Tell against not seekable GIO output stream
This is an automated email from the ASF dual-hosted git repository.
shiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new e5a33f1 ARROW-8830: [GLib] Add support for Tell against not seekable GIO output stream
e5a33f1 is described below
commit e5a33f1220705aec6a224b55d2a6f47fbd957603
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Mon May 18 09:23:52 2020 +0900
ARROW-8830: [GLib] Add support for Tell against not seekable GIO output stream
Closes #7207 from kou/glib-gio-output-define-tell
Authored-by: Sutou Kouhei <ko...@clear-code.com>
Signed-off-by: Yosuke Shiro <yo...@gmail.com>
---
c_glib/arrow-glib/output-stream.cpp | 17 ++++++++---------
c_glib/test/test-gio-output-stream.rb | 16 ++++++++++++++++
2 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/c_glib/arrow-glib/output-stream.cpp b/c_glib/arrow-glib/output-stream.cpp
index 1653332..2c3ccaf 100644
--- a/c_glib/arrow-glib/output-stream.cpp
+++ b/c_glib/arrow-glib/output-stream.cpp
@@ -358,7 +358,8 @@ namespace garrow {
class GIOOutputStream : public arrow::io::OutputStream {
public:
GIOOutputStream(GOutputStream *output_stream) :
- output_stream_(output_stream) {
+ output_stream_(output_stream),
+ position_(0) {
g_object_ref(output_stream_);
}
@@ -386,15 +387,11 @@ namespace garrow {
}
arrow::Result<int64_t> Tell() const override {
- if (!G_IS_SEEKABLE(output_stream_)) {
- std::string message("[gio-output-stream][tell] "
- "not seekable output stream: <");
- message += G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(output_stream_));
- message += ">";
- return arrow::Status::NotImplemented(message);
+ if (G_IS_SEEKABLE(output_stream_)) {
+ return g_seekable_tell(G_SEEKABLE(output_stream_));
+ } else {
+ return position_;
}
-
- return g_seekable_tell(G_SEEKABLE(output_stream_));
}
arrow::Status Write(const void *data,
@@ -408,6 +405,7 @@ namespace garrow {
NULL,
&error);
if (successed) {
+ position_ += n_written_bytes;
return arrow::Status::OK();
} else {
std::stringstream message("[gio-output-stream][write]");
@@ -432,6 +430,7 @@ namespace garrow {
private:
GOutputStream *output_stream_;
+ int64_t position_;
};
};
diff --git a/c_glib/test/test-gio-output-stream.rb b/c_glib/test/test-gio-output-stream.rb
index c77598e..36756cb 100644
--- a/c_glib/test/test-gio-output-stream.rb
+++ b/c_glib/test/test-gio-output-stream.rb
@@ -60,4 +60,20 @@ class TestGIOOutputStream < Test::Unit::TestCase
output = Arrow::GIOOutputStream.new(output_stream)
assert_equal(output_stream, output.raw)
end
+
+ def test_tell
+ unless Gio.const_defined?(:UnixOutputStream)
+ omit("Need Gio::UnixOutputStream")
+ end
+ tempfile = Tempfile.open("arrow-gio-output-stream")
+ begin
+ output_stream = Gio::UnixOutputStream.new(tempfile.to_i, false)
+ output = Arrow::GIOOutputStream.new(output_stream)
+ assert_equal(0, output.tell)
+ output.write("Hello")
+ assert_equal(5, output.tell)
+ ensure
+ tempfile.close!
+ end
+ end
end