arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject arrow git commit: ARROW-967: [GLib] Support initializing array with buffer
Date Mon, 08 May 2017 18:10:17 GMT
Repository: arrow
Updated Branches:
  refs/heads/master cb5e7b6fa -> 3d1983171


ARROW-967: [GLib] Support initializing array with buffer

It's for zero-copy data conversion.

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

Closes #657 from kou/glib-array-new-with-buffer and squashes the following commits:

57f4266 [Kouhei Sutou] [GLib] Support initializing array with buffer


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

Branch: refs/heads/master
Commit: 3d19831717297e91a74e008d44c71695088b39fd
Parents: cb5e7b6
Author: Kouhei Sutou <kou@clear-code.com>
Authored: Mon May 8 20:10:12 2017 +0200
Committer: Uwe L. Korn <uwelk@xhochy.com>
Committed: Mon May 8 20:10:12 2017 +0200

----------------------------------------------------------------------
 c_glib/arrow-glib/array.cpp       | 600 +++++++++++++++++++++++++++++++--
 c_glib/arrow-glib/array.h         |  80 +++++
 c_glib/arrow-glib/buffer.cpp      |   3 +
 c_glib/test/helper/buildable.rb   |  55 +++
 c_glib/test/test-binary-array.rb  |  13 +
 c_glib/test/test-boolean-array.rb |  10 +
 c_glib/test/test-double-array.rb  |  10 +
 c_glib/test/test-float-array.rb   |  10 +
 c_glib/test/test-int16-array.rb   |  10 +
 c_glib/test/test-int32-array.rb   |  10 +
 c_glib/test/test-int64-array.rb   |  10 +
 c_glib/test/test-int8-array.rb    |  10 +
 c_glib/test/test-list-array.rb    |  15 +
 c_glib/test/test-string-array.rb  |  13 +
 c_glib/test/test-struct-array.rb  |  33 ++
 c_glib/test/test-uint16-array.rb  |  10 +
 c_glib/test/test-uint32-array.rb  |  10 +
 c_glib/test/test-uint64-array.rb  |  10 +
 c_glib/test/test-uint8-array.rb   |  10 +
 19 files changed, 889 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/arrow-glib/array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.cpp b/c_glib/arrow-glib/array.cpp
index 8a78984..8bc6ea9 100644
--- a/c_glib/arrow-glib/array.cpp
+++ b/c_glib/arrow-glib/array.cpp
@@ -39,73 +39,89 @@ G_BEGIN_DECLS
  * #GArrowArray is a base class for all array classes such as
  * #GArrowBooleanArray.
  *
- * All array classes are immutable. You need to use array builder
- * class such as #GArrowBooleanArrayBuilder to create a new array
- * except #GArrowNullArray.
+ * All array classes are immutable. You need to use binary data or
+ * array builder to create a new array except #GArrowNullArray. If you
+ * have binary data that uses Arrow format data, you can create a new
+ * array with the binary data as #GArrowBuffer object. If you don't
+ * have binary data, you can use array builder class such as
+ * #GArrowBooleanArrayBuilder that creates Arrow format data
+ * internally and a new array from the data.
  *
  * #GArrowNullArray is a class for null array. It can store zero or
  * more null values. You need to specify an array length to create a
  * new array.
  *
  * #GArrowBooleanArray is a class for binary array. It can store zero
- * or more boolean data. You need to use #GArrowBooleanArrayBuilder to
- * create a new array.
+ * or more boolean data. If you don't have Arrow format data, you need
+ * to use #GArrowBooleanArrayBuilder to create a new array.
  *
  * #GArrowInt8Array is a class for 8-bit integer array. It can store
- * zero or more 8-bit integer data. You need to use
- * #GArrowInt8ArrayBuilder to create a new array.
+ * zero or more 8-bit integer data. If you don't have Arrow format
+ * data, you need to use #GArrowInt8ArrayBuilder to create a new
+ * array.
  *
  * #GArrowUInt8Array is a class for 8-bit unsigned integer array. It
- * can store zero or more 8-bit unsigned integer data. You need to use
- * #GArrowUInt8ArrayBuilder to create a new array.
+ * can store zero or more 8-bit unsigned integer data. If you don't
+ * have Arrow format data, you need to use #GArrowUInt8ArrayBuilder to
+ * create a new array.
  *
  * #GArrowInt16Array is a class for 16-bit integer array. It can store
- * zero or more 16-bit integer data. You need to use
- * #GArrowInt16ArrayBuilder to create a new array.
+ * zero or more 16-bit integer data. If you don't have Arrow format
+ * data, you need to use #GArrowInt16ArrayBuilder to create a new
+ * array.
  *
  * #GArrowUInt16Array is a class for 16-bit unsigned integer array. It
- * can store zero or more 16-bit unsigned integer data. You need to use
- * #GArrowUInt16ArrayBuilder to create a new array.
+ * can store zero or more 16-bit unsigned integer data. If you don't
+ * have Arrow format data, you need to use #GArrowUInt16ArrayBuilder
+ * to create a new array.
  *
  * #GArrowInt32Array is a class for 32-bit integer array. It can store
- * zero or more 32-bit integer data. You need to use
- * #GArrowInt32ArrayBuilder to create a new array.
+ * zero or more 32-bit integer data. If you don't have Arrow format
+ * data, you need to use #GArrowInt32ArrayBuilder to create a new
+ * array.
  *
  * #GArrowUInt32Array is a class for 32-bit unsigned integer array. It
- * can store zero or more 32-bit unsigned integer data. You need to use
- * #GArrowUInt32ArrayBuilder to create a new array.
+ * can store zero or more 32-bit unsigned integer data. If you don't
+ * have Arrow format data, you need to use #GArrowUInt32ArrayBuilder
+ * to create a new array.
  *
  * #GArrowInt64Array is a class for 64-bit integer array. It can store
- * zero or more 64-bit integer data. You need to use
- * #GArrowInt64ArrayBuilder to create a new array.
+ * zero or more 64-bit integer data. If you don't have Arrow format
+ * data, you need to use #GArrowInt64ArrayBuilder to create a new
+ * array.
  *
  * #GArrowUInt64Array is a class for 64-bit unsigned integer array. It
- * can store zero or more 64-bit unsigned integer data. You need to
- * use #GArrowUInt64ArrayBuilder to create a new array.
+ * can store zero or more 64-bit unsigned integer data. If you don't
+ * have Arrow format data, you need to use #GArrowUInt64ArrayBuilder
+ * to create a new array.
  *
  * #GArrowFloatArray is a class for 32-bit floating point array. It
- * can store zero or more 32-bit floating data. You need to use
- * #GArrowFloatArrayBuilder to create a new array.
+ * can store zero or more 32-bit floating data. If you don't have
+ * Arrow format data, you need to use #GArrowFloatArrayBuilder to
+ * create a new array.
  *
  * #GArrowDoubleArray is a class for 64-bit floating point array. It
- * can store zero or more 64-bit floating data. You need to use
- * #GArrowDoubleArrayBuilder to create a new array.
+ * can store zero or more 64-bit floating data. If you don't have
+ * Arrow format data, you need to use #GArrowDoubleArrayBuilder to
+ * create a new array.
  *
  * #GArrowBinaryArray is a class for binary array. It can store zero
- * or more binary data. You need to use #GArrowBinaryArrayBuilder to
- * create a new array.
+ * or more binary data. If you don't have Arrow format data, you need
+ * to use #GArrowBinaryArrayBuilder to create a new array.
  *
  * #GArrowStringArray is a class for UTF-8 encoded string array. It
- * can store zero or more UTF-8 encoded string data. You need to use
- * #GArrowStringArrayBuilder to create a new array.
+ * can store zero or more UTF-8 encoded string data. If you don't have
+ * Arrow format data, you need to use #GArrowStringArrayBuilder to
+ * create a new array.
  *
  * #GArrowListArray is a class for list array. It can store zero or
- * more list data. You need to use #GArrowListArrayBuilder to create a
- * new array.
+ * more list data. If you don't have Arrow format data, you need to
+ * use #GArrowListArrayBuilder to create a new array.
  *
  * #GArrowStructArray is a class for struct array. It can store zero
- * or more structs. One struct has zero or more fields. You need to
- * use #GArrowStructArrayBuilder to create a new array.
+ * or more structs. One struct has zero or more fields. If you don't
+ * have Arrow format data, you need to use #GArrowStructArrayBuilder
+ * to create a new array.
  */
 
 typedef struct GArrowArrayPrivate_ {
@@ -456,6 +472,39 @@ garrow_boolean_array_class_init(GArrowBooleanArrayClass *klass)
 }
 
 /**
+ * garrow_boolean_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowBooleanArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowBooleanArray *
+garrow_boolean_array_new(gint64 length,
+                         GArrowBuffer *data,
+                         GArrowBuffer *null_bitmap,
+                         gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_boolean_array =
+    std::make_shared<arrow::BooleanArray>(length,
+                                          arrow_data,
+                                          arrow_bitmap,
+                                          n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_boolean_array);
+  return GARROW_BOOLEAN_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_boolean_array_get_value:
  * @array: A #GArrowBooleanArray.
  * @i: The index of the target value.
@@ -486,6 +535,39 @@ garrow_int8_array_class_init(GArrowInt8ArrayClass *klass)
 }
 
 /**
+ * garrow_int8_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowInt8Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowInt8Array *
+garrow_int8_array_new(gint64 length,
+                      GArrowBuffer *data,
+                      GArrowBuffer *null_bitmap,
+                      gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_int8_array =
+    std::make_shared<arrow::Int8Array>(length,
+                                       arrow_data,
+                                       arrow_bitmap,
+                                       n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_int8_array);
+  return GARROW_INT8_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_int8_array_get_value:
  * @array: A #GArrowInt8Array.
  * @i: The index of the target value.
@@ -516,6 +598,39 @@ garrow_uint8_array_class_init(GArrowUInt8ArrayClass *klass)
 }
 
 /**
+ * garrow_uint8_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowUInt8Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowUInt8Array *
+garrow_uint8_array_new(gint64 length,
+                       GArrowBuffer *data,
+                       GArrowBuffer *null_bitmap,
+                       gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_uint8_array =
+    std::make_shared<arrow::UInt8Array>(length,
+                                        arrow_data,
+                                        arrow_bitmap,
+                                        n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_uint8_array);
+  return GARROW_UINT8_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_uint8_array_get_value:
  * @array: A #GArrowUInt8Array.
  * @i: The index of the target value.
@@ -546,6 +661,39 @@ garrow_int16_array_class_init(GArrowInt16ArrayClass *klass)
 }
 
 /**
+ * garrow_int16_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowInt16Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowInt16Array *
+garrow_int16_array_new(gint64 length,
+                       GArrowBuffer *data,
+                       GArrowBuffer *null_bitmap,
+                       gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_int16_array =
+    std::make_shared<arrow::Int16Array>(length,
+                                        arrow_data,
+                                        arrow_bitmap,
+                                        n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_int16_array);
+  return GARROW_INT16_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_int16_array_get_value:
  * @array: A #GArrowInt16Array.
  * @i: The index of the target value.
@@ -576,6 +724,39 @@ garrow_uint16_array_class_init(GArrowUInt16ArrayClass *klass)
 }
 
 /**
+ * garrow_uint16_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowUInt16Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowUInt16Array *
+garrow_uint16_array_new(gint64 length,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_uint16_array =
+    std::make_shared<arrow::UInt16Array>(length,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_uint16_array);
+  return GARROW_UINT16_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_uint16_array_get_value:
  * @array: A #GArrowUInt16Array.
  * @i: The index of the target value.
@@ -606,6 +787,39 @@ garrow_int32_array_class_init(GArrowInt32ArrayClass *klass)
 }
 
 /**
+ * garrow_int32_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowInt32Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowInt32Array *
+garrow_int32_array_new(gint64 length,
+                       GArrowBuffer *data,
+                       GArrowBuffer *null_bitmap,
+                       gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_int32_array =
+    std::make_shared<arrow::Int32Array>(length,
+                                        arrow_data,
+                                        arrow_bitmap,
+                                        n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_int32_array);
+  return GARROW_INT32_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_int32_array_get_value:
  * @array: A #GArrowInt32Array.
  * @i: The index of the target value.
@@ -636,6 +850,39 @@ garrow_uint32_array_class_init(GArrowUInt32ArrayClass *klass)
 }
 
 /**
+ * garrow_uint32_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowUInt32Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowUInt32Array *
+garrow_uint32_array_new(gint64 length,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_uint32_array =
+    std::make_shared<arrow::UInt32Array>(length,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_uint32_array);
+  return GARROW_UINT32_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_uint32_array_get_value:
  * @array: A #GArrowUInt32Array.
  * @i: The index of the target value.
@@ -666,6 +913,39 @@ garrow_int64_array_class_init(GArrowInt64ArrayClass *klass)
 }
 
 /**
+ * garrow_int64_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowInt64Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowInt64Array *
+garrow_int64_array_new(gint64 length,
+                       GArrowBuffer *data,
+                       GArrowBuffer *null_bitmap,
+                       gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_int64_array =
+    std::make_shared<arrow::Int64Array>(length,
+                                        arrow_data,
+                                        arrow_bitmap,
+                                        n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_int64_array);
+  return GARROW_INT64_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_int64_array_get_value:
  * @array: A #GArrowInt64Array.
  * @i: The index of the target value.
@@ -696,6 +976,39 @@ garrow_uint64_array_class_init(GArrowUInt64ArrayClass *klass)
 }
 
 /**
+ * garrow_uint64_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowUInt64Array.
+ *
+ * Since: 0.4.0
+ */
+GArrowUInt64Array *
+garrow_uint64_array_new(gint64 length,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_uint64_array =
+    std::make_shared<arrow::UInt64Array>(length,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_uint64_array);
+  return GARROW_UINT64_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_uint64_array_get_value:
  * @array: A #GArrowUInt64Array.
  * @i: The index of the target value.
@@ -725,6 +1038,39 @@ garrow_float_array_class_init(GArrowFloatArrayClass *klass)
 }
 
 /**
+ * garrow_float_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowFloatArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowFloatArray *
+garrow_float_array_new(gint64 length,
+                       GArrowBuffer *data,
+                       GArrowBuffer *null_bitmap,
+                       gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_float_array =
+    std::make_shared<arrow::FloatArray>(length,
+                                        arrow_data,
+                                        arrow_bitmap,
+                                        n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_float_array);
+  return GARROW_FLOAT_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_float_array_get_value:
  * @array: A #GArrowFloatArray.
  * @i: The index of the target value.
@@ -755,6 +1101,39 @@ garrow_double_array_class_init(GArrowDoubleArrayClass *klass)
 }
 
 /**
+ * garrow_double_array_new:
+ * @length: The number of elements.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowDoubleArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowDoubleArray *
+garrow_double_array_new(gint64 length,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_double_array =
+    std::make_shared<arrow::DoubleArray>(length,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_double_array);
+  return GARROW_DOUBLE_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_double_array_get_value:
  * @array: A #GArrowDoubleArray.
  * @i: The index of the target value.
@@ -785,6 +1164,43 @@ garrow_binary_array_class_init(GArrowBinaryArrayClass *klass)
 }
 
 /**
+ * garrow_binary_array_new:
+ * @length: The number of elements.
+ * @value_offsets: The value offsets of @data in Arrow format.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowBinaryArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowBinaryArray *
+garrow_binary_array_new(gint64 length,
+                        GArrowBuffer *value_offsets,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_value_offsets = garrow_buffer_get_raw(value_offsets);
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_binary_array =
+    std::make_shared<arrow::BinaryArray>(length,
+                                         arrow_value_offsets,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_binary_array);
+  return GARROW_BINARY_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_binary_array_get_value:
  * @array: A #GArrowBinaryArray.
  * @i: The index of the target value.
@@ -836,6 +1252,43 @@ garrow_string_array_class_init(GArrowStringArrayClass *klass)
 }
 
 /**
+ * garrow_string_array_new:
+ * @length: The number of elements.
+ * @value_offsets: The value offsets of @data in Arrow format.
+ * @data: The binary data in Arrow format of the array.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowStringArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowStringArray *
+garrow_string_array_new(gint64 length,
+                        GArrowBuffer *value_offsets,
+                        GArrowBuffer *data,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_value_offsets = garrow_buffer_get_raw(value_offsets);
+  const auto arrow_data = garrow_buffer_get_raw(data);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_string_array =
+    std::make_shared<arrow::StringArray>(length,
+                                         arrow_value_offsets,
+                                         arrow_data,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_string_array);
+  return GARROW_STRING_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_string_array_get_string:
  * @array: A #GArrowStringArray.
  * @i: The index of the target value.
@@ -871,6 +1324,45 @@ garrow_list_array_class_init(GArrowListArrayClass *klass)
 }
 
 /**
+ * garrow_list_array_new:
+ * @length: The number of elements.
+ * @value_offsets: The offsets of @values in Arrow format.
+ * @values: The values as #GArrowArray.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowListArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowListArray *
+garrow_list_array_new(gint64 length,
+                      GArrowBuffer *value_offsets,
+                      GArrowArray *values,
+                      GArrowBuffer *null_bitmap,
+                      gint64 n_nulls)
+{
+  const auto arrow_value_offsets = garrow_buffer_get_raw(value_offsets);
+  const auto arrow_values = garrow_array_get_raw(values);
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_data_type = arrow::list(arrow_values->type());
+  auto arrow_list_array =
+    std::make_shared<arrow::ListArray>(arrow_data_type,
+                                       length,
+                                       arrow_value_offsets,
+                                       arrow_values,
+                                       arrow_bitmap,
+                                       n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_list_array);
+  return GARROW_LIST_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_list_array_get_value_type:
  * @array: A #GArrowListArray.
  *
@@ -922,6 +1414,48 @@ garrow_struct_array_class_init(GArrowStructArrayClass *klass)
 }
 
 /**
+ * garrow_struct_array_new:
+ * @data_type: The data type of the struct.
+ * @length: The number of elements.
+ * @children: (element-type GArrowArray): The arrays for each field
+ *   as #GList of #GArrowArray.
+ * @null_bitmap: (nullable): The bitmap that shows null elements. The
+ *   N-th element is null when the N-th bit is 0, not null otherwise.
+ *   If the array has no null elements, the bitmap must be %NULL and
+ *   @n_nulls is 0.
+ * @n_nulls: The number of null elements. If -1 is specified, the
+ *   number of nulls are computed from @null_bitmap.
+ *
+ * Returns: A newly created #GArrowStructArray.
+ *
+ * Since: 0.4.0
+ */
+GArrowStructArray *
+garrow_struct_array_new(GArrowDataType *data_type,
+                        gint64 length,
+                        GList *children,
+                        GArrowBuffer *null_bitmap,
+                        gint64 n_nulls)
+{
+  const auto arrow_data_type = garrow_data_type_get_raw(data_type);
+  std::vector<std::shared_ptr<arrow::Array>> arrow_children;
+  for (GList *node = children; node; node = node->next) {
+    GArrowArray *child = GARROW_ARRAY(node->data);
+    arrow_children.push_back(garrow_array_get_raw(child));
+  }
+  const auto arrow_bitmap = garrow_buffer_get_raw(null_bitmap);
+  auto arrow_struct_array =
+    std::make_shared<arrow::StructArray>(arrow_data_type,
+                                         length,
+                                         arrow_children,
+                                         arrow_bitmap,
+                                         n_nulls);
+  auto arrow_array =
+    std::static_pointer_cast<arrow::Array>(arrow_struct_array);
+  return GARROW_STRUCT_ARRAY(garrow_array_new_raw(&arrow_array));
+}
+
+/**
  * garrow_struct_array_get_field
  * @array: A #GArrowStructArray.
  * @i: The index of the field in the struct.

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/arrow-glib/array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/array.h b/c_glib/arrow-glib/array.h
index f750ee1..c4efeaf 100644
--- a/c_glib/arrow-glib/array.h
+++ b/c_glib/arrow-glib/array.h
@@ -211,6 +211,12 @@ struct _GArrowBooleanArrayClass
 };
 
 GType          garrow_boolean_array_get_type  (void) G_GNUC_CONST;
+
+GArrowBooleanArray *garrow_boolean_array_new(gint64 length,
+                                             GArrowBuffer *data,
+                                             GArrowBuffer *null_bitmap,
+                                             gint64 n_nulls);
+
 gboolean       garrow_boolean_array_get_value (GArrowBooleanArray *array,
                                                gint64 i);
 
@@ -257,6 +263,11 @@ struct _GArrowInt8ArrayClass
 
 GType garrow_int8_array_get_type(void) G_GNUC_CONST;
 
+GArrowInt8Array *garrow_int8_array_new(gint64 length,
+                                       GArrowBuffer *data,
+                                       GArrowBuffer *null_bitmap,
+                                       gint64 n_nulls);
+
 gint8 garrow_int8_array_get_value(GArrowInt8Array *array,
                                   gint64 i);
 
@@ -303,6 +314,11 @@ struct _GArrowUInt8ArrayClass
 
 GType garrow_uint8_array_get_type(void) G_GNUC_CONST;
 
+GArrowUInt8Array *garrow_uint8_array_new(gint64 length,
+                                         GArrowBuffer *data,
+                                         GArrowBuffer *null_bitmap,
+                                         gint64 n_nulls);
+
 guint8 garrow_uint8_array_get_value(GArrowUInt8Array *array,
                                     gint64 i);
 
@@ -349,6 +365,11 @@ struct _GArrowInt16ArrayClass
 
 GType garrow_int16_array_get_type(void) G_GNUC_CONST;
 
+GArrowInt16Array *garrow_int16_array_new(gint64 length,
+                                         GArrowBuffer *data,
+                                         GArrowBuffer *null_bitmap,
+                                         gint64 n_nulls);
+
 gint16 garrow_int16_array_get_value(GArrowInt16Array *array,
                                     gint64 i);
 
@@ -395,6 +416,11 @@ struct _GArrowUInt16ArrayClass
 
 GType garrow_uint16_array_get_type(void) G_GNUC_CONST;
 
+GArrowUInt16Array *garrow_uint16_array_new(gint64 length,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 guint16 garrow_uint16_array_get_value(GArrowUInt16Array *array,
                                       gint64 i);
 
@@ -441,6 +467,11 @@ struct _GArrowInt32ArrayClass
 
 GType garrow_int32_array_get_type(void) G_GNUC_CONST;
 
+GArrowInt32Array *garrow_int32_array_new(gint64 length,
+                                         GArrowBuffer *data,
+                                         GArrowBuffer *null_bitmap,
+                                         gint64 n_nulls);
+
 gint32 garrow_int32_array_get_value(GArrowInt32Array *array,
                                     gint64 i);
 
@@ -487,6 +518,11 @@ struct _GArrowUInt32ArrayClass
 
 GType garrow_uint32_array_get_type(void) G_GNUC_CONST;
 
+GArrowUInt32Array *garrow_uint32_array_new(gint64 length,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 guint32 garrow_uint32_array_get_value(GArrowUInt32Array *array,
                                       gint64 i);
 
@@ -533,6 +569,11 @@ struct _GArrowInt64ArrayClass
 
 GType garrow_int64_array_get_type(void) G_GNUC_CONST;
 
+GArrowInt64Array *garrow_int64_array_new(gint64 length,
+                                         GArrowBuffer *data,
+                                         GArrowBuffer *null_bitmap,
+                                         gint64 n_nulls);
+
 gint64 garrow_int64_array_get_value(GArrowInt64Array *array,
                                     gint64 i);
 
@@ -579,6 +620,11 @@ struct _GArrowUInt64ArrayClass
 
 GType garrow_uint64_array_get_type(void) G_GNUC_CONST;
 
+GArrowUInt64Array *garrow_uint64_array_new(gint64 length,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 guint64 garrow_uint64_array_get_value(GArrowUInt64Array *array,
                                       gint64 i);
 
@@ -625,6 +671,11 @@ struct _GArrowFloatArrayClass
 
 GType garrow_float_array_get_type(void) G_GNUC_CONST;
 
+GArrowFloatArray *garrow_float_array_new(gint64 length,
+                                         GArrowBuffer *data,
+                                         GArrowBuffer *null_bitmap,
+                                         gint64 n_nulls);
+
 gfloat garrow_float_array_get_value(GArrowFloatArray *array,
                                     gint64 i);
 
@@ -671,6 +722,11 @@ struct _GArrowDoubleArrayClass
 
 GType garrow_double_array_get_type(void) G_GNUC_CONST;
 
+GArrowDoubleArray *garrow_double_array_new(gint64 length,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 gdouble garrow_double_array_get_value(GArrowDoubleArray *array,
                                       gint64 i);
 
@@ -717,6 +773,12 @@ struct _GArrowBinaryArrayClass
 
 GType garrow_binary_array_get_type(void) G_GNUC_CONST;
 
+GArrowBinaryArray *garrow_binary_array_new(gint64 length,
+                                           GArrowBuffer *value_offsets,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 GBytes *garrow_binary_array_get_value(GArrowBinaryArray *array,
                                       gint64 i);
 GArrowBuffer *garrow_binary_array_get_buffer(GArrowBinaryArray *array);
@@ -763,6 +825,12 @@ struct _GArrowStringArrayClass
 
 GType garrow_string_array_get_type(void) G_GNUC_CONST;
 
+GArrowStringArray *garrow_string_array_new(gint64 length,
+                                           GArrowBuffer *value_offsets,
+                                           GArrowBuffer *data,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 gchar *garrow_string_array_get_string(GArrowStringArray *array,
                                       gint64 i);
 
@@ -809,6 +877,12 @@ struct _GArrowListArrayClass
 
 GType garrow_list_array_get_type(void) G_GNUC_CONST;
 
+GArrowListArray *garrow_list_array_new(gint64 length,
+                                       GArrowBuffer *value_offsets,
+                                       GArrowArray *values,
+                                       GArrowBuffer *null_bitmap,
+                                       gint64 n_nulls);
+
 GArrowDataType *garrow_list_array_get_value_type(GArrowListArray *array);
 GArrowArray *garrow_list_array_get_value(GArrowListArray *array,
                                          gint64 i);
@@ -856,6 +930,12 @@ struct _GArrowStructArrayClass
 
 GType garrow_struct_array_get_type(void) G_GNUC_CONST;
 
+GArrowStructArray *garrow_struct_array_new(GArrowDataType *data_type,
+                                           gint64 length,
+                                           GList *children,
+                                           GArrowBuffer *null_bitmap,
+                                           gint64 n_nulls);
+
 GArrowArray *garrow_struct_array_get_field(GArrowStructArray *array,
                                            gint i);
 GList *garrow_struct_array_get_fields(GArrowStructArray *array);

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/arrow-glib/buffer.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/buffer.cpp b/c_glib/arrow-glib/buffer.cpp
index 0970128..4be8fed 100644
--- a/c_glib/arrow-glib/buffer.cpp
+++ b/c_glib/arrow-glib/buffer.cpp
@@ -504,6 +504,9 @@ garrow_buffer_new_raw(std::shared_ptr<arrow::Buffer> *arrow_buffer)
 std::shared_ptr<arrow::Buffer>
 garrow_buffer_get_raw(GArrowBuffer *buffer)
 {
+  if (!buffer)
+    return nullptr;
+
   auto priv = GARROW_BUFFER_GET_PRIVATE(buffer);
   return priv->buffer;
 }

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/helper/buildable.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/helper/buildable.rb b/c_glib/test/helper/buildable.rb
index 900e180..4120eed 100644
--- a/c_glib/test/helper/buildable.rb
+++ b/c_glib/test/helper/buildable.rb
@@ -61,6 +61,61 @@ module Helper
       build_array(Arrow::DoubleArrayBuilder, values)
     end
 
+    def build_binary_array(values)
+      build_array(Arrow::BinaryArrayBuilder, values)
+    end
+
+    def build_string_array(values)
+      build_array(Arrow::StringArrayBuilder, values)
+    end
+
+    def build_list_array(value_builder_class, values_list)
+      value_builder = value_builder_class.new
+      builder = Arrow::ListArrayBuilder.new(value_builder)
+      values_list.each do |values|
+        if values.nil?
+          builder.append_null
+        else
+          builder.append
+          values.each do |value|
+            if value.nil?
+              value_builder.append_null
+            else
+              value_builder.append(value)
+            end
+          end
+        end
+      end
+      builder.finish
+    end
+
+    def build_struct_array(fields, structs)
+      field_builders = fields.collect do |field|
+        data_type_name = field.data_type.class.name
+        builder_name = data_type_name.gsub(/DataType/, "ArrayBuilder")
+        Arrow.const_get(builder_name).new
+      end
+      data_type = Arrow::StructDataType.new(fields)
+      builder = Arrow::StructArrayBuilder.new(data_type, field_builders)
+      structs.each do |struct|
+        if struct.nil?
+          builder.append_null
+        else
+          builder.append
+          struct.each do |name, value|
+            field_builder_index = fields.index {|field| field.name == name}
+            field_builder = builder.get_field_builder(field_builder_index)
+            if value.nil?
+              field_builder.append_null
+            else
+              field_builder.append(value)
+            end
+          end
+        end
+      end
+      builder.finish
+    end
+
     private
     def build_array(builder_class, values)
       builder = builder_class.new

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-binary-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-binary-array.rb b/c_glib/test/test-binary-array.rb
index ccdf378..9ae122a 100644
--- a/c_glib/test/test-binary-array.rb
+++ b/c_glib/test/test-binary-array.rb
@@ -16,6 +16,19 @@
 # under the License.
 
 class TestBinaryArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    value_offsets = Arrow::Buffer.new([0, 2, 5, 5].pack("l*"))
+    data = Arrow::Buffer.new("\x00\x01\x02\x03\x04")
+    assert_equal(build_binary_array(["\x00\x01", "\x02\x03\x04", nil]),
+                 Arrow::BinaryArray.new(3,
+                                        value_offsets,
+                                        data,
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_value
     data = "\x00\x01\x02"
     builder = Arrow::BinaryArrayBuilder.new

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-boolean-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-boolean-array.rb b/c_glib/test/test-boolean-array.rb
index 15df1ed..43b8365 100644
--- a/c_glib/test/test-boolean-array.rb
+++ b/c_glib/test/test-boolean-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestBooleanArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_boolean_array([true, false, nil]),
+                 Arrow::BooleanArray.new(3,
+                                         Arrow::Buffer.new([0b001].pack("C*")),
+                                         Arrow::Buffer.new([0b011].pack("C*")),
+                                         -1))
+  end
+
   def test_buffer
     builder = Arrow::BooleanArrayBuilder.new
     builder.append(true)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-double-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-double-array.rb b/c_glib/test/test-double-array.rb
index c644ac6..935fbe5 100644
--- a/c_glib/test/test-double-array.rb
+++ b/c_glib/test/test-double-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestDoubleArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_double_array([-1.1, 2.2, nil]),
+                 Arrow::DoubleArray.new(3,
+                                        Arrow::Buffer.new([-1.1, 2.2].pack("d*")),
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_buffer
     builder = Arrow::DoubleArrayBuilder.new
     builder.append(-1.1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-float-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-float-array.rb b/c_glib/test/test-float-array.rb
index 84876f9..fcac902 100644
--- a/c_glib/test/test-float-array.rb
+++ b/c_glib/test/test-float-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestFloatArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_float_array([-1.1, 2.2, nil]),
+                 Arrow::FloatArray.new(3,
+                                       Arrow::Buffer.new([-1.1, 2.2].pack("f*")),
+                                       Arrow::Buffer.new([0b011].pack("C*")),
+                                       -1))
+  end
+
   def test_buffer
     builder = Arrow::FloatArrayBuilder.new
     builder.append(-1.1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-int16-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-int16-array.rb b/c_glib/test/test-int16-array.rb
index 4b30ddd..6bc7f88 100644
--- a/c_glib/test/test-int16-array.rb
+++ b/c_glib/test/test-int16-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestInt16Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_int16_array([-1, 2, nil]),
+                 Arrow::Int16Array.new(3,
+                                       Arrow::Buffer.new([-1, 2].pack("s*")),
+                                       Arrow::Buffer.new([0b011].pack("C*")),
+                                       -1))
+  end
+
   def test_buffer
     builder = Arrow::Int16ArrayBuilder.new
     builder.append(-1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-int32-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-int32-array.rb b/c_glib/test/test-int32-array.rb
index 90cf022..0b68273 100644
--- a/c_glib/test/test-int32-array.rb
+++ b/c_glib/test/test-int32-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestInt32Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_int32_array([-1, 2, nil]),
+                 Arrow::Int32Array.new(3,
+                                       Arrow::Buffer.new([-1, 2].pack("l*")),
+                                       Arrow::Buffer.new([0b011].pack("C*")),
+                                       -1))
+  end
+
   def test_buffer
     builder = Arrow::Int32ArrayBuilder.new
     builder.append(-1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-int64-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-int64-array.rb b/c_glib/test/test-int64-array.rb
index d302201..c217434 100644
--- a/c_glib/test/test-int64-array.rb
+++ b/c_glib/test/test-int64-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestInt64Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_int64_array([-1, 2, nil]),
+                 Arrow::Int64Array.new(3,
+                                       Arrow::Buffer.new([-1, 2].pack("q*")),
+                                       Arrow::Buffer.new([0b011].pack("C*")),
+                                       -1))
+  end
+
   def test_buffer
     builder = Arrow::Int64ArrayBuilder.new
     builder.append(-1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-int8-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-int8-array.rb b/c_glib/test/test-int8-array.rb
index 9f28fa7..c7ff216 100644
--- a/c_glib/test/test-int8-array.rb
+++ b/c_glib/test/test-int8-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestInt8Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_int8_array([-1, 2, nil]),
+                 Arrow::Int8Array.new(3,
+                                      Arrow::Buffer.new([-1, 2].pack("c*")),
+                                      Arrow::Buffer.new([0b011].pack("C*")),
+                                      -1))
+  end
+
   def test_buffer
     builder = Arrow::Int8ArrayBuilder.new
     builder.append(-1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-list-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-list-array.rb b/c_glib/test/test-list-array.rb
index 34177de..8e481e8 100644
--- a/c_glib/test/test-list-array.rb
+++ b/c_glib/test/test-list-array.rb
@@ -16,6 +16,21 @@
 # under the License.
 
 class TestListArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    value_offsets = Arrow::Buffer.new([0, 2, 5, 5].pack("l*"))
+    data = Arrow::Buffer.new([1, 2, 3, 4, 5].pack("c*"))
+    values = Arrow::Int8Array.new(5, data, nil, 0)
+    assert_equal(build_list_array(Arrow::Int8ArrayBuilder,
+                                  [[1, 2], [3, 4, 5], nil]),
+                 Arrow::ListArray.new(3,
+                                      value_offsets,
+                                      values,
+                                      Arrow::Buffer.new([0b011].pack("C*")),
+                                      -1))
+  end
+
   def test_value
     builder = Arrow::ListArrayBuilder.new(Arrow::Int8ArrayBuilder.new)
     value_builder = builder.value_builder

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-string-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-string-array.rb b/c_glib/test/test-string-array.rb
index a076c22..a9edb0a 100644
--- a/c_glib/test/test-string-array.rb
+++ b/c_glib/test/test-string-array.rb
@@ -16,6 +16,19 @@
 # under the License.
 
 class TestStringArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    value_offsets = Arrow::Buffer.new([0, 5, 11, 11].pack("l*"))
+    data = Arrow::Buffer.new("HelloWorld!")
+    assert_equal(build_string_array(["Hello", "World!", nil]),
+                 Arrow::StringArray.new(3,
+                                        value_offsets,
+                                        data,
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_value
     builder = Arrow::StringArrayBuilder.new
     builder.append("Hello")

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-struct-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-struct-array.rb b/c_glib/test/test-struct-array.rb
index cf450f5..ef0bc71 100644
--- a/c_glib/test/test-struct-array.rb
+++ b/c_glib/test/test-struct-array.rb
@@ -16,6 +16,39 @@
 # under the License.
 
 class TestStructArray < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    fields = [
+      Arrow::Field.new("score", Arrow::Int8DataType.new),
+      Arrow::Field.new("enabled", Arrow::BooleanDataType.new),
+    ]
+    structs = [
+      {
+        "score" => -29,
+        "enabled" => true,
+      },
+      {
+        "score" => 2,
+        "enabled" => false,
+      },
+      nil,
+    ]
+    struct_array1 = build_struct_array(fields, structs)
+
+    data_type = Arrow::StructDataType.new(fields)
+    children = [
+      Arrow::Int8Array.new(2, Arrow::Buffer.new([-29, 2].pack("C*")), nil, 0),
+      Arrow::BooleanArray.new(2, Arrow::Buffer.new([0b01].pack("C*")), nil, 0),
+    ]
+    assert_equal(struct_array1,
+                 Arrow::StructArray.new(data_type,
+                                        3,
+                                        children,
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_fields
     fields = [
       Arrow::Field.new("score", Arrow::Int8DataType.new),

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-uint16-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-uint16-array.rb b/c_glib/test/test-uint16-array.rb
index 82e898e..e3ffa5d 100644
--- a/c_glib/test/test-uint16-array.rb
+++ b/c_glib/test/test-uint16-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestUInt16Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_uint16_array([1, 2, nil]),
+                 Arrow::UInt16Array.new(3,
+                                        Arrow::Buffer.new([1, 2].pack("S*")),
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_buffer
     builder = Arrow::UInt16ArrayBuilder.new
     builder.append(1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-uint32-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-uint32-array.rb b/c_glib/test/test-uint32-array.rb
index c8be06f..95aee79 100644
--- a/c_glib/test/test-uint32-array.rb
+++ b/c_glib/test/test-uint32-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestUInt32Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_uint32_array([1, 2, nil]),
+                 Arrow::UInt32Array.new(3,
+                                        Arrow::Buffer.new([1, 2].pack("L*")),
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_buffer
     builder = Arrow::UInt32ArrayBuilder.new
     builder.append(1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-uint64-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-uint64-array.rb b/c_glib/test/test-uint64-array.rb
index 03082f3..7d91854 100644
--- a/c_glib/test/test-uint64-array.rb
+++ b/c_glib/test/test-uint64-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestUInt64Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_uint64_array([1, 2, nil]),
+                 Arrow::UInt64Array.new(3,
+                                        Arrow::Buffer.new([1, 2].pack("Q*")),
+                                        Arrow::Buffer.new([0b011].pack("C*")),
+                                        -1))
+  end
+
   def test_buffer
     builder = Arrow::UInt64ArrayBuilder.new
     builder.append(1)

http://git-wip-us.apache.org/repos/asf/arrow/blob/3d198317/c_glib/test/test-uint8-array.rb
----------------------------------------------------------------------
diff --git a/c_glib/test/test-uint8-array.rb b/c_glib/test/test-uint8-array.rb
index d7464e3..9c93abe 100644
--- a/c_glib/test/test-uint8-array.rb
+++ b/c_glib/test/test-uint8-array.rb
@@ -16,6 +16,16 @@
 # under the License.
 
 class TestUInt8Array < Test::Unit::TestCase
+  include Helper::Buildable
+
+  def test_new
+    assert_equal(build_uint8_array([1, 2, nil]),
+                 Arrow::UInt8Array.new(3,
+                                       Arrow::Buffer.new([1, 2].pack("C*")),
+                                       Arrow::Buffer.new([0b011].pack("C*")),
+                                       -1))
+  end
+
   def test_buffer
     builder = Arrow::UInt8ArrayBuilder.new
     builder.append(1)


Mime
View raw message