You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/11/14 16:18:05 UTC

[arrow] branch master updated: ARROW-1806: [GLib] Add garrow_record_batch_writer_write_table()

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

wesm 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 e3db5da  ARROW-1806: [GLib] Add garrow_record_batch_writer_write_table()
e3db5da is described below

commit e3db5da648bb74b3d325042e595ae856f1ad8f7f
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Tue Nov 14 11:17:59 2017 -0500

    ARROW-1806: [GLib] Add garrow_record_batch_writer_write_table()
    
    Author: Kouhei Sutou <ko...@clear-code.com>
    
    Closes #1315 from kou/glib-add-recored-batch-writer-write-table and squashes the following commits:
    
    15743615 [Kouhei Sutou] [GLib] Add garrow_record_batch_writer_write_table()
---
 c_glib/arrow-glib/writer.cpp    | 25 +++++++++++++++++++++++++
 c_glib/arrow-glib/writer.h      |  4 ++++
 c_glib/test/test-file-writer.rb | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)

diff --git a/c_glib/arrow-glib/writer.cpp b/c_glib/arrow-glib/writer.cpp
index 7d3b594..9bcda2d 100644
--- a/c_glib/arrow-glib/writer.cpp
+++ b/c_glib/arrow-glib/writer.cpp
@@ -25,6 +25,7 @@
 #include <arrow-glib/error.hpp>
 #include <arrow-glib/record-batch.hpp>
 #include <arrow-glib/schema.hpp>
+#include <arrow-glib/table.hpp>
 
 #include <arrow-glib/output-stream.hpp>
 
@@ -166,6 +167,30 @@ garrow_record_batch_writer_write_record_batch(GArrowRecordBatchWriter *writer,
 }
 
 /**
+ * garrow_record_batch_writer_write_table:
+ * @writer: A #GArrowRecordBatchWriter.
+ * @table: The table to be written.
+ * @error: (nullable): Return locatipcn for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.8.0
+ */
+gboolean
+garrow_record_batch_writer_write_table(GArrowRecordBatchWriter *writer,
+                                       GArrowTable *table,
+                                       GError **error)
+{
+  auto arrow_writer = garrow_record_batch_writer_get_raw(writer);
+  auto arrow_table = garrow_table_get_raw(table);
+
+  auto status = arrow_writer->WriteTable(*arrow_table);
+  return garrow_error_check(error,
+                            status,
+                            "[record-batch-writer][write-table]");
+}
+
+/**
  * garrow_record_batch_writer_close:
  * @writer: A #GArrowRecordBatchWriter.
  * @error: (nullable): Return locatipcn for a #GError or %NULL.
diff --git a/c_glib/arrow-glib/writer.h b/c_glib/arrow-glib/writer.h
index 3853c2b..41b5f72 100644
--- a/c_glib/arrow-glib/writer.h
+++ b/c_glib/arrow-glib/writer.h
@@ -77,6 +77,10 @@ gboolean garrow_record_batch_writer_write_record_batch(
   GArrowRecordBatchWriter *writer,
   GArrowRecordBatch *record_batch,
   GError **error);
+gboolean garrow_record_batch_writer_write_table(
+  GArrowRecordBatchWriter *writer,
+  GArrowTable *table,
+  GError **error);
 gboolean garrow_record_batch_writer_close(
   GArrowRecordBatchWriter *writer,
   GError **error);
diff --git a/c_glib/test/test-file-writer.rb b/c_glib/test/test-file-writer.rb
index 6ba5c7a..3de8e5c 100644
--- a/c_glib/test/test-file-writer.rb
+++ b/c_glib/test/test-file-writer.rb
@@ -16,6 +16,8 @@
 # under the License.
 
 class TestFileWriter < Test::Unit::TestCase
+  include Helper::Buildable
+
   def test_write_record_batch
     tempfile = Tempfile.open("arrow-ipc-file-writer")
     output = Arrow::FileOutputStream.new(tempfile.path, false)
@@ -42,4 +44,35 @@ class TestFileWriter < Test::Unit::TestCase
       input.close
     end
   end
+
+  def test_write_table
+    tempfile = Tempfile.open("arrow-ipc-file-writer")
+    output = Arrow::FileOutputStream.new(tempfile.path, false)
+
+    array = build_boolean_array([true, false, true])
+    field = Arrow::Field.new("enabled", Arrow::BooleanDataType.new)
+    schema = Arrow::Schema.new([field])
+    column = Arrow::Column.new(field, array)
+
+    begin
+      file_writer = Arrow::RecordBatchFileWriter.new(output, schema)
+      begin
+        table = Arrow::Table.new(schema, [column])
+        file_writer.write_table(table)
+      ensure
+        file_writer.close
+      end
+    ensure
+      output.close
+    end
+
+    input = Arrow::MemoryMappedInputStream.new(tempfile.path)
+    begin
+      file_reader = Arrow::RecordBatchFileReader.new(input)
+      assert_equal(Arrow::RecordBatch.new(schema, array.length, [array]),
+                   file_reader.read_record_batch(0))
+    ensure
+      input.close
+    end
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].