Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
cast.h
Go to the documentation of this file.
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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
16 // under the License.
17 
18 #ifndef ARROW_COMPUTE_KERNELS_CAST_H
19 #define ARROW_COMPUTE_KERNELS_CAST_H
20 
21 #include <memory>
22 
23 #include "arrow/status.h"
24 #include "arrow/util/visibility.h"
25 
26 namespace arrow {
27 
28 class Array;
29 class DataType;
30 
31 namespace compute {
32 
33 struct Datum;
34 class FunctionContext;
35 class UnaryKernel;
36 
37 struct ARROW_EXPORT CastOptions {
39  : allow_int_overflow(false),
40  allow_time_truncate(false),
41  allow_float_truncate(false) {}
42 
43  explicit CastOptions(bool safe)
44  : allow_int_overflow(!safe),
45  allow_time_truncate(!safe),
46  allow_float_truncate(!safe) {}
47 
48  static CastOptions Safe() { return CastOptions(true); }
49 
50  static CastOptions Unsafe() { return CastOptions(false); }
51 
55 };
56 
59 ARROW_EXPORT
60 Status GetCastFunction(const DataType& in_type, const std::shared_ptr<DataType>& to_type,
61  const CastOptions& options, std::unique_ptr<UnaryKernel>* kernel);
62 
72 ARROW_EXPORT
73 Status Cast(FunctionContext* context, const Array& value,
74  const std::shared_ptr<DataType>& to_type, const CastOptions& options,
75  std::shared_ptr<Array>* out);
76 
86 ARROW_EXPORT
87 Status Cast(FunctionContext* context, const Datum& value,
88  const std::shared_ptr<DataType>& to_type, const CastOptions& options,
89  Datum* out);
90 
91 } // namespace compute
92 } // namespace arrow
93 
94 #endif // ARROW_COMPUTE_KERNELS_CAST_H
static CastOptions Safe()
Definition: cast.h:48
bool allow_int_overflow
Definition: cast.h:52
Container for variables and options used by function evaluation.
Definition: context.h:47
Definition: status.h:95
static CastOptions Unsafe()
Definition: cast.h:50
Status Cast(FunctionContext *context, const Array &value, const std::shared_ptr< DataType > &to_type, const CastOptions &options, std::shared_ptr< Array > *out)
Cast from one array type to another.
bool allow_time_truncate
Definition: cast.h:53
Variant type for various Arrow C++ data structures.
Definition: kernel.h:52
Status GetCastFunction(const DataType &in_type, const std::shared_ptr< DataType > &to_type, const CastOptions &options, std::unique_ptr< UnaryKernel > *kernel)
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
bool allow_float_truncate
Definition: cast.h:54
Array base type Immutable data array with some logical type and some length.
Definition: array.h:200
CastOptions(bool safe)
Definition: cast.h:43
Definition: cast.h:37
CastOptions()
Definition: cast.h:38
Base class for all data types.
Definition: type.h:148