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 2018/09/26 01:46:55 UTC

[arrow] branch master updated: ARROW-3319: [GLib] Add align() to GArrowInputStream and GArrowOutputStream

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 9d007b1  ARROW-3319: [GLib] Add align() to GArrowInputStream and GArrowOutputStream
9d007b1 is described below

commit 9d007b1eed283af6cf3b2120f36bced1b27cfe73
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Wed Sep 26 10:46:35 2018 +0900

    ARROW-3319: [GLib] Add align() to GArrowInputStream and GArrowOutputStream
    
    Author: Kouhei Sutou <ko...@clear-code.com>
    
    Closes #2626 from kou/glib-add-align-to-stream and squashes the following commits:
    
    9bc5d0b7 <Kouhei Sutou> Fix wrong method call
    73f34760 <Kouhei Sutou>  Add align() to GArrowInputStream and GArrowOutputStream
---
 c_glib/arrow-glib/input-stream.cpp             | 42 ++++++++++++++++++++++++++
 c_glib/arrow-glib/input-stream.h               |  6 ++++
 c_glib/arrow-glib/output-stream.cpp            | 21 +++++++++++++
 c_glib/arrow-glib/output-stream.h              |  3 ++
 c_glib/test/test-buffer-input-stream.rb        | 17 +++++++++++
 c_glib/test/test-buffer-output-stream.rb       |  9 ++++++
 c_glib/test/test-memory-mapped-input-stream.rb |  1 -
 7 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/c_glib/arrow-glib/input-stream.cpp b/c_glib/arrow-glib/input-stream.cpp
index b9f4c27..eea66df 100644
--- a/c_glib/arrow-glib/input-stream.cpp
+++ b/c_glib/arrow-glib/input-stream.cpp
@@ -177,6 +177,47 @@ garrow_input_stream_class_init(GArrowInputStreamClass *klass)
   g_object_class_install_property(gobject_class, PROP_INPUT_STREAM, spec);
 }
 
+/**
+ * garrow_input_stream_advance:
+ * @input_stream: A #GArrowInputStream.
+ * @n_bytes: The number of bytes to be advanced.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ *
+ * Since: 0.11.0
+ */
+gboolean
+garrow_input_stream_advance(GArrowInputStream *input_stream,
+                            gint64 n_bytes,
+                            GError **error)
+{
+  auto arrow_input_stream = garrow_input_stream_get_raw(input_stream);
+  auto status = arrow_input_stream->Advance(n_bytes);
+  return garrow_error_check(error, status, "[input-stream][advance]");
+}
+
+/**
+ * garrow_input_stream_align:
+ * @input_stream: A #GArrowInputStream.
+ * @alignment: The byte multiple for the metadata prefix, usually 8
+ *   or 64, to ensure the body starts on a multiple of that alignment.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ *
+ * Since: 0.11.0
+ */
+gboolean
+garrow_input_stream_align(GArrowInputStream *input_stream,
+                          gint32 alignment,
+                          GError **error)
+{
+  auto arrow_input_stream = garrow_input_stream_get_raw(input_stream);
+  auto status = arrow::ipc::AlignStream(arrow_input_stream.get(),
+                                        alignment);
+  return garrow_error_check(error, status, "[input-stream][align]");
+}
 
 /**
  * garrow_input_stream_read_tensor:
@@ -204,6 +245,7 @@ garrow_input_stream_read_tensor(GArrowInputStream *input_stream,
   }
 }
 
+
 G_DEFINE_TYPE(GArrowSeekableInputStream,                \
               garrow_seekable_input_stream,             \
               GARROW_TYPE_INPUT_STREAM);
diff --git a/c_glib/arrow-glib/input-stream.h b/c_glib/arrow-glib/input-stream.h
index 224bcc8..840f27d 100644
--- a/c_glib/arrow-glib/input-stream.h
+++ b/c_glib/arrow-glib/input-stream.h
@@ -37,6 +37,12 @@ struct _GArrowInputStreamClass
   GObjectClass parent_class;
 };
 
+gboolean garrow_input_stream_advance(GArrowInputStream *input_stream,
+                                     gint64 n_bytes,
+                                     GError **error);
+gboolean garrow_input_stream_align(GArrowInputStream *input_stream,
+                                   gint32 alignment,
+                                   GError **error);
 GArrowTensor *garrow_input_stream_read_tensor(GArrowInputStream *input_stream,
                                               GError **error);
 
diff --git a/c_glib/arrow-glib/output-stream.cpp b/c_glib/arrow-glib/output-stream.cpp
index c9f6e71..98c97f0 100644
--- a/c_glib/arrow-glib/output-stream.cpp
+++ b/c_glib/arrow-glib/output-stream.cpp
@@ -176,6 +176,27 @@ garrow_output_stream_class_init(GArrowOutputStreamClass *klass)
 }
 
 /**
+ * garrow_output_stream_align:
+ * @stream: A #GArrowWritable.
+ * @alignment: The byte multiple for the metadata prefix, usually 8
+ *   or 64, to ensure the body starts on a multiple of that alignment.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE on error.
+ *
+ * Since: 0.11.0
+ */
+gboolean
+garrow_output_stream_align(GArrowOutputStream *stream,
+                           gint32 alignment,
+                           GError **error)
+{
+  auto arrow_stream = garrow_output_stream_get_raw(stream);
+  auto status = arrow::ipc::AlignStream(arrow_stream.get(), alignment);
+  return garrow_error_check(error, status, "[output-stream][align]");
+}
+
+/**
  * garrow_output_stream_write_tensor:
  * @stream: A #GArrowWritable.
  * @tensor: A #GArrowTensor to be written.
diff --git a/c_glib/arrow-glib/output-stream.h b/c_glib/arrow-glib/output-stream.h
index 195a97a..5d887c5 100644
--- a/c_glib/arrow-glib/output-stream.h
+++ b/c_glib/arrow-glib/output-stream.h
@@ -37,6 +37,9 @@ struct _GArrowOutputStreamClass
   GObjectClass parent_class;
 };
 
+gboolean garrow_output_stream_align(GArrowOutputStream *stream,
+                                    gint32 alignment,
+                                    GError **error);
 gint64 garrow_output_stream_write_tensor(GArrowOutputStream *stream,
                                          GArrowTensor *tensor,
                                          GError **error);
diff --git a/c_glib/test/test-buffer-input-stream.rb b/c_glib/test/test-buffer-input-stream.rb
index 51ed8b3..f5a0132 100644
--- a/c_glib/test/test-buffer-input-stream.rb
+++ b/c_glib/test/test-buffer-input-stream.rb
@@ -22,4 +22,21 @@ class TestBufferInputStream < Test::Unit::TestCase
     read_buffer = buffer_input_stream.read(5)
     assert_equal("Hello", read_buffer.data.to_s)
   end
+
+  def test_advance
+    buffer = Arrow::Buffer.new("Hello World")
+    buffer_input_stream = Arrow::BufferInputStream.new(buffer)
+    buffer_input_stream.advance(6)
+    read_buffer = buffer_input_stream.read(5)
+    assert_equal("World", read_buffer.data.to_s)
+  end
+
+  def test_align
+    buffer = Arrow::Buffer.new("Hello World")
+    buffer_input_stream = Arrow::BufferInputStream.new(buffer)
+    buffer_input_stream.advance(3)
+    buffer_input_stream.align(8)
+    read_buffer = buffer_input_stream.read(3)
+    assert_equal("rld", read_buffer.data.to_s)
+  end
 end
diff --git a/c_glib/test/test-buffer-output-stream.rb b/c_glib/test/test-buffer-output-stream.rb
index e1f2617..b68b60e 100644
--- a/c_glib/test/test-buffer-output-stream.rb
+++ b/c_glib/test/test-buffer-output-stream.rb
@@ -23,4 +23,13 @@ class TestBufferOutputStream < Test::Unit::TestCase
     output_stream.close
     assert_equal("Hello", buffer.data.to_s)
   end
+
+  def test_align
+    buffer = Arrow::ResizableBuffer.new(0)
+    output_stream = Arrow::BufferOutputStream.new(buffer)
+    output_stream.write("Hello")
+    output_stream.align(8)
+    output_stream.close
+    assert_equal("Hello\x00\x00\x00", buffer.data.to_s)
+  end
 end
diff --git a/c_glib/test/test-memory-mapped-input-stream.rb b/c_glib/test/test-memory-mapped-input-stream.rb
index c3a5f62..a02d925 100644
--- a/c_glib/test/test-memory-mapped-input-stream.rb
+++ b/c_glib/test/test-memory-mapped-input-stream.rb
@@ -67,7 +67,6 @@ class TestMemoryMappedInputStream < Test::Unit::TestCase
     end
   end
 
-
   def test_mode
     tempfile = Tempfile.open("arrow-memory-mapped-input-stream")
     tempfile.write("Hello World")