arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-918: [GLib] Use GArrowBuffer for read buffer
Date Sun, 30 Apr 2017 17:31:55 GMT
Repository: arrow
Updated Branches:
  refs/heads/master ce0c96221 -> 2d5142cd3


ARROW-918: [GLib] Use GArrowBuffer for read buffer

It's efficient.

Author: Kouhei Sutou <kou@clear-code.com>

Closes #618 from kou/glib-read-buffer and squashes the following commits:

e14bb40 [Kouhei Sutou] [GLib] Use GArrowBuffer for read buffer


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/2d5142cd
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/2d5142cd
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/2d5142cd

Branch: refs/heads/master
Commit: 2d5142cd3fc9a5f5150daf6ea6335029de8002ae
Parents: ce0c962
Author: Kouhei Sutou <kou@clear-code.com>
Authored: Sun Apr 30 13:31:49 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Sun Apr 30 13:31:49 2017 -0400

----------------------------------------------------------------------
 c_glib/arrow-glib/random-access-file.cpp | 20 +++++++++++---------
 c_glib/arrow-glib/random-access-file.h   | 10 ++++------
 c_glib/arrow-glib/readable.cpp           | 23 +++++++++++++----------
 c_glib/arrow-glib/readable.h             | 10 ++++------
 c_glib/test/test-memory-mapped-file.rb   | 18 +++++++-----------
 5 files changed, 39 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/2d5142cd/c_glib/arrow-glib/random-access-file.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/random-access-file.cpp b/c_glib/arrow-glib/random-access-file.cpp
index 976a80d..7441316 100644
--- a/c_glib/arrow-glib/random-access-file.cpp
+++ b/c_glib/arrow-glib/random-access-file.cpp
@@ -23,6 +23,7 @@
 
 #include <arrow/api.h>
 
+#include <arrow-glib/buffer.hpp>
 #include <arrow-glib/error.hpp>
 #include <arrow-glib/random-access-file.hpp>
 
@@ -88,28 +89,29 @@ garrow_random_access_file_get_support_zero_copy(GArrowRandomAccessFile
*file)
  * @file: A #GArrowRandomAccessFile.
  * @position: The read start position.
  * @n_bytes: The number of bytes to be read.
- * @n_read_bytes: (out): The read number of bytes.
- * @buffer: (array length=n_bytes): The buffer to be read data.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Returns: %TRUE on success, %FALSE if there was an error.
+ * Returns: (transfer full) (nullable): #GArrowBuffer that has read
+ *   data on success, %NULL if there was an error.
  */
-gboolean
+GArrowBuffer *
 garrow_random_access_file_read_at(GArrowRandomAccessFile *file,
                                      gint64 position,
                                      gint64 n_bytes,
-                                     gint64 *n_read_bytes,
-                                     guint8 *buffer,
                                      GError **error)
 {
   const auto arrow_random_access_file =
     garrow_random_access_file_get_raw(file);
 
+  std::shared_ptr<arrow::Buffer> arrow_buffer;
   auto status = arrow_random_access_file->ReadAt(position,
                                                  n_bytes,
-                                                 n_read_bytes,
-                                                 buffer);
-  return garrow_error_check(error, status, "[io][random-access-file][read-at]");
+                                                 &arrow_buffer);
+  if (garrow_error_check(error, status, "[io][random-access-file][read-at]")) {
+    return garrow_buffer_new_raw(&arrow_buffer);
+  } else {
+    return NULL;
+  }
 }
 
 G_END_DECLS

http://git-wip-us.apache.org/repos/asf/arrow/blob/2d5142cd/c_glib/arrow-glib/random-access-file.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/random-access-file.h b/c_glib/arrow-glib/random-access-file.h
index 8a7f6b4..83a7d8c 100644
--- a/c_glib/arrow-glib/random-access-file.h
+++ b/c_glib/arrow-glib/random-access-file.h
@@ -45,11 +45,9 @@ GType garrow_random_access_file_get_type(void) G_GNUC_CONST;
 guint64 garrow_random_access_file_get_size(GArrowRandomAccessFile *file,
                                               GError **error);
 gboolean garrow_random_access_file_get_support_zero_copy(GArrowRandomAccessFile *file);
-gboolean garrow_random_access_file_read_at(GArrowRandomAccessFile *file,
-                                              gint64 position,
-                                              gint64 n_bytes,
-                                              gint64 *n_read_bytes,
-                                              guint8 *buffer,
-                                              GError **error);
+GArrowBuffer *garrow_random_access_file_read_at(GArrowRandomAccessFile *file,
+                                                gint64 position,
+                                                gint64 n_bytes,
+                                                GError **error);
 
 G_END_DECLS

http://git-wip-us.apache.org/repos/asf/arrow/blob/2d5142cd/c_glib/arrow-glib/readable.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/readable.cpp b/c_glib/arrow-glib/readable.cpp
index d893853..6a9023e 100644
--- a/c_glib/arrow-glib/readable.cpp
+++ b/c_glib/arrow-glib/readable.cpp
@@ -23,6 +23,7 @@
 
 #include <arrow/api.h>
 
+#include <arrow-glib/buffer.hpp>
 #include <arrow-glib/error.hpp>
 #include <arrow-glib/readable.hpp>
 
@@ -50,23 +51,25 @@ garrow_readable_default_init (GArrowReadableInterface *iface)
  * garrow_readable_read:
  * @readable: A #GArrowReadable.
  * @n_bytes: The number of bytes to be read.
- * @n_read_bytes: (out): The read number of bytes.
- * @buffer: (array length=n_bytes): The buffer to be read data.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Returns: %TRUE on success, %FALSE if there was an error.
+ * Returns: (transfer full) (nullable): #GArrowBuffer that has read
+ *   data on success, %NULL if there was an error.
  */
-gboolean
+GArrowBuffer *
 garrow_readable_read(GArrowReadable *readable,
-                        gint64 n_bytes,
-                        gint64 *n_read_bytes,
-                        guint8 *buffer,
-                        GError **error)
+                     gint64 n_bytes,
+                     GError **error)
 {
   const auto arrow_readable = garrow_readable_get_raw(readable);
 
-  auto status = arrow_readable->Read(n_bytes, n_read_bytes, buffer);
-  return garrow_error_check(error, status, "[io][readable][read]");
+  std::shared_ptr<arrow::Buffer> arrow_buffer;
+  auto status = arrow_readable->Read(n_bytes, &arrow_buffer);
+  if (garrow_error_check(error, status, "[io][readable][read]")) {
+    return garrow_buffer_new_raw(&arrow_buffer);
+  } else {
+    return NULL;
+  }
 }
 
 G_END_DECLS

http://git-wip-us.apache.org/repos/asf/arrow/blob/2d5142cd/c_glib/arrow-glib/readable.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/readable.h b/c_glib/arrow-glib/readable.h
index bde4b01..216e736 100644
--- a/c_glib/arrow-glib/readable.h
+++ b/c_glib/arrow-glib/readable.h
@@ -19,7 +19,7 @@
 
 #pragma once
 
-#include <glib-object.h>
+#include <arrow-glib/buffer.h>
 
 G_BEGIN_DECLS
 
@@ -42,10 +42,8 @@ typedef struct _GArrowReadableInterface GArrowReadableInterface;
 
 GType garrow_readable_get_type(void) G_GNUC_CONST;
 
-gboolean garrow_readable_read(GArrowReadable *readable,
-                                 gint64 n_bytes,
-                                 gint64 *n_read_bytes,
-                                 guint8 *buffer,
-                                 GError **error);
+GArrowBuffer *garrow_readable_read(GArrowReadable *readable,
+                                   gint64 n_bytes,
+                                   GError **error);
 
 G_END_DECLS

http://git-wip-us.apache.org/repos/asf/arrow/blob/2d5142cd/c_glib/test/test-memory-mapped-file.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-memory-mapped-file.rb b/c_glib/test/test-memory-mapped-file.rb
index e78d07a..e09e369 100644
--- a/c_glib/test/test-memory-mapped-file.rb
+++ b/c_glib/test/test-memory-mapped-file.rb
@@ -22,9 +22,8 @@ class TestMemoryMappedFile < Test::Unit::TestCase
     tempfile.close
     file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
     begin
-      buffer = " " * 5
-      file.read(buffer)
-      assert_equal("Hello", buffer)
+      buffer = file.read(5)
+      assert_equal("Hello", buffer.data.to_s)
     ensure
       file.close
     end
@@ -48,9 +47,8 @@ class TestMemoryMappedFile < Test::Unit::TestCase
     tempfile.close
     file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
     begin
-      buffer = " " * 5
-      _success, n_read_bytes = file.read(buffer)
-      assert_equal("Hello", buffer.byteslice(0, n_read_bytes))
+      buffer = file.read(5)
+      assert_equal("Hello", buffer.data.to_s)
     ensure
       file.close
     end
@@ -62,9 +60,8 @@ class TestMemoryMappedFile < Test::Unit::TestCase
     tempfile.close
     file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
     begin
-      buffer = " " * 5
-      _success, n_read_bytes = file.read_at(6, buffer)
-      assert_equal("World", buffer.byteslice(0, n_read_bytes))
+      buffer = file.read_at(6, 5)
+      assert_equal("World", buffer.data.to_s)
     ensure
       file.close
     end
@@ -116,8 +113,7 @@ class TestMemoryMappedFile < Test::Unit::TestCase
     tempfile.close
     file = Arrow::MemoryMappedFile.open(tempfile.path, :read)
     begin
-      buffer = " " * 5
-      file.read(buffer)
+      file.read(5)
       assert_equal(5, file.tell)
     ensure
       file.close


Mime
View raw message