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/04/11 03:34:20 UTC

[arrow] branch master updated: ARROW-2407: [GLib] Add garrow_string_array_builder_append_values()

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 1ee7d11  ARROW-2407: [GLib] Add garrow_string_array_builder_append_values()
1ee7d11 is described below

commit 1ee7d11f562210474921ba07f591fd2df800c757
Author: Kouhei Sutou <ko...@clear-code.com>
AuthorDate: Wed Apr 11 12:33:45 2018 +0900

    ARROW-2407: [GLib] Add garrow_string_array_builder_append_values()
    
    Author: Kouhei Sutou <ko...@clear-code.com>
    
    Closes #1845 from kou/glib-string-array-builder-append and squashes the following commits:
    
    5bc6e8dd [Kouhei Sutou] [GLib] Use C string version for performance
    662cc18d [Kouhei Sutou] [GLib] Add a missing word
    cea3f0ba [Kouhei Sutou] [GLib] Add garrow_string_array_builder_append_values()
---
 c_glib/arrow-glib/array-builder.cpp | 133 ++++++++++++++++++++++++++----------
 c_glib/arrow-glib/array-builder.h   |   6 ++
 c_glib/test/test-array-builder.rb   |  30 ++++++++
 3 files changed, 133 insertions(+), 36 deletions(-)

diff --git a/c_glib/arrow-glib/array-builder.cpp b/c_glib/arrow-glib/array-builder.cpp
index 7625bcd..f129998 100644
--- a/c_glib/arrow-glib/array-builder.cpp
+++ b/c_glib/arrow-glib/array-builder.cpp
@@ -443,7 +443,7 @@ garrow_boolean_array_builder_append(GArrowBooleanArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -495,7 +495,7 @@ garrow_boolean_array_builder_append_null(GArrowBooleanArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -580,7 +580,7 @@ garrow_int_array_builder_append(GArrowIntArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -630,7 +630,7 @@ garrow_int_array_builder_append_null(GArrowIntArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -715,7 +715,7 @@ garrow_uint_array_builder_append(GArrowUIntArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -765,7 +765,7 @@ garrow_uint_array_builder_append_null(GArrowUIntArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -845,7 +845,7 @@ garrow_int8_array_builder_append(GArrowInt8ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -893,7 +893,7 @@ garrow_int8_array_builder_append_null(GArrowInt8ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -973,7 +973,7 @@ garrow_uint8_array_builder_append(GArrowUInt8ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1021,7 +1021,7 @@ garrow_uint8_array_builder_append_null(GArrowUInt8ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1101,7 +1101,7 @@ garrow_int16_array_builder_append(GArrowInt16ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1149,7 +1149,7 @@ garrow_int16_array_builder_append_null(GArrowInt16ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1229,7 +1229,7 @@ garrow_uint16_array_builder_append(GArrowUInt16ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1277,7 +1277,7 @@ garrow_uint16_array_builder_append_null(GArrowUInt16ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1357,7 +1357,7 @@ garrow_int32_array_builder_append(GArrowInt32ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1405,7 +1405,7 @@ garrow_int32_array_builder_append_null(GArrowInt32ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1485,7 +1485,7 @@ garrow_uint32_array_builder_append(GArrowUInt32ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1533,7 +1533,7 @@ garrow_uint32_array_builder_append_null(GArrowUInt32ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1613,7 +1613,7 @@ garrow_int64_array_builder_append(GArrowInt64ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1661,7 +1661,7 @@ garrow_int64_array_builder_append_null(GArrowInt64ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1741,7 +1741,7 @@ garrow_uint64_array_builder_append(GArrowUInt64ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1789,7 +1789,7 @@ garrow_uint64_array_builder_append_null(GArrowUInt64ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1869,7 +1869,7 @@ garrow_float_array_builder_append(GArrowFloatArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1917,7 +1917,7 @@ garrow_float_array_builder_append_null(GArrowFloatArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -1997,7 +1997,7 @@ garrow_double_array_builder_append(GArrowDoubleArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2045,7 +2045,7 @@ garrow_double_array_builder_append_null(GArrowDoubleArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2184,6 +2184,67 @@ garrow_string_array_builder_append(GArrowStringArrayBuilder *builder,
   return garrow_error_check(error, status, "[string-array-builder][append]");
 }
 
+/**
+ * garrow_string_array_builder_append_values:
+ * @builder: A #GArrowStringArrayBuilder.
+ * @values: (array length=values_length): The array of
+ *   strings.
+ * @values_length: The length of `values`.
+ * @is_valids: (nullable) (array length=is_valids_length): The array of
+ *   boolean that shows whether the Nth value is valid or not. If the
+ *   Nth `is_valids` is %TRUE, the Nth `values` is valid value. Otherwise
+ *   the Nth value is null value.
+ * @is_valids_length: The length of `is_valids`.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Append multiple values at once. It's more efficient than multiple
+ * `append()` and `append_null()` calls.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * Since: 0.10.0
+ */
+gboolean
+garrow_string_array_builder_append_values(GArrowStringArrayBuilder *builder,
+                                          const gchar **values,
+                                          gint64 values_length,
+                                          const gboolean *is_valids,
+                                          gint64 is_valids_length,
+                                          GError **error)
+{
+  const char *context = "[string-array-builder][append-values]";
+  auto arrow_builder =
+    static_cast<arrow::StringBuilder *>(
+      garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)));
+
+  if (is_valids_length > 0) {
+    if (values_length != is_valids_length) {
+      g_set_error(error,
+                  GARROW_ERROR,
+                  GARROW_ERROR_INVALID,
+                  "%s: values length and is_valids length must be equal: "
+                  "<%" G_GINT64_FORMAT "> != "
+                  "<%" G_GINT64_FORMAT ">",
+                  context,
+                  values_length,
+                  is_valids_length);
+      return FALSE;
+    }
+  }
+
+  if (is_valids_length > 0) {
+    uint8_t valid_bytes[is_valids_length];
+    for (gint64 i = 0; i < values_length; ++i) {
+      valid_bytes[i] = is_valids[i];
+    }
+    auto status = arrow_builder->Append(values, values_length, valid_bytes);
+    return garrow_error_check(error, status, context);
+  } else {
+    auto status = arrow_builder->Append(values, values_length, nullptr);
+    return garrow_error_check(error, status, context);
+  }
+}
+
 
 G_DEFINE_TYPE(GArrowDate32ArrayBuilder,
               garrow_date32_array_builder,
@@ -2250,7 +2311,7 @@ garrow_date32_array_builder_append(GArrowDate32ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2300,7 +2361,7 @@ garrow_date32_array_builder_append_null(GArrowDate32ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2385,7 +2446,7 @@ garrow_date64_array_builder_append(GArrowDate64ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2435,7 +2496,7 @@ garrow_date64_array_builder_append_null(GArrowDate64ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2522,7 +2583,7 @@ garrow_timestamp_array_builder_append(GArrowTimestampArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2572,7 +2633,7 @@ garrow_timestamp_array_builder_append_null(GArrowTimestampArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2659,7 +2720,7 @@ garrow_time32_array_builder_append(GArrowTime32ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2709,7 +2770,7 @@ garrow_time32_array_builder_append_null(GArrowTime32ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2796,7 +2857,7 @@ garrow_time64_array_builder_append(GArrowTime64ArrayBuilder *builder,
  * @is_valids_length: The length of `is_valids`.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple values at once. It's efficient than multiple
+ * Append multiple values at once. It's more efficient than multiple
  * `append()` and `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
@@ -2846,7 +2907,7 @@ garrow_time64_array_builder_append_null(GArrowTime64ArrayBuilder *builder,
  * @n: The number of null values to be appended.
  * @error: (nullable): Return location for a #GError or %NULL.
  *
- * Append multiple nulls at once. It's efficient than multiple
+ * Append multiple nulls at once. It's more efficient than multiple
  * `append_null()` calls.
  *
  * Returns: %TRUE on success, %FALSE if there was an error.
diff --git a/c_glib/arrow-glib/array-builder.h b/c_glib/arrow-glib/array-builder.h
index ea95f31..284a78f 100644
--- a/c_glib/arrow-glib/array-builder.h
+++ b/c_glib/arrow-glib/array-builder.h
@@ -893,6 +893,12 @@ GArrowStringArrayBuilder *garrow_string_array_builder_new(void);
 gboolean garrow_string_array_builder_append(GArrowStringArrayBuilder *builder,
                                             const gchar *value,
                                             GError **error);
+gboolean garrow_string_array_builder_append_values(GArrowStringArrayBuilder *builder,
+                                                   const gchar **values,
+                                                   gint64 values_length,
+                                                   const gboolean *is_valids,
+                                                   gint64 is_valids_length,
+                                                   GError **error);
 
 
 #define GARROW_TYPE_DATE32_ARRAY_BUILDER        \
diff --git a/c_glib/test/test-array-builder.rb b/c_glib/test/test-array-builder.rb
index a773131..6811102 100644
--- a/c_glib/test/test-array-builder.rb
+++ b/c_glib/test/test-array-builder.rb
@@ -662,4 +662,34 @@ class TestArrayBuilder < Test::Unit::TestCase
       include ArrayBuilderAppendNullsTests
     end
   end
+
+  sub_test_case("StringArrayBuilder") do
+    def create_builder
+      Arrow::StringArrayBuilder.new
+    end
+
+    def value_data_type
+      Arrow::StringDataType.new
+    end
+
+    def builder_class_name
+      "string-array-builder"
+    end
+
+    def sample_values
+      [
+        "hello",
+        "world!!",
+        "",
+      ]
+    end
+
+    sub_test_case("value type") do
+      include ArrayBuilderValueTypeTests
+    end
+
+    sub_test_case("#append_values") do
+      include ArrayBuilderAppendValuesTests
+    end
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
kou@apache.org.