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/codec.hpp>
21 #include <arrow-glib/enums.h>
22 #include <arrow-glib/ipc-options.hpp>
27 * SECTION: ipc-options
28 * @section_id: ipc-options-classes
29 * @title: IPC options classes
30 * @include: arrow-glib/arrow-glib.h
32 * #GArrowReadOptions provides options for reading data.
34 * #GArrowWriteOptions provides options for writing data.
37 typedef struct GArrowReadOptionsPrivate_
{
38 arrow::ipc::IpcReadOptions options
;
39 arrow::ipc::DictionaryMemo dictionary_memo
;
40 } GArrowReadOptionsPrivate
;
43 PROP_READ_OPTIONS_MAX_RECURSION_DEPTH
= 1,
44 PROP_READ_OPTIONS_USE_THREADS
,
47 G_DEFINE_TYPE_WITH_PRIVATE(GArrowReadOptions
,
51 #define GARROW_READ_OPTIONS_GET_PRIVATE(obj) \
52 static_cast<GArrowReadOptionsPrivate *>( \
53 garrow_read_options_get_instance_private( \
54 GARROW_READ_OPTIONS(obj)))
57 garrow_read_options_finalize(GObject
*object
)
59 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(object
);
61 priv
->options
.~IpcReadOptions();
62 priv
->dictionary_memo
.~DictionaryMemo();
64 G_OBJECT_CLASS(garrow_read_options_parent_class
)->finalize(object
);
68 garrow_read_options_set_property(GObject
*object
,
73 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(object
);
76 case PROP_READ_OPTIONS_MAX_RECURSION_DEPTH
:
77 priv
->options
.max_recursion_depth
= g_value_get_int(value
);
79 case PROP_READ_OPTIONS_USE_THREADS
:
80 priv
->options
.use_threads
= g_value_get_boolean(value
);
83 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
89 garrow_read_options_get_property(GObject
*object
,
94 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(object
);
97 case PROP_READ_OPTIONS_MAX_RECURSION_DEPTH
:
98 g_value_set_int(value
, priv
->options
.max_recursion_depth
);
100 case PROP_READ_OPTIONS_USE_THREADS
:
101 g_value_set_boolean(value
, priv
->options
.use_threads
);
104 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
110 garrow_read_options_init(GArrowReadOptions
*object
)
112 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(object
);
113 new(&priv
->options
) arrow::ipc::IpcReadOptions
;
114 priv
->options
= arrow::ipc::IpcReadOptions::Defaults();
115 new(&priv
->dictionary_memo
) arrow::ipc::DictionaryMemo
;
119 garrow_read_options_class_init(GArrowReadOptionsClass
*klass
)
121 auto gobject_class
= G_OBJECT_CLASS(klass
);
123 gobject_class
->finalize
= garrow_read_options_finalize
;
124 gobject_class
->set_property
= garrow_read_options_set_property
;
125 gobject_class
->get_property
= garrow_read_options_get_property
;
127 auto options
= arrow::ipc::IpcReadOptions::Defaults();
132 * GArrowReadOptions:max-recursion-depth:
134 * The maximum permitted schema nesting depth.
138 spec
= g_param_spec_int("max-recursion-depth",
139 "Max recursion depth",
140 "The maximum permitted schema nesting depth",
142 arrow::ipc::kMaxNestingDepth
,
143 options
.max_recursion_depth
,
144 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
145 g_object_class_install_property(gobject_class
,
146 PROP_READ_OPTIONS_MAX_RECURSION_DEPTH
,
150 * GArrowReadOptions:use-threads:
152 * Whether to use the global CPU thread pool.
156 spec
= g_param_spec_boolean("use-threads",
158 "Whether to use the global CPU thread pool",
160 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
161 g_object_class_install_property(gobject_class
,
162 PROP_READ_OPTIONS_USE_THREADS
,
167 * garrow_read_options_new:
169 * Returns: A newly created #GArrowReadOptions.
174 garrow_read_options_new(void)
176 auto options
= g_object_new(GARROW_TYPE_READ_OPTIONS
, NULL
);
177 return GARROW_READ_OPTIONS(options
);
181 * garrow_read_options_get_included_fields:
182 * @options: A #GArrowReadOptions.
183 * @n_fields: (out): The number of included fields.
185 * Returns: (array length=n_fields) (transfer full):
186 * Top-level schema fields to include when deserializing
187 * RecordBatch. If empty, return all deserialized fields.
189 * It should be freed with g_free() when no longer needed.
194 garrow_read_options_get_included_fields(GArrowReadOptions
*options
,
197 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(options
);
198 if (priv
->options
.included_fields
.empty()) {
205 auto n
= priv
->options
.included_fields
.size();
206 auto fields
= g_new(int, n
);
210 for (size_t i
= 0; i
< n
; ++i
) {
211 fields
[i
] = priv
->options
.included_fields
[i
];
217 * garrow_read_options_set_included_fields:
218 * @options: A #GArrowReadOptions.
219 * @fields: (array length=n_fields): Top-level schema fields to
220 * include when deserializing RecordBatch. If empty, return all
221 * deserialized fields.
222 * @n_fields: The number of included fields.
227 garrow_read_options_set_included_fields(GArrowReadOptions
*options
,
231 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(options
);
233 priv
->options
.included_fields
.resize(n_fields
);
234 for (gsize i
= 0; i
< n_fields
; ++i
) {
235 priv
->options
.included_fields
[i
] = fields
[i
];
240 typedef struct GArrowWriteOptionsPrivate_
{
241 arrow::ipc::IpcWriteOptions options
;
243 } GArrowWriteOptionsPrivate
;
246 PROP_WRITE_OPTIONS_ALLOW_64BIT
= 1,
247 PROP_WRITE_OPTIONS_MAX_RECURSION_DEPTH
,
248 PROP_WRITE_OPTIONS_ALIGNMENT
,
249 PROP_WRITE_OPTIONS_WRITE_LEGACY_IPC_FORMAT
,
250 PROP_WRITE_OPTIONS_CODEC
,
251 PROP_WRITE_OPTIONS_USE_THREADS
,
254 G_DEFINE_TYPE_WITH_PRIVATE(GArrowWriteOptions
,
255 garrow_write_options
,
258 #define GARROW_WRITE_OPTIONS_GET_PRIVATE(obj) \
259 static_cast<GArrowWriteOptionsPrivate *>( \
260 garrow_write_options_get_instance_private( \
261 GARROW_WRITE_OPTIONS(obj)))
264 garrow_write_options_dispose(GObject
*object
)
266 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(object
);
269 g_object_unref(priv
->codec
);
273 G_OBJECT_CLASS(garrow_write_options_parent_class
)->dispose(object
);
277 garrow_write_options_finalize(GObject
*object
)
279 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(object
);
281 priv
->options
.~IpcWriteOptions();
283 G_OBJECT_CLASS(garrow_write_options_parent_class
)->finalize(object
);
287 garrow_write_options_set_property(GObject
*object
,
292 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(object
);
295 case PROP_WRITE_OPTIONS_ALLOW_64BIT
:
296 priv
->options
.allow_64bit
= g_value_get_boolean(value
);
298 case PROP_WRITE_OPTIONS_MAX_RECURSION_DEPTH
:
299 priv
->options
.max_recursion_depth
= g_value_get_int(value
);
301 case PROP_WRITE_OPTIONS_ALIGNMENT
:
302 priv
->options
.alignment
= g_value_get_int(value
);
304 case PROP_WRITE_OPTIONS_WRITE_LEGACY_IPC_FORMAT
:
305 priv
->options
.write_legacy_ipc_format
= g_value_get_boolean(value
);
307 case PROP_WRITE_OPTIONS_CODEC
:
309 g_object_unref(priv
->codec
);
311 priv
->codec
= GARROW_CODEC(g_value_dup_object(value
));
312 priv
->options
.codec
= garrow_codec_get_raw(priv
->codec
);
314 case PROP_WRITE_OPTIONS_USE_THREADS
:
315 priv
->options
.use_threads
= g_value_get_boolean(value
);
318 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
324 garrow_write_options_get_property(GObject
*object
,
329 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(object
);
332 case PROP_WRITE_OPTIONS_ALLOW_64BIT
:
333 g_value_set_boolean(value
, priv
->options
.allow_64bit
);
335 case PROP_WRITE_OPTIONS_MAX_RECURSION_DEPTH
:
336 g_value_set_int(value
, priv
->options
.max_recursion_depth
);
338 case PROP_WRITE_OPTIONS_ALIGNMENT
:
339 g_value_set_int(value
, priv
->options
.alignment
);
341 case PROP_WRITE_OPTIONS_WRITE_LEGACY_IPC_FORMAT
:
342 g_value_set_boolean(value
, priv
->options
.write_legacy_ipc_format
);
344 case PROP_WRITE_OPTIONS_CODEC
:
345 g_value_set_object(value
, priv
->codec
);
347 case PROP_WRITE_OPTIONS_USE_THREADS
:
348 g_value_set_boolean(value
, priv
->options
.use_threads
);
351 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, prop_id
, pspec
);
357 garrow_write_options_init(GArrowWriteOptions
*object
)
359 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(object
);
360 new(&priv
->options
) arrow::ipc::IpcWriteOptions
;
361 priv
->options
= arrow::ipc::IpcWriteOptions::Defaults();
362 if (priv
->options
.codec
) {
363 priv
->codec
= garrow_codec_new_raw(&(priv
->options
.codec
));
370 garrow_write_options_class_init(GArrowWriteOptionsClass
*klass
)
372 auto gobject_class
= G_OBJECT_CLASS(klass
);
374 gobject_class
->dispose
= garrow_write_options_dispose
;
375 gobject_class
->finalize
= garrow_write_options_finalize
;
376 gobject_class
->set_property
= garrow_write_options_set_property
;
377 gobject_class
->get_property
= garrow_write_options_get_property
;
379 auto options
= arrow::ipc::IpcWriteOptions::Defaults();
384 * GArrowWriteOptions:allow-64bit:
386 * Whether to allow field lengths that don't fit in a signed 32-bit
387 * int. Some implementations may not be able to parse such streams.
391 spec
= g_param_spec_boolean("allow-64bit",
393 "Whether to allow signed 64-bit int "
396 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
397 g_object_class_install_property(gobject_class
,
398 PROP_WRITE_OPTIONS_ALLOW_64BIT
,
402 * GArrowWriteOptions:max-recursion-depth:
404 * The maximum permitted schema nesting depth.
408 spec
= g_param_spec_int("max-recursion-depth",
409 "Max recursion depth",
410 "The maximum permitted schema nesting depth",
412 arrow::ipc::kMaxNestingDepth
,
413 options
.max_recursion_depth
,
414 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
415 g_object_class_install_property(gobject_class
,
416 PROP_WRITE_OPTIONS_MAX_RECURSION_DEPTH
,
420 * GArrowWriteOptions:alignment:
422 * Write padding after memory buffers to this multiple of
423 * bytes. Generally 8 or 64.
427 spec
= g_param_spec_int("alignment",
430 "after memory buffers to this multiple of bytes",
434 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
435 g_object_class_install_property(gobject_class
,
436 PROP_WRITE_OPTIONS_ALIGNMENT
,
440 * GArrowWriteOptions:write-legacy-ipc-format:
442 * Whether to write the pre-0.15.0 encapsulated IPC message format
443 * consisting of a 4-byte prefix instead of 8 byte.
447 spec
= g_param_spec_boolean("write-legacy-ipc-format",
448 "Write legacy IPC format",
449 "Whether to write legacy IPC format",
450 options
.write_legacy_ipc_format
,
451 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
452 g_object_class_install_property(gobject_class
,
453 PROP_WRITE_OPTIONS_WRITE_LEGACY_IPC_FORMAT
,
457 * GArrowWriteOptions:codec:
459 * Codec to use for compressing and decompressing record batch body
460 * buffers. This is not part of the Arrow IPC protocol and only for
461 * internal use (e.g. Feather files).
463 * May only be UNCOMPRESSED, LZ4_FRAME and ZSTD.
467 spec
= g_param_spec_object("codec",
470 "compressing record batch body buffers.",
472 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
473 g_object_class_install_property(gobject_class
,
474 PROP_WRITE_OPTIONS_CODEC
,
478 * GArrowWriteOptions:use-threads:
480 * Whether to use the global CPU thread pool.
484 spec
= g_param_spec_boolean("use-threads",
486 "Whether to use the global CPU thread pool",
488 static_cast<GParamFlags
>(G_PARAM_READWRITE
));
489 g_object_class_install_property(gobject_class
,
490 PROP_WRITE_OPTIONS_USE_THREADS
,
495 * garrow_write_options_new:
497 * Returns: A newly created #GArrowWriteOptions.
502 garrow_write_options_new(void)
504 auto options
= g_object_new(GARROW_TYPE_WRITE_OPTIONS
, NULL
);
505 return GARROW_WRITE_OPTIONS(options
);
510 arrow::ipc::IpcReadOptions
*
511 garrow_read_options_get_raw(GArrowReadOptions
*options
)
513 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(options
);
514 return &(priv
->options
);
517 arrow::ipc::DictionaryMemo
*
518 garrow_read_options_get_dictionary_memo_raw(GArrowReadOptions
*options
)
520 auto priv
= GARROW_READ_OPTIONS_GET_PRIVATE(options
);
521 return &(priv
->dictionary_memo
);
524 arrow::ipc::IpcWriteOptions
*
525 garrow_write_options_get_raw(GArrowWriteOptions
*options
)
527 auto priv
= GARROW_WRITE_OPTIONS_GET_PRIVATE(options
);
528 return &(priv
->options
);