Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:00

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <memory>
0021 #include <string>
0022 
0023 #include "arrow/status.h"
0024 #include "arrow/util/macros.h"
0025 #include "arrow/util/visibility.h"
0026 
0027 namespace arrow {
0028 
0029 class Array;
0030 class DataType;
0031 class Field;
0032 class MemoryPool;
0033 
0034 namespace json {
0035 
0036 /// \brief interface for conversion of Arrays
0037 ///
0038 /// Converters are not required to be correct for arbitrary input- only
0039 /// for unconverted arrays emitted by a corresponding parser.
0040 class ARROW_EXPORT Converter {
0041  public:
0042   virtual ~Converter() = default;
0043 
0044   /// convert an array
0045   /// on failure, this converter may be promoted to another converter which
0046   /// *can* convert the given input.
0047   virtual Status Convert(const std::shared_ptr<Array>& in,
0048                          std::shared_ptr<Array>* out) = 0;
0049 
0050   std::shared_ptr<DataType> out_type() const { return out_type_; }
0051 
0052   MemoryPool* pool() { return pool_; }
0053 
0054  protected:
0055   ARROW_DISALLOW_COPY_AND_ASSIGN(Converter);
0056 
0057   Converter(MemoryPool* pool, const std::shared_ptr<DataType>& out_type)
0058       : pool_(pool), out_type_(out_type) {}
0059 
0060   MemoryPool* pool_;
0061   std::shared_ptr<DataType> out_type_;
0062 };
0063 
0064 /// \brief produce a single converter to the specified out_type
0065 ARROW_EXPORT Status MakeConverter(const std::shared_ptr<DataType>& out_type,
0066                                   MemoryPool* pool, std::shared_ptr<Converter>* out);
0067 
0068 class ARROW_EXPORT PromotionGraph {
0069  public:
0070   virtual ~PromotionGraph() = default;
0071 
0072   /// \brief produce a valid field which will be inferred as null
0073   virtual std::shared_ptr<Field> Null(const std::string& name) const = 0;
0074 
0075   /// \brief given an unexpected field encountered during parsing, return a type to which
0076   /// it may be convertible (may return null if none is available)
0077   virtual std::shared_ptr<DataType> Infer(
0078       const std::shared_ptr<Field>& unexpected_field) const = 0;
0079 
0080   /// \brief given a type to which conversion failed, return a promoted type to which
0081   /// conversion may succeed (may return null if none is available)
0082   virtual std::shared_ptr<DataType> Promote(
0083       const std::shared_ptr<DataType>& failed,
0084       const std::shared_ptr<Field>& unexpected_field) const = 0;
0085 
0086  protected:
0087   ARROW_DISALLOW_COPY_AND_ASSIGN(PromotionGraph);
0088   PromotionGraph() = default;
0089 };
0090 
0091 ARROW_EXPORT const PromotionGraph* GetPromotionGraph();
0092 
0093 }  // namespace json
0094 }  // namespace arrow