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 2022/07/22 02:43:03 UTC

[arrow] branch master updated: ARROW-17157: [GLib][Ruby][Flight] Add support for headers to GAFlightCallOptions (#13671)

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 38b956f4da ARROW-17157: [GLib][Ruby][Flight] Add support for headers to GAFlightCallOptions (#13671)
38b956f4da is described below

commit 38b956f4da174c1e72607159c9a98f9dbacf6f75
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Fri Jul 22 11:42:56 2022 +0900

    ARROW-17157: [GLib][Ruby][Flight] Add support for headers to GAFlightCallOptions (#13671)
    
    Authored-by: Sutou Kouhei <ko...@clear-code.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-cuda-glib/meson.build                 |  1 +
 c_glib/arrow-dataset-glib/meson.build              |  1 +
 c_glib/arrow-flight-glib/client.cpp                | 57 ++++++++++++++++++++++
 c_glib/arrow-flight-glib/client.h                  | 14 ++++++
 c_glib/arrow-flight-glib/common.cpp                | 16 ++++++
 c_glib/arrow-flight-glib/common.h                  |  5 ++
 c_glib/arrow-flight-glib/meson.build               |  1 +
 c_glib/arrow-flight-sql-glib/meson.build           |  1 +
 c_glib/arrow-flight-sql-glib/server.h              |  4 +-
 c_glib/arrow-glib/meson.build                      |  1 +
 c_glib/gandiva-glib/meson.build                    |  1 +
 c_glib/meson.build                                 |  1 +
 c_glib/parquet-glib/meson.build                    |  1 +
 c_glib/plasma-glib/meson.build                     |  1 +
 .../test/flight/test-call-options.rb               | 42 ++++++++++------
 .../lib/arrow-flight/call-options.rb               | 18 +++++++
 ruby/red-arrow-flight/test/test-call-options.rb    | 53 ++++++++++++++++++++
 17 files changed, 201 insertions(+), 17 deletions(-)

diff --git a/c_glib/arrow-cuda-glib/meson.build b/c_glib/arrow-cuda-glib/meson.build
index f49199d3ac..fd9e8f0e7b 100644
--- a/c_glib/arrow-cuda-glib/meson.build
+++ b/c_glib/arrow-cuda-glib/meson.build
@@ -71,6 +71,7 @@ if have_gi
                        dependencies: gir_dependencies,
                        export_packages: 'arrow-cuda-glib',
                        extra_args: gir_extra_args,
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'arrow-cuda-glib/arrow-cuda-glib.h',
                        identifier_prefix: 'GArrowCUDA',
                        includes: [
diff --git a/c_glib/arrow-dataset-glib/meson.build b/c_glib/arrow-dataset-glib/meson.build
index 3d4521678d..afdbbd79a1 100644
--- a/c_glib/arrow-dataset-glib/meson.build
+++ b/c_glib/arrow-dataset-glib/meson.build
@@ -95,6 +95,7 @@ if have_gi
                          '--warn-all',
                          '--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
                        ],
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'arrow-dataset-glib/arrow-dataset-glib.h',
                        identifier_prefix: 'GADataset',
                        includes: [
diff --git a/c_glib/arrow-flight-glib/client.cpp b/c_glib/arrow-flight-glib/client.cpp
index 8710433bd0..862cfe093e 100644
--- a/c_glib/arrow-flight-glib/client.cpp
+++ b/c_glib/arrow-flight-glib/client.cpp
@@ -108,6 +108,63 @@ gaflight_call_options_new(void)
     g_object_new(GAFLIGHT_TYPE_CALL_OPTIONS, NULL));
 }
 
+/**
+ * gaflight_call_options_add_header:
+ * @options: A #GAFlightCallOptions.
+ * @name: A header name.
+ * @value: A header value.
+ *
+ * Add a header.
+ *
+ * Since: 9.0.0
+ */
+void
+gaflight_call_options_add_header(GAFlightCallOptions *options,
+                                 const gchar *name,
+                                 const gchar *value)
+{
+  auto flight_options = gaflight_call_options_get_raw(options);
+  flight_options->headers.emplace_back(name, value);
+}
+
+/**
+ * gaflight_call_options_clear_headers:
+ * @options: A #GAFlightCallOptions.
+ *
+ * Clear all headers.
+ *
+ * Since: 9.0.0
+ */
+void
+gaflight_call_options_clear_headers(GAFlightCallOptions *options)
+{
+  auto flight_options = gaflight_call_options_get_raw(options);
+  flight_options->headers.clear();
+}
+
+/**
+ * gaflight_call_options_foreach_header:
+ * @options: A #GAFlightCallOptions.
+ * @func: (scope call): The user's callback function.
+ * @user_data: (closure): Data for @func.
+ *
+ * Iterates over all header in the options.
+ *
+ * Since: 9.0.0
+ */
+void
+gaflight_call_options_foreach_header(GAFlightCallOptions *options,
+                                     GAFlightHeaderFunc func,
+                                     gpointer user_data)
+{
+  auto flight_options = gaflight_call_options_get_raw(options);
+  for (const auto &header : flight_options->headers) {
+    auto &key = header.first;
+    auto &value = header.second;
+    func(key.c_str(), value.c_str(), user_data);
+  }
+}
+
 
 typedef struct GAFlightClientOptionsPrivate_ {
   arrow::flight::FlightClientOptions options;
diff --git a/c_glib/arrow-flight-glib/client.h b/c_glib/arrow-flight-glib/client.h
index d4339a5fed..30ddb0076c 100644
--- a/c_glib/arrow-flight-glib/client.h
+++ b/c_glib/arrow-flight-glib/client.h
@@ -52,6 +52,20 @@ GARROW_AVAILABLE_IN_5_0
 GAFlightCallOptions *
 gaflight_call_options_new(void);
 
+GARROW_AVAILABLE_IN_9_0
+void
+gaflight_call_options_add_header(GAFlightCallOptions *options,
+                                 const gchar *name,
+                                 const gchar *value);
+GARROW_AVAILABLE_IN_9_0
+void
+gaflight_call_options_clear_headers(GAFlightCallOptions *options);
+GARROW_AVAILABLE_IN_9_0
+void
+gaflight_call_options_foreach_header(GAFlightCallOptions *options,
+                                     GAFlightHeaderFunc func,
+                                     gpointer user_data);
+
 
 #define GAFLIGHT_TYPE_CLIENT_OPTIONS (gaflight_client_options_get_type())
 G_DECLARE_DERIVABLE_TYPE(GAFlightClientOptions,
diff --git a/c_glib/arrow-flight-glib/common.cpp b/c_glib/arrow-flight-glib/common.cpp
index 0365096af3..fd28b77f04 100644
--- a/c_glib/arrow-flight-glib/common.cpp
+++ b/c_glib/arrow-flight-glib/common.cpp
@@ -53,6 +53,22 @@ G_BEGIN_DECLS
  * Since: 5.0.0
  */
 
+
+/**
+ * GAFlightHeaderFunc:
+ * @name: A header name.
+ * @value: The value corresponding to the name.
+ * @user_data: User data passed to gaflight_call_options_foreach_header()
+ *   and so on.
+ *
+ * It is called with each header name/value pair, together with the
+ * @user_data parameter which is passed to
+ * gaflight_call_options_foreach_header() and so on.
+ *
+ * Since: 9.0.0
+ */
+
+
 typedef struct GAFlightCriteriaPrivate_ {
   arrow::flight::Criteria criteria;
   GBytes *expression;
diff --git a/c_glib/arrow-flight-glib/common.h b/c_glib/arrow-flight-glib/common.h
index 368fb665b4..469ff4097f 100644
--- a/c_glib/arrow-flight-glib/common.h
+++ b/c_glib/arrow-flight-glib/common.h
@@ -24,6 +24,11 @@
 G_BEGIN_DECLS
 
 
+typedef void(*GAFlightHeaderFunc)(const gchar *name,
+                                  const gchar *value,
+                                  gpointer  user_data);
+
+
 #define GAFLIGHT_TYPE_CRITERIA (gaflight_criteria_get_type())
 G_DECLARE_DERIVABLE_TYPE(GAFlightCriteria,
                          gaflight_criteria,
diff --git a/c_glib/arrow-flight-glib/meson.build b/c_glib/arrow-flight-glib/meson.build
index 5d57e292e1..3eb3177a52 100644
--- a/c_glib/arrow-flight-glib/meson.build
+++ b/c_glib/arrow-flight-glib/meson.build
@@ -72,6 +72,7 @@ if have_gi
                          '--warn-all',
                          '--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
                        ],
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'arrow-flight-glib/arrow-flight-glib.h',
                        identifier_prefix: 'GAFlight',
                        includes: [
diff --git a/c_glib/arrow-flight-sql-glib/meson.build b/c_glib/arrow-flight-sql-glib/meson.build
index d1c7957f56..21cec3f0d1 100644
--- a/c_glib/arrow-flight-sql-glib/meson.build
+++ b/c_glib/arrow-flight-sql-glib/meson.build
@@ -73,6 +73,7 @@ if have_gi
                          '--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
                          '--include-uninstalled=./arrow-flight-glib/ArrowFlight-1.0.gir',
                        ],
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'arrow-flight-sql-glib/arrow-flight-sql-glib.h',
                        identifier_prefix: 'GAFlightSQL',
                        includes: [
diff --git a/c_glib/arrow-flight-sql-glib/server.h b/c_glib/arrow-flight-sql-glib/server.h
index 9bd57c746f..bc58f42aa2 100644
--- a/c_glib/arrow-flight-sql-glib/server.h
+++ b/c_glib/arrow-flight-sql-glib/server.h
@@ -103,7 +103,7 @@ struct _GAFlightSQLServerClass
   GAFlightDataStream *(*do_get_statement)(
     GAFlightSQLServer *server,
     GAFlightServerCallContext *context,
-    GAFlightSQLStatementQueryTicket *command,
+    GAFlightSQLStatementQueryTicket *ticket,
     GError **error);
 };
 
@@ -120,7 +120,7 @@ GAFlightDataStream *
 gaflightsql_server_do_get_statement(
   GAFlightSQLServer *server,
   GAFlightServerCallContext *context,
-  GAFlightSQLStatementQueryTicket *command,
+  GAFlightSQLStatementQueryTicket *ticket,
   GError **error);
 
 G_END_DECLS
diff --git a/c_glib/arrow-glib/meson.build b/c_glib/arrow-glib/meson.build
index 82ae52691d..c7233d8b18 100644
--- a/c_glib/arrow-glib/meson.build
+++ b/c_glib/arrow-glib/meson.build
@@ -277,6 +277,7 @@ if have_gi
                                       extra_args: [
                                         '--warn-all',
                                       ],
+                                      fatal_warnings: gi_fatal_warnings,
                                       header: 'arrow-glib/arrow-glib.h',
                                       identifier_prefix: 'GArrow',
                                       includes: [
diff --git a/c_glib/gandiva-glib/meson.build b/c_glib/gandiva-glib/meson.build
index be3cb611ee..c397bd1f9f 100644
--- a/c_glib/gandiva-glib/meson.build
+++ b/c_glib/gandiva-glib/meson.build
@@ -110,6 +110,7 @@ if have_gi
                          '--warn-all',
                          '--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
                        ],
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'gandiva-glib/gandiva-glib.h',
                        identifier_prefix: 'GGandiva',
                        includes: [
diff --git a/c_glib/meson.build b/c_glib/meson.build
index 92fbf3c5a5..14f3a6225b 100644
--- a/c_glib/meson.build
+++ b/c_glib/meson.build
@@ -55,6 +55,7 @@ base_include_directories = [
   include_directories('.')
 ]
 
+gi_fatal_warnings = (build_machine.system() != 'windows')
 have_gi = dependency('gobject-introspection-1.0', required: false).found()
 if have_gi
   pkgconfig_variables += ['girdir=@0@'.format(gir_dir)]
diff --git a/c_glib/parquet-glib/meson.build b/c_glib/parquet-glib/meson.build
index a9a56ab3ef..15a2d56383 100644
--- a/c_glib/parquet-glib/meson.build
+++ b/c_glib/parquet-glib/meson.build
@@ -79,6 +79,7 @@ if have_gi
                          '--warn-all',
                          '--include-uninstalled=./arrow-glib/Arrow-1.0.gir',
                        ],
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'parquet-glib/parquet-glib.h',
                        identifier_prefix: 'GParquet',
                        includes: [
diff --git a/c_glib/plasma-glib/meson.build b/c_glib/plasma-glib/meson.build
index 46083ea811..cf811d42b7 100644
--- a/c_glib/plasma-glib/meson.build
+++ b/c_glib/plasma-glib/meson.build
@@ -108,6 +108,7 @@ if have_gi
                        dependencies: gir_dependencies,
                        export_packages: 'plasma-glib',
                        extra_args: gir_extra_args,
+                       fatal_warnings: gi_fatal_warnings,
                        header: 'plasma-glib/plasma-glib.h',
                        identifier_prefix: 'GPlasma',
                        includes: gir_includes,
diff --git a/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb b/c_glib/test/flight/test-call-options.rb
similarity index 52%
copy from ruby/red-arrow-flight/lib/arrow-flight/call-options.rb
copy to c_glib/test/flight/test-call-options.rb
index 2030b2d330..bf4dd6ae81 100644
--- a/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb
+++ b/c_glib/test/flight/test-call-options.rb
@@ -15,21 +15,33 @@
 # specific language governing permissions and limitations
 # under the License.
 
-module ArrowFlight
-  class CallOptions
-    class << self
-      def try_convert(value)
-        case value
-        when Hash
-          options = new
-          value.each do |name, value|
-            options.__send__("#{name}=", value)
-          end
-          options
-        else
-          nil
-        end
-      end
+class TestFlightCallOptions < Test::Unit::TestCase
+  def setup
+    omit("Arrow Flight is required") unless defined?(ArrowFlight)
+    @options = ArrowFlight::CallOptions.new
+  end
+
+  def collect_headers
+    headers = []
+    @options.foreach_header do |name, value|
+      headers << [name, value]
     end
+    headers
+  end
+
+  def test_add_headers
+    @options.add_header("name1", "value1")
+    @options.add_header("name2", "value2")
+    assert_equal([
+                   ["name1", "value1"],
+                   ["name2", "value2"],
+                 ],
+                 collect_headers)
+  end
+
+  def test_clear_headers
+    @options.add_header("name1", "value1")
+    @options.clear_headers
+    assert_equal([], collect_headers)
   end
 end
diff --git a/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb b/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb
index 2030b2d330..e9e45c33ec 100644
--- a/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb
+++ b/ruby/red-arrow-flight/lib/arrow-flight/call-options.rb
@@ -31,5 +31,23 @@ module ArrowFlight
         end
       end
     end
+
+    def headers=(headers)
+      clear_headers
+      headers.each do |name, value|
+        add_header(name, value)
+      end
+    end
+
+    def each_header
+      return to_enum(__method__) unless block_given?
+      foreach_header do |key, value|
+        yield(key, value)
+      end
+    end
+
+    def headers
+      each_header.to_a
+    end
   end
 end
diff --git a/ruby/red-arrow-flight/test/test-call-options.rb b/ruby/red-arrow-flight/test/test-call-options.rb
new file mode 100644
index 0000000000..f54bbfe076
--- /dev/null
+++ b/ruby/red-arrow-flight/test/test-call-options.rb
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class TestCallOptions < Test::Unit::TestCase
+  sub_test_case(".try_convert") do
+    def test_headers
+      options = ArrowFlight::CallOptions.try_convert(headers: {"a" => "b"})
+      assert_equal([["a", "b"]],
+                   options.headers)
+    end
+  end
+
+  def setup
+    @options = ArrowFlight::CallOptions.new
+  end
+
+  def test_add_header
+    @options.add_header("name1", "value1")
+    @options.add_header("name2", "value2")
+    assert_equal([
+                   ["name1", "value1"],
+                   ["name2", "value2"],
+                 ],
+                 @options.headers)
+  end
+
+  def test_set_headers
+    @options.add_header("name1", "value1")
+    @options.headers = {
+      "name2" => "value2",
+      "name3" => "value3",
+    }
+    assert_equal([
+                   ["name2", "value2"],
+                   ["name3", "value3"],
+                 ],
+                 @options.headers)
+  end
+end