@@ -7617,112 +7617,34 @@ garrow_make_struct_options_new(void)
76177617}
76187618
76197619/* *
7620- * garrow_make_struct_options_set_field_nullability :
7620+ * garrow_make_struct_options_add_field :
76217621 * @options: A #GArrowMakeStructOptions.
7622- * @nullability: (element-type gboolean) (nullable) (transfer none): A #GList
7623- * of nullability values, or %NULL.
7622+ * @name: The name of the field to add.
7623+ * @nullability: Whether the field is nullable.
7624+ * @metadata: (nullable) (element-type utf8 utf8): A #GHashTable for the field's
7625+ * metadata, or %NULL.
76247626 *
7625- * Sets the nullability information for each struct field.
7627+ * Adds a field to the struct options with the specified name, nullability,
7628+ * and optional metadata.
76267629 *
76277630 * Since: 23.0.0
76287631 */
76297632void
7630- garrow_make_struct_options_set_field_nullability (GArrowMakeStructOptions *options,
7631- GList *nullability)
7633+ garrow_make_struct_options_add_field (GArrowMakeStructOptions *options,
7634+ const char *name,
7635+ gboolean nullability,
7636+ GHashTable *metadata)
76327637{
76337638 auto arrow_options = static_cast <arrow::compute::MakeStructOptions *>(
76347639 garrow_function_options_get_raw (GARROW_FUNCTION_OPTIONS (options)));
7635- arrow_options->field_nullability .clear ();
7636- if (nullability) {
7637- for (GList *node = nullability; node; node = node->next ) {
7638- gboolean value = GPOINTER_TO_INT (node->data );
7639- arrow_options->field_nullability .push_back (value != FALSE );
7640- }
7641- }
7642- }
7643-
7644- /* *
7645- * garrow_make_struct_options_get_field_nullability:
7646- * @options: A #GArrowMakeStructOptions.
7647- *
7648- * Returns: (element-type gboolean) (transfer full): A #GList of nullability
7649- * values. It should be freed with g_list_free() when no longer needed.
7650- *
7651- * Gets the nullability information for each struct field.
7652- *
7653- * Since: 23.0.0
7654- */
7655- GList *
7656- garrow_make_struct_options_get_field_nullability (GArrowMakeStructOptions *options)
7657- {
7658- auto arrow_options = static_cast <arrow::compute::MakeStructOptions *>(
7659- garrow_function_options_get_raw (GARROW_FUNCTION_OPTIONS (options)));
7660- const auto &arrow_nullability = arrow_options->field_nullability ;
7661- GList *list = NULL ;
7662- for (gsize i = 0 ; i < arrow_nullability.size (); ++i) {
7663- gboolean value = arrow_nullability[i] ? TRUE : FALSE ;
7664- list = g_list_prepend (list, GINT_TO_POINTER (value));
7665- }
7666- return g_list_reverse (list);
7667- }
7668-
7669- /* *
7670- * garrow_make_struct_options_set_field_metadata:
7671- * @options: A #GArrowMakeStructOptions.
7672- * @metadata: (element-type GHashTable) (nullable) (transfer none): A #GList of
7673- * #GHashTable for each field's metadata, or %NULL.
7674- *
7675- * Sets the metadata for each struct field.
7676- *
7677- * Since: 23.0.0
7678- */
7679- void
7680- garrow_make_struct_options_set_field_metadata (GArrowMakeStructOptions *options,
7681- GList *metadata)
7682- {
7683- auto arrow_options = static_cast <arrow::compute::MakeStructOptions *>(
7684- garrow_function_options_get_raw (GARROW_FUNCTION_OPTIONS (options)));
7685- arrow_options->field_metadata .clear ();
7640+ arrow_options->field_names .emplace_back (name);
7641+ arrow_options->field_nullability .push_back (nullability != FALSE );
76867642 if (metadata) {
7687- for (GList *node = metadata; node; node = node->next ) {
7688- auto hash_table = static_cast <GHashTable *>(node->data );
7689- if (hash_table) {
7690- arrow_options->field_metadata .push_back (
7691- garrow_internal_hash_table_to_metadata (hash_table));
7692- } else {
7693- arrow_options->field_metadata .push_back (NULLPTR);
7694- }
7695- }
7696- }
7697- }
7698-
7699- /* *
7700- * garrow_make_struct_options_get_field_metadata:
7701- * @options: A #GArrowMakeStructOptions.
7702- *
7703- * Returns: (element-type GHashTable) (transfer full): A #GList of #GHashTable
7704- * for each field's metadata. It should be freed with g_list_free_full() and
7705- * g_hash_table_unref() when no longer needed.
7706- *
7707- * Gets the metadata for each struct field.
7708- *
7709- * Since: 23.0.0
7710- */
7711- GList *
7712- garrow_make_struct_options_get_field_metadata (GArrowMakeStructOptions *options)
7713- {
7714- auto arrow_options = static_cast <arrow::compute::MakeStructOptions *>(
7715- garrow_function_options_get_raw (GARROW_FUNCTION_OPTIONS (options)));
7716- const auto &arrow_metadata = arrow_options->field_metadata ;
7717- GList *list = NULL ;
7718- for (gsize i = 0 ; i < arrow_metadata.size (); ++i) {
7719- GHashTable *hash_table = NULL ;
7720- if (arrow_metadata[i] && arrow_metadata[i].get ()) {
7721- hash_table = garrow_internal_hash_table_from_metadata (arrow_metadata[i]);
7722- }
7723- list = g_list_prepend (list, hash_table);
7643+ arrow_options->field_metadata .push_back (
7644+ garrow_internal_hash_table_to_metadata (metadata));
7645+ } else {
7646+ arrow_options->field_metadata .push_back (nullptr );
77247647 }
7725- return g_list_reverse (list);
77267648}
77277649
77287650G_END_DECLS
0 commit comments