]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/c_glib/arrow-dataset-glib/fragment.cpp
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / c_glib / arrow-dataset-glib / fragment.cpp
CommitLineData
1d09f67e
TL
1/*
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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
17 * under the License.
18 */
19
20#include <arrow-glib/record-batch.hpp>
21#include <arrow-glib/schema.hpp>
22
23#include <arrow-dataset-glib/fragment.hpp>
24
25G_BEGIN_DECLS
26
27/**
28 * SECTION: fragment
29 * @section_id: fragment
30 * @title: Fragment classes
31 * @include: arrow-dataset-glib/arrow-dataset-glib.h
32 *
33 * #GADatasetFragment is a base class for all fragment classes.
34 *
35 * #GADatasetInMemoryFragment is a class for in-memory fragment.
36 *
37 * Since: 4.0.0
38 */
39
40/* arrow::dataset::Fragment */
41
42typedef struct GADatasetFragmentPrivate_ {
43 std::shared_ptr<arrow::dataset::Fragment> fragment;
44} GADatasetFragmentPrivate;
45
46enum {
47 PROP_FRAGMENT = 1,
48};
49
50G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE(GADatasetFragment,
51 gadataset_fragment,
52 G_TYPE_OBJECT)
53
54#define GADATASET_FRAGMENT_GET_PRIVATE(obj) \
55 static_cast<GADatasetFragmentPrivate *>( \
56 gadataset_fragment_get_instance_private( \
57 GADATASET_FRAGMENT(obj)))
58
59static void
60gadataset_fragment_finalize(GObject *object)
61{
62 auto priv = GADATASET_FRAGMENT_GET_PRIVATE(object);
63
64 priv->fragment.~shared_ptr();
65
66 G_OBJECT_CLASS(gadataset_fragment_parent_class)->finalize(object);
67}
68
69static void
70gadataset_fragment_set_property(GObject *object,
71 guint prop_id,
72 const GValue *value,
73 GParamSpec *pspec)
74{
75 auto priv = GADATASET_FRAGMENT_GET_PRIVATE(object);
76
77 switch (prop_id) {
78 case PROP_FRAGMENT:
79 priv->fragment =
80 *static_cast<std::shared_ptr<arrow::dataset::Fragment> *>(
81 g_value_get_pointer(value));
82 break;
83 default:
84 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
85 break;
86 }
87}
88
89static void
90gadataset_fragment_init(GADatasetFragment *object)
91{
92 auto priv = GADATASET_FRAGMENT_GET_PRIVATE(object);
93 new(&priv->fragment) std::shared_ptr<arrow::dataset::Fragment>;
94}
95
96static void
97gadataset_fragment_class_init(GADatasetFragmentClass *klass)
98{
99 auto gobject_class = G_OBJECT_CLASS(klass);
100
101 gobject_class->finalize = gadataset_fragment_finalize;
102 gobject_class->set_property = gadataset_fragment_set_property;
103
104 GParamSpec *spec;
105 spec = g_param_spec_pointer("fragment",
106 "Fragment",
107 "The raw std::shared<arrow::dataset::Fragment> *",
108 static_cast<GParamFlags>(G_PARAM_WRITABLE |
109 G_PARAM_CONSTRUCT_ONLY));
110 g_object_class_install_property(gobject_class, PROP_FRAGMENT, spec);
111}
112
113/* arrow::dataset::InMemoryFragment */
114
115G_DEFINE_TYPE(GADatasetInMemoryFragment,
116 gadataset_in_memory_fragment,
117 GADATASET_TYPE_FRAGMENT)
118
119static void
120gadataset_in_memory_fragment_init(GADatasetInMemoryFragment *object)
121{
122}
123
124static void
125gadataset_in_memory_fragment_class_init(GADatasetInMemoryFragmentClass *klass)
126{
127}
128
129/**
130 * gadataset_in_memory_fragment_new:
131 * @schema: A #GArrowSchema.
132 * @record_batches: (array length=n_record_batches):
133 * (element-type GArrowRecordBatch): The record batches of the table.
134 * @n_record_batches: The number of record batches.
135 *
136 * Returns: A newly created #GADatasetInMemoryFragment.
137 *
138 * Since: 4.0.0
139 */
140GADatasetInMemoryFragment *
141gadataset_in_memory_fragment_new(GArrowSchema *schema,
142 GArrowRecordBatch **record_batches,
143 gsize n_record_batches)
144{
145 auto arrow_schema = garrow_schema_get_raw(schema);
146 std::vector<std::shared_ptr<arrow::RecordBatch>> arrow_record_batches;
147 arrow_record_batches.reserve(n_record_batches);
148 for (gsize i = 0; i < n_record_batches; ++i) {
149 auto arrow_record_batch = garrow_record_batch_get_raw(record_batches[i]);
150 arrow_record_batches.push_back(arrow_record_batch);
151 }
152 auto arrow_in_memory_fragment =
153 std::make_shared<arrow::dataset::InMemoryFragment>(arrow_schema,
154 arrow_record_batches);
155 return gadataset_in_memory_fragment_new_raw(&arrow_in_memory_fragment);
156}
157
158G_END_DECLS
159
160GADatasetFragment *
161gadataset_fragment_new_raw(
162 std::shared_ptr<arrow::dataset::Fragment> *arrow_fragment)
163{
164 auto fragment =
165 GADATASET_FRAGMENT(g_object_new(GADATASET_TYPE_FRAGMENT,
166 "fragment", arrow_fragment,
167 NULL));
168 return fragment;
169}
170
171std::shared_ptr<arrow::dataset::Fragment>
172gadataset_fragment_get_raw(GADatasetFragment *fragment)
173{
174 auto priv = GADATASET_FRAGMENT_GET_PRIVATE(fragment);
175 return priv->fragment;
176}
177
178GADatasetInMemoryFragment *
179gadataset_in_memory_fragment_new_raw(
180 std::shared_ptr<arrow::dataset::InMemoryFragment> *arrow_fragment)
181{
182 auto fragment =
183 GADATASET_IN_MEMORY_FRAGMENT(g_object_new(GADATASET_TYPE_IN_MEMORY_FRAGMENT,
184 "fragment", arrow_fragment,
185 NULL));
186 return fragment;
187}