]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/json/converter.h
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / cpp / src / arrow / json / converter.h
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 #pragma once
19
20 #include <memory>
21 #include <string>
22
23 #include "arrow/status.h"
24 #include "arrow/util/macros.h"
25 #include "arrow/util/visibility.h"
26
27 namespace arrow {
28
29 class Array;
30 class DataType;
31 class Field;
32 class MemoryPool;
33
34 namespace json {
35
36 /// \brief interface for conversion of Arrays
37 ///
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 {
41 public:
42 virtual ~Converter() = default;
43
44 /// convert an array
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;
49
50 std::shared_ptr<DataType> out_type() const { return out_type_; }
51
52 MemoryPool* pool() { return pool_; }
53
54 protected:
55 ARROW_DISALLOW_COPY_AND_ASSIGN(Converter);
56
57 Converter(MemoryPool* pool, const std::shared_ptr<DataType>& out_type)
58 : pool_(pool), out_type_(out_type) {}
59
60 MemoryPool* pool_;
61 std::shared_ptr<DataType> out_type_;
62 };
63
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);
67
68 class ARROW_EXPORT PromotionGraph {
69 public:
70 virtual ~PromotionGraph() = default;
71
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;
74
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;
79
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;
85
86 protected:
87 ARROW_DISALLOW_COPY_AND_ASSIGN(PromotionGraph);
88 PromotionGraph() = default;
89 };
90
91 ARROW_EXPORT const PromotionGraph* GetPromotionGraph();
92
93 } // namespace json
94 } // namespace arrow