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 5014dc5f78 ARROW-17158: [GLib][Flight] Add support for GetFlightInfo 
(#13672)
5014dc5f78 is described below

commit 5014dc5f78d51a0df7af144805af84a26e611899
Author: Sutou Kouhei <[email protected]>
AuthorDate: Fri Jul 22 10:18:46 2022 +0900

    ARROW-17158: [GLib][Flight] Add support for GetFlightInfo (#13672)
    
    Authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-flight-glib/client.cpp | 34 ++++++++++++++++++++++++
 c_glib/arrow-flight-glib/client.h   |  7 +++++
 c_glib/arrow-flight-glib/server.cpp | 52 +++++++++++++++++++++++++++++++++++++
 c_glib/arrow-flight-glib/server.h   | 10 +++++++
 c_glib/test/flight/test-client.rb   |  8 ++++++
 c_glib/test/helper/flight-server.rb |  5 ++++
 6 files changed, 116 insertions(+)

diff --git a/c_glib/arrow-flight-glib/client.cpp 
b/c_glib/arrow-flight-glib/client.cpp
index 4995f25c91..8710433bd0 100644
--- a/c_glib/arrow-flight-glib/client.cpp
+++ b/c_glib/arrow-flight-glib/client.cpp
@@ -403,6 +403,40 @@ gaflight_client_list_flights(GAFlightClient *client,
   return g_list_reverse(listing);
 }
 
+/**
+ * gaflight_client_get_flight_info:
+ * @client: A #GAFlightClient.
+ * @descriptor: A #GAFlightDescriptor to be processed.
+ * @options: (nullable): A #GAFlightCallOptions.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (nullable) (transfer full): The returned #GAFlightInfo on
+ *   success, %NULL on error.
+ *
+ * Since: 9.0.0
+ */
+GAFlightInfo *
+gaflight_client_get_flight_info(GAFlightClient *client,
+                                GAFlightDescriptor *descriptor,
+                                GAFlightCallOptions *options,
+                                GError **error)
+{
+  auto flight_client = gaflight_client_get_raw(client);
+  auto flight_descriptor = gaflight_descriptor_get_raw(descriptor);
+  arrow::flight::FlightCallOptions flight_default_options;
+  auto flight_options = &flight_default_options;
+  if (options) {
+    flight_options = gaflight_call_options_get_raw(options);
+  }
+  auto result = flight_client->GetFlightInfo(*flight_options,
+                                             *flight_descriptor);
+  if (!garrow::check(error, result, "[flight-client][get-flight-info]")) {
+    return NULL;
+  }
+  auto flight_info = std::move(*result);
+  return gaflight_info_new_raw(flight_info.release());
+}
+
 /**
  * gaflight_client_do_get:
  * @client: A #GAFlightClient.
diff --git a/c_glib/arrow-flight-glib/client.h 
b/c_glib/arrow-flight-glib/client.h
index f601e66e79..d4339a5fed 100644
--- a/c_glib/arrow-flight-glib/client.h
+++ b/c_glib/arrow-flight-glib/client.h
@@ -98,6 +98,13 @@ gaflight_client_list_flights(GAFlightClient *client,
                              GAFlightCallOptions *options,
                              GError **error);
 
+GARROW_AVAILABLE_IN_9_0
+GAFlightInfo *
+gaflight_client_get_flight_info(GAFlightClient *client,
+                                GAFlightDescriptor *descriptor,
+                                GAFlightCallOptions *options,
+                                GError **error);
+
 GARROW_AVAILABLE_IN_6_0
 GAFlightStreamReader *
 gaflight_client_do_get(GAFlightClient *client,
diff --git a/c_glib/arrow-flight-glib/server.cpp 
b/c_glib/arrow-flight-glib/server.cpp
index 64f8737d7e..40bad8b496 100644
--- a/c_glib/arrow-flight-glib/server.cpp
+++ b/c_glib/arrow-flight-glib/server.cpp
@@ -489,6 +489,30 @@ namespace gaflight {
       return arrow::Status::OK();
     }
 
+    arrow::Status
+    GetFlightInfo(const arrow::flight::ServerCallContext &context,
+                  const arrow::flight::FlightDescriptor &request,
+                  std::unique_ptr<arrow::flight::FlightInfo> *info) override {
+      auto gacontext = gaflight_server_call_context_new_raw(&context);
+      auto garequest = gaflight_descriptor_new_raw(&request);
+      GError *gerror = nullptr;
+      auto gainfo = gaflight_server_get_flight_info(gaserver_,
+                                                    gacontext,
+                                                    garequest,
+                                                    &gerror);
+      g_object_unref(garequest);
+      g_object_unref(gacontext);
+      if (gerror) {
+        return garrow_error_to_status(gerror,
+                                      arrow::StatusCode::UnknownError,
+                                      "[flight-server][get-flight-info]");
+      }
+      *info = arrow::internal::make_unique<arrow::flight::FlightInfo>(
+        *gaflight_info_get_raw(gainfo));
+      g_object_unref(gainfo);
+      return arrow::Status::OK();
+    }
+
     arrow::Status DoGet(
       const arrow::flight::ServerCallContext &context,
       const arrow::flight::Ticket &ticket,
@@ -666,6 +690,34 @@ gaflight_server_list_flights(GAFlightServer *server,
   return (*(klass->list_flights))(server, context, criteria, error);
 }
 
+/**
+ * gaflight_server_get_flight_info:
+ * @server: A #GAFlightServer.
+ * @context: A #GAFlightServerCallContext.
+ * @request: A #GAFlightDescriptor.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: (transfer full): A #GAFlightInfo on success, %NULL on error.
+ *
+ * Since: 9.0.0
+ */
+GAFlightInfo *
+gaflight_server_get_flight_info(GAFlightServer *server,
+                                GAFlightServerCallContext *context,
+                                GAFlightDescriptor *request,
+                                GError **error)
+{
+  auto klass = GAFLIGHT_SERVER_GET_CLASS(server);
+  if (!(klass && klass->get_flight_info)) {
+    g_set_error(error,
+                GARROW_ERROR,
+                GARROW_ERROR_NOT_IMPLEMENTED,
+                "not implemented");
+    return nullptr;
+  }
+  return (*(klass->get_flight_info))(server, context, request, error);
+}
+
 /**
  * gaflight_server_do_get:
  * @server: A #GAFlightServer.
diff --git a/c_glib/arrow-flight-glib/server.h 
b/c_glib/arrow-flight-glib/server.h
index d83b59eb5b..b293c7408a 100644
--- a/c_glib/arrow-flight-glib/server.h
+++ b/c_glib/arrow-flight-glib/server.h
@@ -113,6 +113,10 @@ struct _GAFlightServerClass
                          GAFlightServerCallContext *context,
                          GAFlightCriteria *criteria,
                          GError **error);
+  GAFlightInfo *(*get_flight_info)(GAFlightServer *server,
+                                   GAFlightServerCallContext *context,
+                                   GAFlightDescriptor *request,
+                                   GError **error);
   GAFlightDataStream *(*do_get)(GAFlightServer *server,
                                 GAFlightServerCallContext *context,
                                 GAFlightTicket *ticket,
@@ -142,6 +146,12 @@ gaflight_server_list_flights(GAFlightServer *server,
                              GAFlightServerCallContext *context,
                              GAFlightCriteria *criteria,
                              GError **error);
+GARROW_AVAILABLE_IN_9_0
+GAFlightInfo *
+gaflight_server_get_flight_info(GAFlightServer *server,
+                                GAFlightServerCallContext *context,
+                                GAFlightDescriptor *request,
+                                GError **error);
 GARROW_AVAILABLE_IN_6_0
 GAFlightDataStream *
 gaflight_server_do_get(GAFlightServer *server,
diff --git a/c_glib/test/flight/test-client.rb 
b/c_glib/test/flight/test-client.rb
index 48f03223f4..d2fb3cc682 100644
--- a/c_glib/test/flight/test-client.rb
+++ b/c_glib/test/flight/test-client.rb
@@ -50,6 +50,14 @@ class TestFlightClient < Test::Unit::TestCase
                  client.list_flights)
   end
 
+  def test_get_flight_info
+    client = ArrowFlight::Client.new(@location)
+    request = ArrowFlight::CommandDescriptor.new("page-view")
+    generator = Helper::FlightInfoGenerator.new
+    assert_equal(generator.page_view,
+                 client.get_flight_info(request))
+  end
+
   sub_test_case("#do_get") do
     def test_success
       client = ArrowFlight::Client.new(@location)
diff --git a/c_glib/test/helper/flight-server.rb 
b/c_glib/test/helper/flight-server.rb
index 89fd13b421..238b2f4b58 100644
--- a/c_glib/test/helper/flight-server.rb
+++ b/c_glib/test/helper/flight-server.rb
@@ -27,6 +27,11 @@ module Helper
       [generator.page_view]
     end
 
+    def virtual_do_get_flight_info(command, criteria)
+      generator = FlightInfoGenerator.new
+      generator.page_view
+    end
+
     def virtual_do_do_get(context, ticket)
       generator = FlightInfoGenerator.new
       unless ticket == generator.page_view_ticket

Reply via email to