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
23 #include "arrow/status.h"
24 #include "arrow/util/macros.h"
25 #include "arrow/util/visibility.h"
36 /// \brief interface for conversion of Arrays
38 /// Converters are not required to be correct for arbitrary input- only
39 /// for unconverted arrays emitted by a corresponding parser.
40 class ARROW_EXPORT Converter
{
42 virtual ~Converter() = default;
45 /// on failure, this converter may be promoted to another converter which
46 /// *can* convert the given input.
47 virtual Status
Convert(const std::shared_ptr
<Array
>& in
,
48 std::shared_ptr
<Array
>* out
) = 0;
50 std::shared_ptr
<DataType
> out_type() const { return out_type_
; }
52 MemoryPool
* pool() { return pool_
; }
55 ARROW_DISALLOW_COPY_AND_ASSIGN(Converter
);
57 Converter(MemoryPool
* pool
, const std::shared_ptr
<DataType
>& out_type
)
58 : pool_(pool
), out_type_(out_type
) {}
61 std::shared_ptr
<DataType
> out_type_
;
64 /// \brief produce a single converter to the specified out_type
65 ARROW_EXPORT Status
MakeConverter(const std::shared_ptr
<DataType
>& out_type
,
66 MemoryPool
* pool
, std::shared_ptr
<Converter
>* out
);
68 class ARROW_EXPORT PromotionGraph
{
70 virtual ~PromotionGraph() = default;
72 /// \brief produce a valid field which will be inferred as null
73 virtual std::shared_ptr
<Field
> Null(const std::string
& name
) const = 0;
75 /// \brief given an unexpected field encountered during parsing, return a type to which
76 /// it may be convertible (may return null if none is available)
77 virtual std::shared_ptr
<DataType
> Infer(
78 const std::shared_ptr
<Field
>& unexpected_field
) const = 0;
80 /// \brief given a type to which conversion failed, return a promoted type to which
81 /// conversion may succeed (may return null if none is available)
82 virtual std::shared_ptr
<DataType
> Promote(
83 const std::shared_ptr
<DataType
>& failed
,
84 const std::shared_ptr
<Field
>& unexpected_field
) const = 0;
87 ARROW_DISALLOW_COPY_AND_ASSIGN(PromotionGraph
);
88 PromotionGraph() = default;
91 ARROW_EXPORT
const PromotionGraph
* GetPromotionGraph();