]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/ruby/red-arrow/ext/arrow/values.cpp
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 "converters.hpp"
24 class ValuesBuilder
: private Converter
, public arrow::ArrayVisitor
{
26 explicit ValuesBuilder(VALUE values
)
32 void build(const arrow::Array
& array
, VALUE rb_array
) {
34 check_status(array
.Accept(this),
40 void build(const arrow::ChunkedArray
& chunked_array
,
41 VALUE rb_chunked_array
) {
43 for (const auto& array
: chunked_array
.chunks()) {
44 check_status(array
->Accept(this),
45 "[chunked-array][values]");
46 row_offset_
+= array
->length();
53 arrow::Status Visit(const arrow::TYPE ## Array& array) override { \
55 return arrow::Status::OK(); \
74 VISIT(FixedSizeBinary
)
96 template <typename ArrayType
>
97 void convert(const ArrayType
& array
) {
98 const auto n
= array
.length();
99 if (array
.null_count() > 0) {
100 for (int64_t i
= 0, ii
= row_offset_
; i
< n
; ++i
, ++ii
) {
102 if (!array
.IsNull(i
)) {
103 value
= convert_value(array
, i
);
105 rb_ary_store(values_
, ii
, value
);
108 for (int64_t i
= 0, ii
= row_offset_
; i
< n
; ++i
, ++ii
) {
109 rb_ary_store(values_
, ii
, convert_value(array
, i
));
114 // Destination for converted values.
117 // The current row offset.
123 array_values(VALUE rb_array
) {
124 auto garrow_array
= GARROW_ARRAY(RVAL2GOBJ(rb_array
));
125 auto array
= garrow_array_get_raw(garrow_array
).get();
126 const auto n_rows
= array
->length();
127 auto values
= rb_ary_new_capa(n_rows
);
130 ValuesBuilder
builder(values
);
131 builder
.build(*array
, rb_array
);
132 } catch (rb::State
& state
) {
140 chunked_array_values(VALUE rb_chunked_array
) {
141 auto garrow_chunked_array
=
142 GARROW_CHUNKED_ARRAY(RVAL2GOBJ(rb_chunked_array
));
144 garrow_chunked_array_get_raw(garrow_chunked_array
).get();
145 const auto n_rows
= chunked_array
->length();
146 auto values
= rb_ary_new_capa(n_rows
);
149 ValuesBuilder
builder(values
);
150 builder
.build(*chunked_array
, rb_chunked_array
);
151 } catch (rb::State
& state
) {