2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 #include <arrow-glib/arrow-glib.hpp>
22 #include <arrow-flight-glib/client.hpp>
23 #include <arrow-flight-glib/common.hpp>
30 * @title: Client related classes
31 * @include: arrow-flight-glib/arrow-flight-glib.h
33 * #GAFlightStreamReader is a class for reading record batches from a
36 * #GAFlightCallOptions is a class for options of each call.
38 * #GAFlightClientOptions is a class for options of each client.
40 * #GAFlightClient is a class for Apache Arrow Flight client.
45 G_DEFINE_TYPE(GAFlightStreamReader
,
46 gaflight_stream_reader
,
47 GAFLIGHT_TYPE_RECORD_BATCH_READER
)
50 gaflight_stream_reader_init(GAFlightStreamReader
*object
)
55 gaflight_stream_reader_class_init(GAFlightStreamReaderClass
*klass
)
59 typedef struct GAFlightCallOptionsPrivate_
{
60 arrow::flight::FlightCallOptions options
;
61 } GAFlightCallOptionsPrivate
;
63 G_DEFINE_TYPE_WITH_PRIVATE(GAFlightCallOptions
,
64 gaflight_call_options
,
67 #define GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(obj) \
68 static_cast<GAFlightCallOptionsPrivate *>( \
69 gaflight_call_options_get_instance_private( \
70 GAFLIGHT_CALL_OPTIONS(obj)))
73 gaflight_call_options_finalize(GObject
*object
)
75 auto priv
= GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(object
);
77 priv
->options
.~FlightCallOptions();
79 G_OBJECT_CLASS(gaflight_call_options_parent_class
)->finalize(object
);
83 gaflight_call_options_init(GAFlightCallOptions
*object
)
85 auto priv
= GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(object
);
86 new(&priv
->options
) arrow::flight::FlightCallOptions
;
90 gaflight_call_options_class_init(GAFlightCallOptionsClass
*klass
)
92 auto gobject_class
= G_OBJECT_CLASS(klass
);
94 gobject_class
->finalize
= gaflight_call_options_finalize
;
98 * gaflight_call_options_new:
100 * Returns: The newly created options for a call.
104 GAFlightCallOptions
*
105 gaflight_call_options_new(void)
107 return static_cast<GAFlightCallOptions
*>(
108 g_object_new(GAFLIGHT_TYPE_CALL_OPTIONS
, NULL
));
112 typedef struct GAFlightClientOptionsPrivate_
{
113 arrow::flight::FlightClientOptions options
;
114 } GAFlightClientOptionsPrivate
;
116 G_DEFINE_TYPE_WITH_PRIVATE(GAFlightClientOptions
,
117 gaflight_client_options
,
120 #define GAFLIGHT_CLIENT_OPTIONS_GET_PRIVATE(obj) \
121 static_cast<GAFlightClientOptionsPrivate *>( \
122 gaflight_client_options_get_instance_private( \
123 GAFLIGHT_CLIENT_OPTIONS(obj)))
126 gaflight_client_options_finalize(GObject
*object
)
128 auto priv
= GAFLIGHT_CLIENT_OPTIONS_GET_PRIVATE(object
);
130 priv
->options
.~FlightClientOptions();
132 G_OBJECT_CLASS(gaflight_client_options_parent_class
)->finalize(object
);
136 gaflight_client_options_init(GAFlightClientOptions
*object
)
138 auto priv
= GAFLIGHT_CLIENT_OPTIONS_GET_PRIVATE(object
);
139 new(&(priv
->options
)) arrow::flight::FlightClientOptions
;
140 priv
->options
= arrow::flight::FlightClientOptions::Defaults();
144 gaflight_client_options_class_init(GAFlightClientOptionsClass
*klass
)
146 auto gobject_class
= G_OBJECT_CLASS(klass
);
148 gobject_class
->finalize
= gaflight_client_options_finalize
;
152 * gaflight_client_options_new:
154 * Returns: The newly created options for a client.
158 GAFlightClientOptions
*
159 gaflight_client_options_new(void)
161 return static_cast<GAFlightClientOptions
*>(
162 g_object_new(GAFLIGHT_TYPE_CLIENT_OPTIONS
, NULL
));
166 typedef struct GAFlightClientPrivate_
{
167 arrow::flight::FlightClient
*client
;
168 } GAFlightClientPrivate
;
174 G_DEFINE_TYPE_WITH_PRIVATE(GAFlightClient
,
178 #define GAFLIGHT_CLIENT_GET_PRIVATE(obj) \
179 static_cast<GAFlightClientPrivate *>( \
180 gaflight_client_get_instance_private( \
181 GAFLIGHT_CLIENT(obj)))
184 gaflight_client_finalize(GObject
*object
)
186 auto priv
= GAFLIGHT_CLIENT_GET_PRIVATE(object
);
190 G_OBJECT_CLASS(gaflight_client_parent_class
)->finalize(object
);
194 gaflight_client_set_property(GObject
*object
,
199 auto priv
= GAFLIGHT_CLIENT_GET_PRIVATE(object
);
204 static_cast<arrow::flight::FlightClient
*>(g_value_get_pointer(value
));
207 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
213 gaflight_client_init(GAFlightClient
*object
)
218 gaflight_client_class_init(GAFlightClientClass
*klass
)
220 auto gobject_class
= G_OBJECT_CLASS(klass
);
222 gobject_class
->finalize
= gaflight_client_finalize
;
223 gobject_class
->set_property
= gaflight_client_set_property
;
226 spec
= g_param_spec_pointer("client",
228 "The raw arrow::flight::FlightClient *",
229 static_cast<GParamFlags
>(G_PARAM_WRITABLE
|
230 G_PARAM_CONSTRUCT_ONLY
));
231 g_object_class_install_property(gobject_class
, PROP_CLIENT
, spec
);
235 * gaflight_client_new:
236 * @location: A #GAFlightLocation to be connected.
237 * @options: (nullable): A #GAFlightClientOptions.
238 * @error: (nullable): Return location for a #GError or %NULL.
240 * Returns: (nullable): The newly created client, %NULL on error.
245 gaflight_client_new(GAFlightLocation
*location
,
246 GAFlightClientOptions
*options
,
249 const auto flight_location
= gaflight_location_get_raw(location
);
250 std::unique_ptr
<arrow::flight::FlightClient
> flight_client
;
251 arrow::Status status
;
253 const auto flight_options
= gaflight_client_options_get_raw(options
);
254 status
= arrow::flight::FlightClient::Connect(*flight_location
,
258 status
= arrow::flight::FlightClient::Connect(*flight_location
,
261 if (garrow::check(error
, status
, "[flight-client][new]")) {
262 return gaflight_client_new_raw(flight_client
.release());
269 * gaflight_client_list_flights:
270 * @client: A #GAFlightClient.
271 * @criteria: (nullable): A #GAFlightCriteria.
272 * @options: (nullable): A #GAFlightCallOptions.
273 * @error: (nullable): Return location for a #GError or %NULL.
275 * Returns: (nullable) (element-type GAFlightInfo) (transfer full):
276 * The returned list of #GAFlightInfo on success, %NULL on error.
281 gaflight_client_list_flights(GAFlightClient
*client
,
282 GAFlightCriteria
*criteria
,
283 GAFlightCallOptions
*options
,
286 auto flight_client
= gaflight_client_get_raw(client
);
287 arrow::flight::Criteria flight_default_criteria
;
288 auto flight_criteria
= &flight_default_criteria
;
290 flight_criteria
= gaflight_criteria_get_raw(criteria
);
292 arrow::flight::FlightCallOptions flight_default_options
;
293 auto flight_options
= &flight_default_options
;
295 flight_options
= gaflight_call_options_get_raw(options
);
297 std::unique_ptr
<arrow::flight::FlightListing
> flight_listing
;
298 auto status
= flight_client
->ListFlights(*flight_options
,
301 if (!garrow::check(error
,
303 "[flight-client][list-flights]")) {
306 GList
*listing
= NULL
;
307 std::unique_ptr
<arrow::flight::FlightInfo
> flight_info
;
309 status
= flight_listing
->Next(&flight_info
);
310 if (!garrow::check(error
,
312 "[flight-client][list-flights]")) {
313 g_list_free_full(listing
, g_object_unref
);
319 auto info
= gaflight_info_new_raw(flight_info
.release());
320 listing
= g_list_prepend(listing
, info
);
322 return g_list_reverse(listing
);
326 * gaflight_client_do_get:
327 * @client: A #GAFlightClient.
328 * @ticket: A #GAFlightTicket.
329 * @options: (nullable): A #GAFlightCallOptions.
330 * @error: (nullable): Return location for a #GError or %NULL.
332 * Returns: (nullable) (transfer full):
333 * The #GAFlightStreamReader to read record batched from the server
334 * on success, %NULL on error.
338 GAFlightStreamReader
*
339 gaflight_client_do_get(GAFlightClient
*client
,
340 GAFlightTicket
*ticket
,
341 GAFlightCallOptions
*options
,
344 auto flight_client
= gaflight_client_get_raw(client
);
345 const auto flight_ticket
= gaflight_ticket_get_raw(ticket
);
346 arrow::flight::FlightCallOptions flight_default_options
;
347 auto flight_options
= &flight_default_options
;
349 flight_options
= gaflight_call_options_get_raw(options
);
351 std::unique_ptr
<arrow::flight::FlightStreamReader
> flight_reader
;
352 auto status
= flight_client
->DoGet(*flight_options
,
355 if (garrow::check(error
,
357 "[flight-client][do-get]")) {
358 return gaflight_stream_reader_new_raw(flight_reader
.release());
368 GAFlightStreamReader
*
369 gaflight_stream_reader_new_raw(
370 arrow::flight::FlightStreamReader
*flight_reader
)
372 return GAFLIGHT_STREAM_READER(
373 g_object_new(GAFLIGHT_TYPE_STREAM_READER
,
374 "reader", flight_reader
,
378 arrow::flight::FlightCallOptions
*
379 gaflight_call_options_get_raw(GAFlightCallOptions
*options
)
381 auto priv
= GAFLIGHT_CALL_OPTIONS_GET_PRIVATE(options
);
382 return &(priv
->options
);
385 arrow::flight::FlightClientOptions
*
386 gaflight_client_options_get_raw(GAFlightClientOptions
*options
)
388 auto priv
= GAFLIGHT_CLIENT_OPTIONS_GET_PRIVATE(options
);
389 return &(priv
->options
);
392 arrow::flight::FlightClient
*
393 gaflight_client_get_raw(GAFlightClient
*client
)
395 auto priv
= GAFLIGHT_CLIENT_GET_PRIVATE(client
);
400 gaflight_client_new_raw(arrow::flight::FlightClient
*flight_client
)
402 return GAFLIGHT_CLIENT(g_object_new(GAFLIGHT_TYPE_CLIENT
,
403 "client", flight_client
,