You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2022/07/03 10:45:42 UTC

[arrow] branch master updated: ARROW-16971: [GLib] Check g_seekable_can_seek() before calling g_seekable_tell() (#13498)

This is an automated email from the ASF dual-hosted git repository.

kou 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 2c7c12fd40 ARROW-16971: [GLib] Check g_seekable_can_seek() before calling g_seekable_tell() (#13498)
2c7c12fd40 is described below

commit 2c7c12fd408339817f0322f137d25e9f60a87a26
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Sun Jul 3 19:45:36 2022 +0900

    ARROW-16971: [GLib] Check g_seekable_can_seek() before calling g_seekable_tell() (#13498)
    
    Authored-by: Sutou Kouhei <ko...@clear-code.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/input-stream.cpp   |  3 ++-
 c_glib/arrow-glib/output-stream.cpp  |  3 ++-
 ruby/red-arrow/example/read-pipe.rb  | 27 ++++++++++++++++++++++++++
 ruby/red-arrow/example/write-pipe.rb | 37 ++++++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/c_glib/arrow-glib/input-stream.cpp b/c_glib/arrow-glib/input-stream.cpp
index 0a21cee6b6..e1e46c7df1 100644
--- a/c_glib/arrow-glib/input-stream.cpp
+++ b/c_glib/arrow-glib/input-stream.cpp
@@ -788,7 +788,8 @@ namespace garrow {
     }
 
     arrow::Result<int64_t> Tell() const override {
-      if (!G_IS_SEEKABLE(input_stream_)) {
+      if (!(G_IS_SEEKABLE(input_stream_) &&
+            g_seekable_can_seek(G_SEEKABLE(input_stream_)))) {
         std::string message("[gio-input-stream][tell] "
                             "not seekable input stream: <");
         message += G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(input_stream_));
diff --git a/c_glib/arrow-glib/output-stream.cpp b/c_glib/arrow-glib/output-stream.cpp
index 9eaee9a81d..bcb901d5f9 100644
--- a/c_glib/arrow-glib/output-stream.cpp
+++ b/c_glib/arrow-glib/output-stream.cpp
@@ -383,7 +383,8 @@ namespace garrow {
     }
 
     arrow::Result<int64_t> Tell() const override {
-      if (G_IS_SEEKABLE(output_stream_)) {
+      if (G_IS_SEEKABLE(output_stream_) &&
+          g_seekable_can_seek(G_SEEKABLE(output_stream_))) {
         return g_seekable_tell(G_SEEKABLE(output_stream_));
       } else {
         return position_;
diff --git a/ruby/red-arrow/example/read-pipe.rb b/ruby/red-arrow/example/read-pipe.rb
new file mode 100755
index 0000000000..b8c7ada124
--- /dev/null
+++ b/ruby/red-arrow/example/read-pipe.rb
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require "arrow"
+
+Gio::RubyInputStream.open($stdin) do |gio_input|
+  Arrow::GIOInputStream.open(gio_input) do |arrow_input|
+    reader = Arrow::RecordBatchStreamReader.new(arrow_input)
+    p reader.read_all
+  end
+end
diff --git a/ruby/red-arrow/example/write-pipe.rb b/ruby/red-arrow/example/write-pipe.rb
new file mode 100755
index 0000000000..0781dc6427
--- /dev/null
+++ b/ruby/red-arrow/example/write-pipe.rb
@@ -0,0 +1,37 @@
+#!/usr/bin/env ruby
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+require "arrow"
+
+table = Arrow::Table.new(a: [1, 2, 3],
+                         b: ["a", "b", "c"])
+IO.pipe do |input, output|
+  pid = spawn(RbConfig.ruby, File.join(__dir__, "read-pipe.rb"), in: input)
+  input.close
+  output.singleton_class.__send__(:undef_method, :seek)
+  Gio::RubyOutputStream.open(output) do |gio_output|
+    Arrow::GIOOutputStream.open(gio_output) do |arrow_output|
+      Arrow::RecordBatchStreamWriter.open(arrow_output, table.schema) do |writer|
+        writer.write_table(table)
+      end
+    end
+  end
+  output.close
+  Process.waitpid(pid)
+end