]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/r/src/scalar.cpp
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
18 #include "./arrow_types.h"
20 #if defined(ARROW_R_WITH_ARROW)
22 #include <arrow/array/array_base.h>
23 #include <arrow/array/util.h>
24 #include <arrow/scalar.h>
25 #include <arrow/type.h>
29 const char* r6_class_name
<arrow::Scalar
>::get(
30 const std::shared_ptr
<arrow::Scalar
>& scalar
) {
31 if (scalar
->type
->id() == arrow::Type::STRUCT
) {
32 return "StructScalar";
40 std::shared_ptr
<arrow::Scalar
> Array__GetScalar(const std::shared_ptr
<arrow::Array
>& x
,
42 return ValueOrStop(x
->GetScalar(i
));
46 std::string
Scalar__ToString(const std::shared_ptr
<arrow::Scalar
>& s
) {
51 std::shared_ptr
<arrow::Scalar
> StructScalar__field(
52 const std::shared_ptr
<arrow::StructScalar
>& s
, int i
) {
53 return ValueOrStop(s
->field(i
));
57 std::shared_ptr
<arrow::Scalar
> StructScalar__GetFieldByName(
58 const std::shared_ptr
<arrow::StructScalar
>& s
, const std::string
& name
) {
59 return ValueOrStop(s
->field(name
));
63 SEXP
Scalar__as_vector(const std::shared_ptr
<arrow::Scalar
>& scalar
) {
64 auto array
= ValueOrStop(arrow::MakeArrayFromScalar(*scalar
, 1, gc_memory_pool()));
66 // defined in array_to_vector.cpp
67 SEXP
Array__as_vector(const std::shared_ptr
<arrow::Array
>& array
);
68 return Array__as_vector(array
);
72 std::shared_ptr
<arrow::Array
> MakeArrayFromScalar(
73 const std::shared_ptr
<arrow::Scalar
>& scalar
, int n
) {
74 return ValueOrStop(arrow::MakeArrayFromScalar(*scalar
, n
, gc_memory_pool()));
78 bool Scalar__is_valid(const std::shared_ptr
<arrow::Scalar
>& s
) { return s
->is_valid
; }
81 std::shared_ptr
<arrow::DataType
> Scalar__type(const std::shared_ptr
<arrow::Scalar
>& s
) {
86 bool Scalar__Equals(const std::shared_ptr
<arrow::Scalar
>& lhs
,
87 const std::shared_ptr
<arrow::Scalar
>& rhs
) {
88 return lhs
->Equals(rhs
);
92 bool Scalar__ApproxEquals(const std::shared_ptr
<arrow::Scalar
>& lhs
,
93 const std::shared_ptr
<arrow::Scalar
>& rhs
) {
94 return lhs
->ApproxEquals(*rhs
);