Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:57

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 <cstdint>
0021 #include <memory>
0022 
0023 #include "arrow/csv/options.h"
0024 #include "arrow/result.h"
0025 #include "arrow/type_fwd.h"
0026 #include "arrow/util/macros.h"
0027 #include "arrow/util/visibility.h"
0028 
0029 namespace arrow {
0030 namespace csv {
0031 
0032 class BlockParser;
0033 
0034 class ARROW_EXPORT Converter {
0035  public:
0036   Converter(const std::shared_ptr<DataType>& type, const ConvertOptions& options,
0037             MemoryPool* pool);
0038   virtual ~Converter() = default;
0039 
0040   virtual Result<std::shared_ptr<Array>> Convert(const BlockParser& parser,
0041                                                  int32_t col_index) = 0;
0042 
0043   std::shared_ptr<DataType> type() const { return type_; }
0044 
0045   // Create a Converter for the given data type
0046   static Result<std::shared_ptr<Converter>> Make(
0047       const std::shared_ptr<DataType>& type, const ConvertOptions& options,
0048       MemoryPool* pool = default_memory_pool());
0049 
0050  protected:
0051   ARROW_DISALLOW_COPY_AND_ASSIGN(Converter);
0052 
0053   virtual Status Initialize() = 0;
0054 
0055   // CAUTION: ConvertOptions can grow large (if it customizes hundreds or
0056   // thousands of columns), so avoid copying it in each Converter.
0057   const ConvertOptions& options_;
0058   MemoryPool* pool_;
0059   std::shared_ptr<DataType> type_;
0060 };
0061 
0062 class ARROW_EXPORT DictionaryConverter : public Converter {
0063  public:
0064   DictionaryConverter(const std::shared_ptr<DataType>& value_type,
0065                       const ConvertOptions& options, MemoryPool* pool);
0066 
0067   // If the dictionary length goes above this value, conversion will fail
0068   // with Status::IndexError.
0069   virtual void SetMaxCardinality(int32_t max_length) = 0;
0070 
0071   // Create a Converter for the given dictionary value type.
0072   // The dictionary index type will always be Int32.
0073   static Result<std::shared_ptr<DictionaryConverter>> Make(
0074       const std::shared_ptr<DataType>& value_type, const ConvertOptions& options,
0075       MemoryPool* pool = default_memory_pool());
0076 
0077  protected:
0078   std::shared_ptr<DataType> value_type_;
0079 };
0080 
0081 }  // namespace csv
0082 }  // namespace arrow