You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/03/17 01:09:51 UTC
[4/9] arrow git commit: ARROW-631: [GLib] Import
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/list-data-type.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/list-data-type.cpp b/c_glib/arrow-glib/list-data-type.cpp
new file mode 100644
index 0000000..e82e6fd
--- /dev/null
+++ b/c_glib/arrow-glib/list-data-type.cpp
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/field.hpp>
+#include <arrow-glib/list-data-type.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: list-data-type
+ * @short_description: List data type
+ *
+ * #GArrowListDataType is a class for list data type.
+ */
+
+G_DEFINE_TYPE(GArrowListDataType, \
+ garrow_list_data_type, \
+ GARROW_TYPE_DATA_TYPE)
+
+static void
+garrow_list_data_type_init(GArrowListDataType *object)
+{
+}
+
+static void
+garrow_list_data_type_class_init(GArrowListDataTypeClass *klass)
+{
+}
+
+/**
+ * garrow_list_data_type_new:
+ * @field: The field of elements
+ *
+ * Returns: The newly created list data type.
+ */
+GArrowListDataType *
+garrow_list_data_type_new(GArrowField *field)
+{
+ auto arrow_field = garrow_field_get_raw(field);
+ auto arrow_data_type =
+ std::make_shared<arrow::ListType>(arrow_field);
+
+ GArrowListDataType *data_type =
+ GARROW_LIST_DATA_TYPE(g_object_new(GARROW_TYPE_LIST_DATA_TYPE,
+ "data-type", &arrow_data_type,
+ NULL));
+ return data_type;
+}
+
+/**
+ * garrow_list_data_type_get_value_field:
+ * @list_data_type: A #GArrowListDataType.
+ *
+ * Returns: (transfer full): The field of value.
+ */
+GArrowField *
+garrow_list_data_type_get_value_field(GArrowListDataType *list_data_type)
+{
+ auto arrow_data_type =
+ garrow_data_type_get_raw(GARROW_DATA_TYPE(list_data_type));
+ auto arrow_list_data_type =
+ static_cast<arrow::ListType *>(arrow_data_type.get());
+
+ auto arrow_field = arrow_list_data_type->value_field();
+ auto field = garrow_field_new_raw(&arrow_field);
+
+ return field;
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/list-data-type.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/list-data-type.h b/c_glib/arrow-glib/list-data-type.h
new file mode 100644
index 0000000..bb406e2
--- /dev/null
+++ b/c_glib/arrow-glib/list-data-type.h
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/data-type.h>
+#include <arrow-glib/field.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_LIST_DATA_TYPE \
+ (garrow_list_data_type_get_type())
+#define GARROW_LIST_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_LIST_DATA_TYPE, \
+ GArrowListDataType))
+#define GARROW_LIST_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_LIST_DATA_TYPE, \
+ GArrowListDataTypeClass))
+#define GARROW_IS_LIST_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_LIST_DATA_TYPE))
+#define GARROW_IS_LIST_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_LIST_DATA_TYPE))
+#define GARROW_LIST_DATA_TYPE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_LIST_DATA_TYPE, \
+ GArrowListDataTypeClass))
+
+typedef struct _GArrowListDataType GArrowListDataType;
+typedef struct _GArrowListDataTypeClass GArrowListDataTypeClass;
+
+/**
+ * GArrowListDataType:
+ *
+ * It wraps `arrow::ListType`.
+ */
+struct _GArrowListDataType
+{
+ /*< private >*/
+ GArrowDataType parent_instance;
+};
+
+struct _GArrowListDataTypeClass
+{
+ GArrowDataTypeClass parent_class;
+};
+
+GType garrow_list_data_type_get_type (void) G_GNUC_CONST;
+
+GArrowListDataType *garrow_list_data_type_new (GArrowField *field);
+
+GArrowField *garrow_list_data_type_get_value_field (GArrowListDataType *list_data_type);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/null-array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/null-array.cpp b/c_glib/arrow-glib/null-array.cpp
new file mode 100644
index 0000000..0e0ea51
--- /dev/null
+++ b/c_glib/arrow-glib/null-array.cpp
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array.hpp>
+#include <arrow-glib/null-array.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: null-array
+ * @short_description: Null array class
+ *
+ * #GArrowNullArray is a class for null array. It can store zero
+ * or more null values.
+ *
+ * #GArrowNullArray is immutable. You need to specify an array length
+ * to create a new array.
+ */
+
+G_DEFINE_TYPE(GArrowNullArray, \
+ garrow_null_array, \
+ GARROW_TYPE_ARRAY)
+
+static void
+garrow_null_array_init(GArrowNullArray *object)
+{
+}
+
+static void
+garrow_null_array_class_init(GArrowNullArrayClass *klass)
+{
+}
+
+/**
+ * garrow_null_array_new:
+ * @length: An array length.
+ *
+ * Returns: A newly created #GArrowNullArray.
+ */
+GArrowNullArray *
+garrow_null_array_new(gint64 length)
+{
+ auto arrow_null_array = std::make_shared<arrow::NullArray>(length);
+ std::shared_ptr<arrow::Array> arrow_array = arrow_null_array;
+ auto array = garrow_array_new_raw(&arrow_array);
+ return GARROW_NULL_ARRAY(array);
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/null-array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/null-array.h b/c_glib/arrow-glib/null-array.h
new file mode 100644
index 0000000..e25f305
--- /dev/null
+++ b/c_glib/arrow-glib/null-array.h
@@ -0,0 +1,70 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/array.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_NULL_ARRAY \
+ (garrow_null_array_get_type())
+#define GARROW_NULL_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_NULL_ARRAY, \
+ GArrowNullArray))
+#define GARROW_NULL_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_NULL_ARRAY, \
+ GArrowNullArrayClass))
+#define GARROW_IS_NULL_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_NULL_ARRAY))
+#define GARROW_IS_NULL_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_NULL_ARRAY))
+#define GARROW_NULL_ARRAY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_NULL_ARRAY, \
+ GArrowNullArrayClass))
+
+typedef struct _GArrowNullArray GArrowNullArray;
+typedef struct _GArrowNullArrayClass GArrowNullArrayClass;
+
+/**
+ * GArrowNullArray:
+ *
+ * It wraps `arrow::NullArray`.
+ */
+struct _GArrowNullArray
+{
+ /*< private >*/
+ GArrowArray parent_instance;
+};
+
+struct _GArrowNullArrayClass
+{
+ GArrowArrayClass parent_class;
+};
+
+GType garrow_null_array_get_type(void) G_GNUC_CONST;
+
+GArrowNullArray *garrow_null_array_new(gint64 length);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/null-data-type.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/null-data-type.cpp b/c_glib/arrow-glib/null-data-type.cpp
new file mode 100644
index 0000000..1f75d3b
--- /dev/null
+++ b/c_glib/arrow-glib/null-data-type.cpp
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/null-data-type.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: null-data-type
+ * @short_description: Null data type
+ *
+ * #GArrowNullDataType is a class for null data type.
+ */
+
+G_DEFINE_TYPE(GArrowNullDataType, \
+ garrow_null_data_type, \
+ GARROW_TYPE_DATA_TYPE)
+
+static void
+garrow_null_data_type_init(GArrowNullDataType *object)
+{
+}
+
+static void
+garrow_null_data_type_class_init(GArrowNullDataTypeClass *klass)
+{
+}
+
+/**
+ * garrow_null_data_type_new:
+ *
+ * Returns: The newly created null data type.
+ */
+GArrowNullDataType *
+garrow_null_data_type_new(void)
+{
+ auto arrow_data_type = arrow::null();
+
+ GArrowNullDataType *data_type =
+ GARROW_NULL_DATA_TYPE(g_object_new(GARROW_TYPE_NULL_DATA_TYPE,
+ "data-type", &arrow_data_type,
+ NULL));
+ return data_type;
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/null-data-type.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/null-data-type.h b/c_glib/arrow-glib/null-data-type.h
new file mode 100644
index 0000000..006b76c
--- /dev/null
+++ b/c_glib/arrow-glib/null-data-type.h
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/data-type.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_NULL_DATA_TYPE \
+ (garrow_null_data_type_get_type())
+#define GARROW_NULL_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_NULL_DATA_TYPE, \
+ GArrowNullDataType))
+#define GARROW_NULL_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_NULL_DATA_TYPE, \
+ GArrowNullDataTypeClass))
+#define GARROW_IS_NULL_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_NULL_DATA_TYPE))
+#define GARROW_IS_NULL_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_NULL_DATA_TYPE))
+#define GARROW_NULL_DATA_TYPE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_NULL_DATA_TYPE, \
+ GArrowNullDataTypeClass))
+
+typedef struct _GArrowNullDataType GArrowNullDataType;
+typedef struct _GArrowNullDataTypeClass GArrowNullDataTypeClass;
+
+/**
+ * GArrowNullDataType:
+ *
+ * It wraps `arrow::NullType`.
+ */
+struct _GArrowNullDataType
+{
+ /*< private >*/
+ GArrowDataType parent_instance;
+};
+
+struct _GArrowNullDataTypeClass
+{
+ GArrowDataTypeClass parent_class;
+};
+
+GType garrow_null_data_type_get_type (void) G_GNUC_CONST;
+GArrowNullDataType *garrow_null_data_type_new (void);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/record-batch.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/record-batch.cpp b/c_glib/arrow-glib/record-batch.cpp
new file mode 100644
index 0000000..8ac1791
--- /dev/null
+++ b/c_glib/arrow-glib/record-batch.cpp
@@ -0,0 +1,288 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array.hpp>
+#include <arrow-glib/record-batch.hpp>
+#include <arrow-glib/schema.hpp>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: record-batch
+ * @short_description: Record batch class
+ *
+ * #GArrowRecordBatch is a class for record batch. Record batch is
+ * similar to #GArrowTable. Record batch also has also zero or more
+ * columns and zero or more records.
+ *
+ * Record batch is used for shared memory IPC.
+ */
+
+typedef struct GArrowRecordBatchPrivate_ {
+ std::shared_ptr<arrow::RecordBatch> record_batch;
+} GArrowRecordBatchPrivate;
+
+enum {
+ PROP_0,
+ PROP_RECORD_BATCH
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowRecordBatch,
+ garrow_record_batch,
+ G_TYPE_OBJECT)
+
+#define GARROW_RECORD_BATCH_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+ GARROW_TYPE_RECORD_BATCH, \
+ GArrowRecordBatchPrivate))
+
+static void
+garrow_record_batch_finalize(GObject *object)
+{
+ GArrowRecordBatchPrivate *priv;
+
+ priv = GARROW_RECORD_BATCH_GET_PRIVATE(object);
+
+ priv->record_batch = nullptr;
+
+ G_OBJECT_CLASS(garrow_record_batch_parent_class)->finalize(object);
+}
+
+static void
+garrow_record_batch_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GArrowRecordBatchPrivate *priv;
+
+ priv = GARROW_RECORD_BATCH_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_RECORD_BATCH:
+ priv->record_batch =
+ *static_cast<std::shared_ptr<arrow::RecordBatch> *>(g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_record_batch_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_record_batch_init(GArrowRecordBatch *object)
+{
+}
+
+static void
+garrow_record_batch_class_init(GArrowRecordBatchClass *klass)
+{
+ GObjectClass *gobject_class;
+ GParamSpec *spec;
+
+ gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->finalize = garrow_record_batch_finalize;
+ gobject_class->set_property = garrow_record_batch_set_property;
+ gobject_class->get_property = garrow_record_batch_get_property;
+
+ spec = g_param_spec_pointer("record-batch",
+ "RecordBatch",
+ "The raw std::shared<arrow::RecordBatch> *",
+ static_cast<GParamFlags>(G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_RECORD_BATCH, spec);
+}
+
+/**
+ * garrow_record_batch_new:
+ * @schema: The schema of the record batch.
+ * @n_rows: The number of the rows in the record batch.
+ * @columns: (element-type GArrowArray): The columns in the record batch.
+ *
+ * Returns: A newly created #GArrowRecordBatch.
+ */
+GArrowRecordBatch *
+garrow_record_batch_new(GArrowSchema *schema,
+ guint32 n_rows,
+ GList *columns)
+{
+ std::vector<std::shared_ptr<arrow::Array>> arrow_columns;
+ for (GList *node = columns; node; node = node->next) {
+ GArrowArray *column = GARROW_ARRAY(node->data);
+ arrow_columns.push_back(garrow_array_get_raw(column));
+ }
+
+ auto arrow_record_batch =
+ std::make_shared<arrow::RecordBatch>(garrow_schema_get_raw(schema),
+ n_rows,
+ arrow_columns);
+ return garrow_record_batch_new_raw(&arrow_record_batch);
+}
+
+/**
+ * garrow_record_batch_get_schema:
+ * @record_batch: A #GArrowRecordBatch.
+ *
+ * Returns: (transfer full): The schema of the record batch.
+ */
+GArrowSchema *
+garrow_record_batch_get_schema(GArrowRecordBatch *record_batch)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ auto arrow_schema = arrow_record_batch->schema();
+ return garrow_schema_new_raw(&arrow_schema);
+}
+
+/**
+ * garrow_record_batch_get_column:
+ * @record_batch: A #GArrowRecordBatch.
+ * @i: The index of the target column.
+ *
+ * Returns: (transfer full): The i-th column in the record batch.
+ */
+GArrowArray *
+garrow_record_batch_get_column(GArrowRecordBatch *record_batch,
+ guint i)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ auto arrow_column = arrow_record_batch->column(i);
+ return garrow_array_new_raw(&arrow_column);
+}
+
+/**
+ * garrow_record_batch_get_columns:
+ * @record_batch: A #GArrowRecordBatch.
+ *
+ * Returns: (element-type GArrowArray) (transfer full):
+ * The columns in the record batch.
+ */
+GList *
+garrow_record_batch_get_columns(GArrowRecordBatch *record_batch)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+
+ GList *columns = NULL;
+ for (auto arrow_column : arrow_record_batch->columns()) {
+ GArrowArray *column = garrow_array_new_raw(&arrow_column);
+ columns = g_list_prepend(columns, column);
+ }
+
+ return g_list_reverse(columns);
+}
+
+/**
+ * garrow_record_batch_get_column_name:
+ * @record_batch: A #GArrowRecordBatch.
+ * @i: The index of the target column.
+ *
+ * Returns: The name of the i-th column in the record batch.
+ */
+const gchar *
+garrow_record_batch_get_column_name(GArrowRecordBatch *record_batch,
+ guint i)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ return arrow_record_batch->column_name(i).c_str();
+}
+
+/**
+ * garrow_record_batch_get_n_columns:
+ * @record_batch: A #GArrowRecordBatch.
+ *
+ * Returns: The number of columns in the record batch.
+ */
+guint
+garrow_record_batch_get_n_columns(GArrowRecordBatch *record_batch)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ return arrow_record_batch->num_columns();
+}
+
+/**
+ * garrow_record_batch_get_n_rows:
+ * @record_batch: A #GArrowRecordBatch.
+ *
+ * Returns: The number of rows in the record batch.
+ */
+gint64
+garrow_record_batch_get_n_rows(GArrowRecordBatch *record_batch)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ return arrow_record_batch->num_rows();
+}
+
+/**
+ * garrow_record_batch_slice:
+ * @record_batch: A #GArrowRecordBatch.
+ * @offset: The offset of sub #GArrowRecordBatch.
+ * @length: The length of sub #GArrowRecordBatch.
+ *
+ * Returns: (transfer full): The sub #GArrowRecordBatch. It covers
+ * only from `offset` to `offset + length` range. The sub
+ * #GArrowRecordBatch shares values with the base
+ * #GArrowRecordBatch.
+ */
+GArrowRecordBatch *
+garrow_record_batch_slice(GArrowRecordBatch *record_batch,
+ gint64 offset,
+ gint64 length)
+{
+ const auto arrow_record_batch = garrow_record_batch_get_raw(record_batch);
+ auto arrow_sub_record_batch = arrow_record_batch->Slice(offset, length);
+ return garrow_record_batch_new_raw(&arrow_sub_record_batch);
+}
+
+G_END_DECLS
+
+GArrowRecordBatch *
+garrow_record_batch_new_raw(std::shared_ptr<arrow::RecordBatch> *arrow_record_batch)
+{
+ auto record_batch =
+ GARROW_RECORD_BATCH(g_object_new(GARROW_TYPE_RECORD_BATCH,
+ "record-batch", arrow_record_batch,
+ NULL));
+ return record_batch;
+}
+
+std::shared_ptr<arrow::RecordBatch>
+garrow_record_batch_get_raw(GArrowRecordBatch *record_batch)
+{
+ GArrowRecordBatchPrivate *priv;
+
+ priv = GARROW_RECORD_BATCH_GET_PRIVATE(record_batch);
+ return priv->record_batch;
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/record-batch.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/record-batch.h b/c_glib/arrow-glib/record-batch.h
new file mode 100644
index 0000000..92eee4d
--- /dev/null
+++ b/c_glib/arrow-glib/record-batch.h
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/array.h>
+#include <arrow-glib/schema.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_RECORD_BATCH \
+ (garrow_record_batch_get_type())
+#define GARROW_RECORD_BATCH(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_RECORD_BATCH, \
+ GArrowRecordBatch))
+#define GARROW_RECORD_BATCH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_RECORD_BATCH, \
+ GArrowRecordBatchClass))
+#define GARROW_IS_RECORD_BATCH(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_RECORD_BATCH))
+#define GARROW_IS_RECORD_BATCH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_RECORD_BATCH))
+#define GARROW_RECORD_BATCH_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_RECORD_BATCH, \
+ GArrowRecordBatchClass))
+
+typedef struct _GArrowRecordBatch GArrowRecordBatch;
+typedef struct _GArrowRecordBatchClass GArrowRecordBatchClass;
+
+/**
+ * GArrowRecordBatch:
+ *
+ * It wraps `arrow::RecordBatch`.
+ */
+struct _GArrowRecordBatch
+{
+ /*< private >*/
+ GObject parent_instance;
+};
+
+struct _GArrowRecordBatchClass
+{
+ GObjectClass parent_class;
+};
+
+GType garrow_record_batch_get_type(void) G_GNUC_CONST;
+
+GArrowRecordBatch *garrow_record_batch_new(GArrowSchema *schema,
+ guint32 n_rows,
+ GList *columns);
+
+GArrowSchema *garrow_record_batch_get_schema (GArrowRecordBatch *record_batch);
+GArrowArray *garrow_record_batch_get_column (GArrowRecordBatch *record_batch,
+ guint i);
+GList *garrow_record_batch_get_columns (GArrowRecordBatch *record_batch);
+const gchar *garrow_record_batch_get_column_name(GArrowRecordBatch *record_batch,
+ guint i);
+guint garrow_record_batch_get_n_columns (GArrowRecordBatch *record_batch);
+gint64 garrow_record_batch_get_n_rows (GArrowRecordBatch *record_batch);
+GArrowRecordBatch *garrow_record_batch_slice (GArrowRecordBatch *record_batch,
+ gint64 offset,
+ gint64 length);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/record-batch.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/record-batch.hpp b/c_glib/arrow-glib/record-batch.hpp
new file mode 100644
index 0000000..2e4fe03
--- /dev/null
+++ b/c_glib/arrow-glib/record-batch.hpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow/api.h>
+
+#include <arrow-glib/record-batch.h>
+
+GArrowRecordBatch *garrow_record_batch_new_raw(std::shared_ptr<arrow::RecordBatch> *arrow_record_batch);
+std::shared_ptr<arrow::RecordBatch> garrow_record_batch_get_raw(GArrowRecordBatch *record_batch);
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/schema.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/schema.cpp b/c_glib/arrow-glib/schema.cpp
new file mode 100644
index 0000000..4d5ae5a
--- /dev/null
+++ b/c_glib/arrow-glib/schema.cpp
@@ -0,0 +1,245 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/field.hpp>
+#include <arrow-glib/schema.hpp>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: schema
+ * @short_description: Schema class
+ *
+ * #GArrowSchema is a class for schema. Schema is metadata of a
+ * table. It has zero or more #GArrowFields.
+ */
+
+typedef struct GArrowSchemaPrivate_ {
+ std::shared_ptr<arrow::Schema> schema;
+} GArrowSchemaPrivate;
+
+enum {
+ PROP_0,
+ PROP_SCHEMA
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowSchema,
+ garrow_schema,
+ G_TYPE_OBJECT)
+
+#define GARROW_SCHEMA_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+ GARROW_TYPE_SCHEMA, \
+ GArrowSchemaPrivate))
+
+static void
+garrow_schema_finalize(GObject *object)
+{
+ GArrowSchemaPrivate *priv;
+
+ priv = GARROW_SCHEMA_GET_PRIVATE(object);
+
+ priv->schema = nullptr;
+
+ G_OBJECT_CLASS(garrow_schema_parent_class)->finalize(object);
+}
+
+static void
+garrow_schema_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GArrowSchemaPrivate *priv;
+
+ priv = GARROW_SCHEMA_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_SCHEMA:
+ priv->schema =
+ *static_cast<std::shared_ptr<arrow::Schema> *>(g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_schema_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_schema_init(GArrowSchema *object)
+{
+}
+
+static void
+garrow_schema_class_init(GArrowSchemaClass *klass)
+{
+ GObjectClass *gobject_class;
+ GParamSpec *spec;
+
+ gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->finalize = garrow_schema_finalize;
+ gobject_class->set_property = garrow_schema_set_property;
+ gobject_class->get_property = garrow_schema_get_property;
+
+ spec = g_param_spec_pointer("schema",
+ "Schema",
+ "The raw std::shared<arrow::Schema> *",
+ static_cast<GParamFlags>(G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_SCHEMA, spec);
+}
+
+/**
+ * garrow_schema_new:
+ * @fields: (element-type GArrowField): The fields of the schema.
+ *
+ * Returns: A newly created #GArrowSchema.
+ */
+GArrowSchema *
+garrow_schema_new(GList *fields)
+{
+ std::vector<std::shared_ptr<arrow::Field>> arrow_fields;
+ for (GList *node = fields; node; node = node->next) {
+ GArrowField *field = GARROW_FIELD(node->data);
+ arrow_fields.push_back(garrow_field_get_raw(field));
+ }
+
+ auto arrow_schema = std::make_shared<arrow::Schema>(arrow_fields);
+ return garrow_schema_new_raw(&arrow_schema);
+}
+
+/**
+ * garrow_schema_get_field:
+ * @schema: A #GArrowSchema.
+ * @i: The index of the target field.
+ *
+ * Returns: (transfer full): The i-th field of the schema.
+ */
+GArrowField *
+garrow_schema_get_field(GArrowSchema *schema, guint i)
+{
+ const auto arrow_schema = garrow_schema_get_raw(schema);
+ auto arrow_field = arrow_schema->field(i);
+ return garrow_field_new_raw(&arrow_field);
+}
+
+/**
+ * garrow_schema_get_field_by_name:
+ * @schema: A #GArrowSchema.
+ * @name: The name of the field to be found.
+ *
+ * Returns: (transfer full): The found field or %NULL.
+ */
+GArrowField *
+garrow_schema_get_field_by_name(GArrowSchema *schema,
+ const gchar *name)
+{
+ const auto arrow_schema = garrow_schema_get_raw(schema);
+ auto arrow_field = arrow_schema->GetFieldByName(std::string(name));
+ if (arrow_field == nullptr) {
+ return NULL;
+ } else {
+ return garrow_field_new_raw(&arrow_field);
+ }
+}
+
+/**
+ * garrow_schema_n_fields:
+ * @schema: A #GArrowSchema.
+ *
+ * Returns: The number of fields of the schema.
+ */
+guint
+garrow_schema_n_fields(GArrowSchema *schema)
+{
+ const auto arrow_schema = garrow_schema_get_raw(schema);
+ return arrow_schema->num_fields();
+}
+
+/**
+ * garrow_schema_get_fields:
+ * @schema: A #GArrowSchema.
+ *
+ * Returns: (element-type GArrowField) (transfer full):
+ * The fields of the schema.
+ */
+GList *
+garrow_schema_get_fields(GArrowSchema *schema)
+{
+ const auto arrow_schema = garrow_schema_get_raw(schema);
+
+ GList *fields = NULL;
+ for (auto arrow_field : arrow_schema->fields()) {
+ GArrowField *field = garrow_field_new_raw(&arrow_field);
+ fields = g_list_prepend(fields, field);
+ }
+
+ return g_list_reverse(fields);
+}
+
+/**
+ * garrow_schema_to_string:
+ * @schema: A #GArrowSchema.
+ *
+ * Returns: The string representation of the schema.
+ */
+gchar *
+garrow_schema_to_string(GArrowSchema *schema)
+{
+ const auto arrow_schema = garrow_schema_get_raw(schema);
+ return g_strdup(arrow_schema->ToString().c_str());
+}
+
+G_END_DECLS
+
+GArrowSchema *
+garrow_schema_new_raw(std::shared_ptr<arrow::Schema> *arrow_schema)
+{
+ auto schema = GARROW_SCHEMA(g_object_new(GARROW_TYPE_SCHEMA,
+ "schema", arrow_schema,
+ NULL));
+ return schema;
+}
+
+std::shared_ptr<arrow::Schema>
+garrow_schema_get_raw(GArrowSchema *schema)
+{
+ GArrowSchemaPrivate *priv;
+
+ priv = GARROW_SCHEMA_GET_PRIVATE(schema);
+ return priv->schema;
+}
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/schema.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/schema.h b/c_glib/arrow-glib/schema.h
new file mode 100644
index 0000000..7615634
--- /dev/null
+++ b/c_glib/arrow-glib/schema.h
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/field.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_SCHEMA \
+ (garrow_schema_get_type())
+#define GARROW_SCHEMA(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_SCHEMA, \
+ GArrowSchema))
+#define GARROW_SCHEMA_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_SCHEMA, \
+ GArrowSchemaClass))
+#define GARROW_IS_SCHEMA(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_SCHEMA))
+#define GARROW_IS_SCHEMA_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_SCHEMA))
+#define GARROW_SCHEMA_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_SCHEMA, \
+ GArrowSchemaClass))
+
+typedef struct _GArrowSchema GArrowSchema;
+typedef struct _GArrowSchemaClass GArrowSchemaClass;
+
+/**
+ * GArrowSchema:
+ *
+ * It wraps `arrow::Schema`.
+ */
+struct _GArrowSchema
+{
+ /*< private >*/
+ GObject parent_instance;
+};
+
+struct _GArrowSchemaClass
+{
+ GObjectClass parent_class;
+};
+
+GType garrow_schema_get_type (void) G_GNUC_CONST;
+
+GArrowSchema *garrow_schema_new (GList *fields);
+
+GArrowField *garrow_schema_get_field (GArrowSchema *schema,
+ guint i);
+GArrowField *garrow_schema_get_field_by_name(GArrowSchema *schema,
+ const gchar *name);
+
+guint garrow_schema_n_fields (GArrowSchema *schema);
+GList *garrow_schema_get_fields (GArrowSchema *schema);
+
+gchar *garrow_schema_to_string (GArrowSchema *schema);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/schema.hpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/schema.hpp b/c_glib/arrow-glib/schema.hpp
new file mode 100644
index 0000000..0d02534
--- /dev/null
+++ b/c_glib/arrow-glib/schema.hpp
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow/api.h>
+
+#include <arrow-glib/schema.h>
+
+GArrowSchema *garrow_schema_new_raw(std::shared_ptr<arrow::Schema> *arrow_schema);
+std::shared_ptr<arrow::Schema> garrow_schema_get_raw(GArrowSchema *schema);
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-array-builder.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-array-builder.cpp b/c_glib/arrow-glib/string-array-builder.cpp
new file mode 100644
index 0000000..ebad53a
--- /dev/null
+++ b/c_glib/arrow-glib/string-array-builder.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array-builder.hpp>
+#include <arrow-glib/string-array-builder.h>
+#include <arrow-glib/error.hpp>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: string-array-builder
+ * @short_description: UTF-8 encoded string array builder class
+ *
+ * #GArrowStringArrayBuilder is the class to create a new
+ * #GArrowStringArray.
+ */
+
+G_DEFINE_TYPE(GArrowStringArrayBuilder,
+ garrow_string_array_builder,
+ GARROW_TYPE_BINARY_ARRAY_BUILDER)
+
+static void
+garrow_string_array_builder_init(GArrowStringArrayBuilder *builder)
+{
+}
+
+static void
+garrow_string_array_builder_class_init(GArrowStringArrayBuilderClass *klass)
+{
+}
+
+/**
+ * garrow_string_array_builder_new:
+ *
+ * Returns: A newly created #GArrowStringArrayBuilder.
+ */
+GArrowStringArrayBuilder *
+garrow_string_array_builder_new(void)
+{
+ auto memory_pool = arrow::default_memory_pool();
+ auto arrow_builder =
+ std::make_shared<arrow::StringBuilder>(memory_pool);
+ auto builder =
+ GARROW_STRING_ARRAY_BUILDER(g_object_new(GARROW_TYPE_STRING_ARRAY_BUILDER,
+ "array-builder", &arrow_builder,
+ NULL));
+ return builder;
+}
+
+/**
+ * garrow_string_array_builder_append:
+ * @builder: A #GArrowStringArrayBuilder.
+ * @value: A string value.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ */
+gboolean
+garrow_string_array_builder_append(GArrowStringArrayBuilder *builder,
+ const gchar *value,
+ GError **error)
+{
+ auto arrow_builder =
+ static_cast<arrow::StringBuilder *>(
+ garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)).get());
+
+ auto status = arrow_builder->Append(value,
+ static_cast<gint32>(strlen(value)));
+ if (status.ok()) {
+ return TRUE;
+ } else {
+ garrow_error_set(error, status, "[string-array-builder][append]");
+ return FALSE;
+ }
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-array-builder.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-array-builder.h b/c_glib/arrow-glib/string-array-builder.h
new file mode 100644
index 0000000..f370ed9
--- /dev/null
+++ b/c_glib/arrow-glib/string-array-builder.h
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/binary-array-builder.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRING_ARRAY_BUILDER \
+ (garrow_string_array_builder_get_type())
+#define GARROW_STRING_ARRAY_BUILDER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRING_ARRAY_BUILDER, \
+ GArrowStringArrayBuilder))
+#define GARROW_STRING_ARRAY_BUILDER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRING_ARRAY_BUILDER, \
+ GArrowStringArrayBuilderClass))
+#define GARROW_IS_STRING_ARRAY_BUILDER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRING_ARRAY_BUILDER))
+#define GARROW_IS_STRING_ARRAY_BUILDER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRING_ARRAY_BUILDER))
+#define GARROW_STRING_ARRAY_BUILDER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRING_ARRAY_BUILDER, \
+ GArrowStringArrayBuilderClass))
+
+typedef struct _GArrowStringArrayBuilder GArrowStringArrayBuilder;
+typedef struct _GArrowStringArrayBuilderClass GArrowStringArrayBuilderClass;
+
+/**
+ * GArrowStringArrayBuilder:
+ *
+ * It wraps `arrow::StringBuilder`.
+ */
+struct _GArrowStringArrayBuilder
+{
+ /*< private >*/
+ GArrowBinaryArrayBuilder parent_instance;
+};
+
+struct _GArrowStringArrayBuilderClass
+{
+ GArrowBinaryArrayBuilderClass parent_class;
+};
+
+GType garrow_string_array_builder_get_type(void) G_GNUC_CONST;
+
+GArrowStringArrayBuilder *garrow_string_array_builder_new(void);
+
+gboolean garrow_string_array_builder_append(GArrowStringArrayBuilder *builder,
+ const gchar *value,
+ GError **error);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-array.cpp b/c_glib/arrow-glib/string-array.cpp
new file mode 100644
index 0000000..329c742
--- /dev/null
+++ b/c_glib/arrow-glib/string-array.cpp
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array.hpp>
+#include <arrow-glib/string-array.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: string-array
+ * @short_description: UTF-8 encoded string array class
+ *
+ * #GArrowStringArray is a class for UTF-8 encoded string array. It
+ * can store zero or more UTF-8 encoded string data.
+ *
+ * #GArrowStringArray is immutable. You need to use
+ * #GArrowStringArrayBuilder to create a new array.
+ */
+
+G_DEFINE_TYPE(GArrowStringArray, \
+ garrow_string_array, \
+ GARROW_TYPE_BINARY_ARRAY)
+
+static void
+garrow_string_array_init(GArrowStringArray *object)
+{
+}
+
+static void
+garrow_string_array_class_init(GArrowStringArrayClass *klass)
+{
+}
+
+/**
+ * garrow_string_array_get_string:
+ * @array: A #GArrowStringArray.
+ * @i: The index of the target value.
+ *
+ * Returns: The i-th UTF-8 encoded string.
+ */
+gchar *
+garrow_string_array_get_string(GArrowStringArray *array,
+ gint64 i)
+{
+ auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+ auto arrow_string_array =
+ static_cast<arrow::StringArray *>(arrow_array.get());
+ gint32 length;
+ auto value =
+ reinterpret_cast<const gchar *>(arrow_string_array->GetValue(i, &length));
+ return g_strndup(value, length);
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-array.h b/c_glib/arrow-glib/string-array.h
new file mode 100644
index 0000000..41a53cd
--- /dev/null
+++ b/c_glib/arrow-glib/string-array.h
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/binary-array.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRING_ARRAY \
+ (garrow_string_array_get_type())
+#define GARROW_STRING_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRING_ARRAY, \
+ GArrowStringArray))
+#define GARROW_STRING_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRING_ARRAY, \
+ GArrowStringArrayClass))
+#define GARROW_IS_STRING_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRING_ARRAY))
+#define GARROW_IS_STRING_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRING_ARRAY))
+#define GARROW_STRING_ARRAY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRING_ARRAY, \
+ GArrowStringArrayClass))
+
+typedef struct _GArrowStringArray GArrowStringArray;
+typedef struct _GArrowStringArrayClass GArrowStringArrayClass;
+
+/**
+ * GArrowStringArray:
+ *
+ * It wraps `arrow::StringArray`.
+ */
+struct _GArrowStringArray
+{
+ /*< private >*/
+ GArrowBinaryArray parent_instance;
+};
+
+struct _GArrowStringArrayClass
+{
+ GArrowBinaryArrayClass parent_class;
+};
+
+GType garrow_string_array_get_type(void) G_GNUC_CONST;
+
+gchar *garrow_string_array_get_string(GArrowStringArray *array,
+ gint64 i);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-data-type.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-data-type.cpp b/c_glib/arrow-glib/string-data-type.cpp
new file mode 100644
index 0000000..96a31bf
--- /dev/null
+++ b/c_glib/arrow-glib/string-data-type.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/string-data-type.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: string-data-type
+ * @short_description: UTF-8 encoded string data type
+ *
+ * #GArrowStringDataType is a class for UTF-8 encoded string data
+ * type.
+ */
+
+G_DEFINE_TYPE(GArrowStringDataType, \
+ garrow_string_data_type, \
+ GARROW_TYPE_DATA_TYPE)
+
+static void
+garrow_string_data_type_init(GArrowStringDataType *object)
+{
+}
+
+static void
+garrow_string_data_type_class_init(GArrowStringDataTypeClass *klass)
+{
+}
+
+/**
+ * garrow_string_data_type_new:
+ *
+ * Returns: The newly created UTF-8 encoded string data type.
+ */
+GArrowStringDataType *
+garrow_string_data_type_new(void)
+{
+ auto arrow_data_type = arrow::utf8();
+
+ GArrowStringDataType *data_type =
+ GARROW_STRING_DATA_TYPE(g_object_new(GARROW_TYPE_STRING_DATA_TYPE,
+ "data-type", &arrow_data_type,
+ NULL));
+ return data_type;
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/string-data-type.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/string-data-type.h b/c_glib/arrow-glib/string-data-type.h
new file mode 100644
index 0000000..d10a325
--- /dev/null
+++ b/c_glib/arrow-glib/string-data-type.h
@@ -0,0 +1,69 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/data-type.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRING_DATA_TYPE \
+ (garrow_string_data_type_get_type())
+#define GARROW_STRING_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRING_DATA_TYPE, \
+ GArrowStringDataType))
+#define GARROW_STRING_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRING_DATA_TYPE, \
+ GArrowStringDataTypeClass))
+#define GARROW_IS_STRING_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRING_DATA_TYPE))
+#define GARROW_IS_STRING_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRING_DATA_TYPE))
+#define GARROW_STRING_DATA_TYPE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRING_DATA_TYPE, \
+ GArrowStringDataTypeClass))
+
+typedef struct _GArrowStringDataType GArrowStringDataType;
+typedef struct _GArrowStringDataTypeClass GArrowStringDataTypeClass;
+
+/**
+ * GArrowStringDataType:
+ *
+ * It wraps `arrow::StringType`.
+ */
+struct _GArrowStringDataType
+{
+ /*< private >*/
+ GArrowDataType parent_instance;
+};
+
+struct _GArrowStringDataTypeClass
+{
+ GArrowDataTypeClass parent_class;
+};
+
+GType garrow_string_data_type_get_type (void) G_GNUC_CONST;
+GArrowStringDataType *garrow_string_data_type_new (void);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-array-builder.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-array-builder.cpp b/c_glib/arrow-glib/struct-array-builder.cpp
new file mode 100644
index 0000000..2453a5b
--- /dev/null
+++ b/c_glib/arrow-glib/struct-array-builder.cpp
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array-builder.hpp>
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/error.hpp>
+#include <arrow-glib/field.hpp>
+#include <arrow-glib/struct-array-builder.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: struct-array-builder
+ * @short_description: Struct array builder class
+ * @include: arrow-glib/arrow-glib.h
+ *
+ * #GArrowStructArrayBuilder is the class to create a new
+ * #GArrowStructArray.
+ */
+
+G_DEFINE_TYPE(GArrowStructArrayBuilder,
+ garrow_struct_array_builder,
+ GARROW_TYPE_ARRAY_BUILDER)
+
+static void
+garrow_struct_array_builder_init(GArrowStructArrayBuilder *builder)
+{
+}
+
+static void
+garrow_struct_array_builder_class_init(GArrowStructArrayBuilderClass *klass)
+{
+}
+
+/**
+ * garrow_struct_array_builder_new:
+ * @data_type: #GArrowStructDataType for the struct.
+ * @field_builders: (element-type GArrowArray): #GArrowArrayBuilders
+ * for fields.
+ *
+ * Returns: A newly created #GArrowStructArrayBuilder.
+ */
+GArrowStructArrayBuilder *
+garrow_struct_array_builder_new(GArrowStructDataType *data_type,
+ GList *field_builders)
+{
+ auto memory_pool = arrow::default_memory_pool();
+ auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type));
+ std::vector<std::shared_ptr<arrow::ArrayBuilder>> arrow_field_builders;
+ for (GList *node = field_builders; node; node = g_list_next(node)) {
+ auto field_builder = static_cast<GArrowArrayBuilder *>(node->data);
+ auto arrow_field_builder = garrow_array_builder_get_raw(field_builder);
+ arrow_field_builders.push_back(arrow_field_builder);
+ }
+
+ auto arrow_struct_builder =
+ std::make_shared<arrow::StructBuilder>(memory_pool,
+ arrow_data_type,
+ arrow_field_builders);
+ std::shared_ptr<arrow::ArrayBuilder> arrow_builder = arrow_struct_builder;
+ auto builder = garrow_array_builder_new_raw(&arrow_builder);
+ return GARROW_STRUCT_ARRAY_BUILDER(builder);
+}
+
+/**
+ * garrow_struct_array_builder_append:
+ * @builder: A #GArrowStructArrayBuilder.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * It appends a new struct element. To append a new struct element,
+ * you need to call this function then append struct element field
+ * values to all `field_builder`s. `field_value`s are the
+ * #GArrowArrayBuilder specified to constructor. You can get
+ * `field_builder` by garrow_struct_array_builder_get_field_builder()
+ * or garrow_struct_array_builder_get_field_builders().
+ *
+ * |[<!-- language="C" -->
+ * // TODO
+ * ]|
+ */
+gboolean
+garrow_struct_array_builder_append(GArrowStructArrayBuilder *builder,
+ GError **error)
+{
+ auto arrow_builder =
+ static_cast<arrow::StructBuilder *>(
+ garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)).get());
+
+ auto status = arrow_builder->Append();
+ if (status.ok()) {
+ return TRUE;
+ } else {
+ garrow_error_set(error, status, "[struct-array-builder][append]");
+ return FALSE;
+ }
+}
+
+/**
+ * garrow_struct_array_builder_append_null:
+ * @builder: A #GArrowStructArrayBuilder.
+ * @error: (nullable): Return location for a #GError or %NULL.
+ *
+ * Returns: %TRUE on success, %FALSE if there was an error.
+ *
+ * It appends a new NULL element.
+ */
+gboolean
+garrow_struct_array_builder_append_null(GArrowStructArrayBuilder *builder,
+ GError **error)
+{
+ auto arrow_builder =
+ static_cast<arrow::StructBuilder *>(
+ garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)).get());
+
+ auto status = arrow_builder->AppendNull();
+ if (status.ok()) {
+ return TRUE;
+ } else {
+ garrow_error_set(error, status, "[struct-array-builder][append-null]");
+ return FALSE;
+ }
+}
+
+/**
+ * garrow_struct_array_builder_get_field_builder:
+ * @builder: A #GArrowStructArrayBuilder.
+ * @i: The index of the field in the struct.
+ *
+ * Returns: (transfer full): The #GArrowArrayBuilder for the i-th field.
+ */
+GArrowArrayBuilder *
+garrow_struct_array_builder_get_field_builder(GArrowStructArrayBuilder *builder,
+ gint i)
+{
+ auto arrow_builder =
+ static_cast<arrow::StructBuilder *>(
+ garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)).get());
+ auto arrow_field_builder = arrow_builder->field_builder(i);
+ return garrow_array_builder_new_raw(&arrow_field_builder);
+}
+
+/**
+ * garrow_struct_array_builder_get_field_builders:
+ * @builder: A #GArrowStructArrayBuilder.
+ *
+ * Returns: (element-type GArrowArray) (transfer full):
+ * The #GArrowArrayBuilder for all fields.
+ */
+GList *
+garrow_struct_array_builder_get_field_builders(GArrowStructArrayBuilder *builder)
+{
+ auto arrow_struct_builder =
+ static_cast<arrow::StructBuilder *>(
+ garrow_array_builder_get_raw(GARROW_ARRAY_BUILDER(builder)).get());
+
+ GList *field_builders = NULL;
+ for (auto arrow_field_builder : arrow_struct_builder->field_builders()) {
+ auto field_builder = garrow_array_builder_new_raw(&arrow_field_builder);
+ field_builders = g_list_prepend(field_builders, field_builder);
+ }
+
+ return g_list_reverse(field_builders);
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-array-builder.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-array-builder.h b/c_glib/arrow-glib/struct-array-builder.h
new file mode 100644
index 0000000..7dd8662
--- /dev/null
+++ b/c_glib/arrow-glib/struct-array-builder.h
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/array-builder.h>
+#include <arrow-glib/struct-data-type.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRUCT_ARRAY_BUILDER \
+ (garrow_struct_array_builder_get_type())
+#define GARROW_STRUCT_ARRAY_BUILDER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRUCT_ARRAY_BUILDER, \
+ GArrowStructArrayBuilder))
+#define GARROW_STRUCT_ARRAY_BUILDER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRUCT_ARRAY_BUILDER, \
+ GArrowStructArrayBuilderClass))
+#define GARROW_IS_STRUCT_ARRAY_BUILDER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRUCT_ARRAY_BUILDER))
+#define GARROW_IS_STRUCT_ARRAY_BUILDER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRUCT_ARRAY_BUILDER))
+#define GARROW_STRUCT_ARRAY_BUILDER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRUCT_ARRAY_BUILDER, \
+ GArrowStructArrayBuilderClass))
+
+typedef struct _GArrowStructArrayBuilder GArrowStructArrayBuilder;
+typedef struct _GArrowStructArrayBuilderClass GArrowStructArrayBuilderClass;
+
+/**
+ * GArrowStructArrayBuilder:
+ *
+ * It wraps `arrow::StructBuilder`.
+ */
+struct _GArrowStructArrayBuilder
+{
+ /*< private >*/
+ GArrowArrayBuilder parent_instance;
+};
+
+struct _GArrowStructArrayBuilderClass
+{
+ GArrowArrayBuilderClass parent_class;
+};
+
+GType garrow_struct_array_builder_get_type(void) G_GNUC_CONST;
+
+GArrowStructArrayBuilder *garrow_struct_array_builder_new(GArrowStructDataType *data_type,
+ GList *field_builders);
+
+gboolean garrow_struct_array_builder_append(GArrowStructArrayBuilder *builder,
+ GError **error);
+gboolean garrow_struct_array_builder_append_null(GArrowStructArrayBuilder *builder,
+ GError **error);
+
+GArrowArrayBuilder *garrow_struct_array_builder_get_field_builder(GArrowStructArrayBuilder *builder,
+ gint i);
+GList *garrow_struct_array_builder_get_field_builders(GArrowStructArrayBuilder *builder);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-array.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-array.cpp b/c_glib/arrow-glib/struct-array.cpp
new file mode 100644
index 0000000..14c2d17
--- /dev/null
+++ b/c_glib/arrow-glib/struct-array.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/array.hpp>
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/struct-array.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: struct-array
+ * @short_description: Struct array class
+ * @include: arrow-glib/arrow-glib.h
+ *
+ * #GArrowStructArray is a class for struct array. It can store zero
+ * or more structs. One struct has zero or more fields.
+ *
+ * #GArrowStructArray is immutable. You need to use
+ * #GArrowStructArrayBuilder to create a new array.
+ */
+
+G_DEFINE_TYPE(GArrowStructArray, \
+ garrow_struct_array, \
+ GARROW_TYPE_ARRAY)
+
+static void
+garrow_struct_array_init(GArrowStructArray *object)
+{
+}
+
+static void
+garrow_struct_array_class_init(GArrowStructArrayClass *klass)
+{
+}
+
+/**
+ * garrow_struct_array_get_field
+ * @array: A #GArrowStructArray.
+ * @i: The index of the field in the struct.
+ *
+ * Returns: (transfer full): The i-th field.
+ */
+GArrowArray *
+garrow_struct_array_get_field(GArrowStructArray *array,
+ gint i)
+{
+ auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+ auto arrow_struct_array =
+ static_cast<arrow::StructArray *>(arrow_array.get());
+ auto arrow_field = arrow_struct_array->field(i);
+ return garrow_array_new_raw(&arrow_field);
+}
+
+/**
+ * garrow_struct_array_get_fields
+ * @array: A #GArrowStructArray.
+ *
+ * Returns: (element-type GArrowArray) (transfer full):
+ * The fields in the struct.
+ */
+GList *
+garrow_struct_array_get_fields(GArrowStructArray *array)
+{
+ const auto arrow_array = garrow_array_get_raw(GARROW_ARRAY(array));
+ const auto arrow_struct_array =
+ static_cast<const arrow::StructArray *>(arrow_array.get());
+
+ GList *fields = NULL;
+ for (auto arrow_field : arrow_struct_array->fields()) {
+ GArrowArray *field = garrow_array_new_raw(&arrow_field);
+ fields = g_list_prepend(fields, field);
+ }
+
+ return g_list_reverse(fields);
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-array.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-array.h b/c_glib/arrow-glib/struct-array.h
new file mode 100644
index 0000000..f96e9d4
--- /dev/null
+++ b/c_glib/arrow-glib/struct-array.h
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/array.h>
+#include <arrow-glib/data-type.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRUCT_ARRAY \
+ (garrow_struct_array_get_type())
+#define GARROW_STRUCT_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRUCT_ARRAY, \
+ GArrowStructArray))
+#define GARROW_STRUCT_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRUCT_ARRAY, \
+ GArrowStructArrayClass))
+#define GARROW_IS_STRUCT_ARRAY(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRUCT_ARRAY))
+#define GARROW_IS_STRUCT_ARRAY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRUCT_ARRAY))
+#define GARROW_STRUCT_ARRAY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRUCT_ARRAY, \
+ GArrowStructArrayClass))
+
+typedef struct _GArrowStructArray GArrowStructArray;
+typedef struct _GArrowStructArrayClass GArrowStructArrayClass;
+
+/**
+ * GArrowStructArray:
+ *
+ * It wraps `arrow::StructArray`.
+ */
+struct _GArrowStructArray
+{
+ /*< private >*/
+ GArrowArray parent_instance;
+};
+
+struct _GArrowStructArrayClass
+{
+ GArrowArrayClass parent_class;
+};
+
+GType garrow_struct_array_get_type(void) G_GNUC_CONST;
+
+GArrowArray *garrow_struct_array_get_field(GArrowStructArray *array,
+ gint i);
+GList *garrow_struct_array_get_fields(GArrowStructArray *array);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-data-type.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-data-type.cpp b/c_glib/arrow-glib/struct-data-type.cpp
new file mode 100644
index 0000000..9a4f2a2
--- /dev/null
+++ b/c_glib/arrow-glib/struct-data-type.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/data-type.hpp>
+#include <arrow-glib/field.hpp>
+#include <arrow-glib/struct-data-type.h>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: struct-data-type
+ * @short_description: Struct data type
+ *
+ * #GArrowStructDataType is a class for struct data type.
+ */
+
+G_DEFINE_TYPE(GArrowStructDataType, \
+ garrow_struct_data_type, \
+ GARROW_TYPE_DATA_TYPE)
+
+static void
+garrow_struct_data_type_init(GArrowStructDataType *object)
+{
+}
+
+static void
+garrow_struct_data_type_class_init(GArrowStructDataTypeClass *klass)
+{
+}
+
+/**
+ * garrow_struct_data_type_new:
+ * @fields: (element-type GArrowField): The fields of the struct.
+ *
+ * Returns: The newly created struct data type.
+ */
+GArrowStructDataType *
+garrow_struct_data_type_new(GList *fields)
+{
+ std::vector<std::shared_ptr<arrow::Field>> arrow_fields;
+ for (GList *node = fields; node; node = g_list_next(node)) {
+ auto field = GARROW_FIELD(node->data);
+ auto arrow_field = garrow_field_get_raw(field);
+ arrow_fields.push_back(arrow_field);
+ }
+
+ auto arrow_data_type = std::make_shared<arrow::StructType>(arrow_fields);
+ GArrowStructDataType *data_type =
+ GARROW_STRUCT_DATA_TYPE(g_object_new(GARROW_TYPE_STRUCT_DATA_TYPE,
+ "data-type", &arrow_data_type,
+ NULL));
+ return data_type;
+}
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/struct-data-type.h
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/struct-data-type.h b/c_glib/arrow-glib/struct-data-type.h
new file mode 100644
index 0000000..0a2c743
--- /dev/null
+++ b/c_glib/arrow-glib/struct-data-type.h
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <arrow-glib/data-type.h>
+#include <arrow-glib/field.h>
+
+G_BEGIN_DECLS
+
+#define GARROW_TYPE_STRUCT_DATA_TYPE \
+ (garrow_struct_data_type_get_type())
+#define GARROW_STRUCT_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GARROW_TYPE_STRUCT_DATA_TYPE, \
+ GArrowStructDataType))
+#define GARROW_STRUCT_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ GARROW_TYPE_STRUCT_DATA_TYPE, \
+ GArrowStructDataTypeClass))
+#define GARROW_IS_STRUCT_DATA_TYPE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GARROW_TYPE_STRUCT_DATA_TYPE))
+#define GARROW_IS_STRUCT_DATA_TYPE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ GARROW_TYPE_STRUCT_DATA_TYPE))
+#define GARROW_STRUCT_DATA_TYPE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GARROW_TYPE_STRUCT_DATA_TYPE, \
+ GArrowStructDataTypeClass))
+
+typedef struct _GArrowStructDataType GArrowStructDataType;
+typedef struct _GArrowStructDataTypeClass GArrowStructDataTypeClass;
+
+/**
+ * GArrowStructDataType:
+ *
+ * It wraps `arrow::StructType`.
+ */
+struct _GArrowStructDataType
+{
+ /*< private >*/
+ GArrowDataType parent_instance;
+};
+
+struct _GArrowStructDataTypeClass
+{
+ GArrowDataTypeClass parent_class;
+};
+
+GType garrow_struct_data_type_get_type (void) G_GNUC_CONST;
+
+GArrowStructDataType *garrow_struct_data_type_new(GList *fields);
+
+G_END_DECLS
http://git-wip-us.apache.org/repos/asf/arrow/blob/39c7274f/c_glib/arrow-glib/table.cpp
----------------------------------------------------------------------
diff --git a/c_glib/arrow-glib/table.cpp b/c_glib/arrow-glib/table.cpp
new file mode 100644
index 0000000..2410e76
--- /dev/null
+++ b/c_glib/arrow-glib/table.cpp
@@ -0,0 +1,240 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <arrow-glib/column.hpp>
+#include <arrow-glib/schema.hpp>
+#include <arrow-glib/table.hpp>
+
+G_BEGIN_DECLS
+
+/**
+ * SECTION: table
+ * @short_description: Table class
+ *
+ * #GArrowTable is a class for table. Table has zero or more
+ * #GArrowColumns and zero or more records.
+ */
+
+typedef struct GArrowTablePrivate_ {
+ std::shared_ptr<arrow::Table> table;
+} GArrowTablePrivate;
+
+enum {
+ PROP_0,
+ PROP_TABLE
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE(GArrowTable,
+ garrow_table,
+ G_TYPE_OBJECT)
+
+#define GARROW_TABLE_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+ GARROW_TYPE_TABLE, \
+ GArrowTablePrivate))
+
+static void
+garrow_table_dispose(GObject *object)
+{
+ GArrowTablePrivate *priv;
+
+ priv = GARROW_TABLE_GET_PRIVATE(object);
+
+ priv->table = nullptr;
+
+ G_OBJECT_CLASS(garrow_table_parent_class)->dispose(object);
+}
+
+static void
+garrow_table_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GArrowTablePrivate *priv;
+
+ priv = GARROW_TABLE_GET_PRIVATE(object);
+
+ switch (prop_id) {
+ case PROP_TABLE:
+ priv->table =
+ *static_cast<std::shared_ptr<arrow::Table> *>(g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_table_get_property(GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+garrow_table_init(GArrowTable *object)
+{
+}
+
+static void
+garrow_table_class_init(GArrowTableClass *klass)
+{
+ GObjectClass *gobject_class;
+ GParamSpec *spec;
+
+ gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = garrow_table_dispose;
+ gobject_class->set_property = garrow_table_set_property;
+ gobject_class->get_property = garrow_table_get_property;
+
+ spec = g_param_spec_pointer("table",
+ "Table",
+ "The raw std::shared<arrow::Table> *",
+ static_cast<GParamFlags>(G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(gobject_class, PROP_TABLE, spec);
+}
+
+/**
+ * garrow_table_new:
+ * @name: The name of the table.
+ * @schema: The schema of the table.
+ * @columns: (element-type GArrowColumn): The columns of the table.
+ *
+ * Returns: A newly created #GArrowTable.
+ */
+GArrowTable *
+garrow_table_new(const gchar *name,
+ GArrowSchema *schema,
+ GList *columns)
+{
+ std::vector<std::shared_ptr<arrow::Column>> arrow_columns;
+ for (GList *node = columns; node; node = node->next) {
+ GArrowColumn *column = GARROW_COLUMN(node->data);
+ arrow_columns.push_back(garrow_column_get_raw(column));
+ }
+
+ auto arrow_table =
+ std::make_shared<arrow::Table>(name,
+ garrow_schema_get_raw(schema),
+ arrow_columns);
+ return garrow_table_new_raw(&arrow_table);
+}
+
+/**
+ * garrow_table_get_name:
+ * @table: A #GArrowTable.
+ *
+ * Returns: The name of the table.
+ */
+const gchar *
+garrow_table_get_name(GArrowTable *table)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ return arrow_table->name().c_str();
+}
+
+/**
+ * garrow_table_get_schema:
+ * @table: A #GArrowTable.
+ *
+ * Returns: (transfer full): The schema of the table.
+ */
+GArrowSchema *
+garrow_table_get_schema(GArrowTable *table)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ auto arrow_schema = arrow_table->schema();
+ return garrow_schema_new_raw(&arrow_schema);
+}
+
+/**
+ * garrow_table_get_column:
+ * @table: A #GArrowTable.
+ * @i: The index of the target column.
+ *
+ * Returns: (transfer full): The i-th column in the table.
+ */
+GArrowColumn *
+garrow_table_get_column(GArrowTable *table,
+ guint i)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ auto arrow_column = arrow_table->column(i);
+ return garrow_column_new_raw(&arrow_column);
+}
+
+/**
+ * garrow_table_get_n_columns:
+ * @table: A #GArrowTable.
+ *
+ * Returns: The number of columns in the table.
+ */
+guint
+garrow_table_get_n_columns(GArrowTable *table)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ return arrow_table->num_columns();
+}
+
+/**
+ * garrow_table_get_n_rows:
+ * @table: A #GArrowTable.
+ *
+ * Returns: The number of rows in the table.
+ */
+guint64
+garrow_table_get_n_rows(GArrowTable *table)
+{
+ const auto arrow_table = garrow_table_get_raw(table);
+ return arrow_table->num_rows();
+}
+
+G_END_DECLS
+
+GArrowTable *
+garrow_table_new_raw(std::shared_ptr<arrow::Table> *arrow_table)
+{
+ auto table = GARROW_TABLE(g_object_new(GARROW_TYPE_TABLE,
+ "table", arrow_table,
+ NULL));
+ return table;
+}
+
+std::shared_ptr<arrow::Table>
+garrow_table_get_raw(GArrowTable *table)
+{
+ GArrowTablePrivate *priv;
+
+ priv = GARROW_TABLE_GET_PRIVATE(table);
+ return priv->table;
+}