OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TypedParquetDetectBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "DataMgr/AbstractBuffer.h"
20 
21 namespace foreign_storage {
22 
24  public:
26 
27  void read(int8_t* const destination,
28  const size_t num_bytes,
29  const size_t offset = 0,
30  const Data_Namespace::MemoryLevel destination_buffer_type =
32  const int destination_device_id = -1) override;
33 
34  void write(
35  int8_t* source,
36  const size_t num_bytes,
37  const size_t offset = 0,
38  const Data_Namespace::MemoryLevel source_buffer_type = Data_Namespace::CPU_LEVEL,
39  const int source_device_id = -1) override;
40 
41  void reserve(size_t additional_num_bytes) override;
42 
43  void append(
44  int8_t* source,
45  const size_t num_bytes,
46  const Data_Namespace::MemoryLevel source_buffer_type = Data_Namespace::CPU_LEVEL,
47  const int device_id = -1) override;
48 
49  void reserveNumElements(size_t additional_num_elements);
50 
51  int8_t* getMemoryPtr() override;
52  size_t pageCount() const override;
53  size_t pageSize() const override;
54  size_t reservedSize() const override;
55  Data_Namespace::MemoryLevel getType() const override;
56 
57  template <typename T>
58  void setConverterType(std::function<std::string(const T&)> element_to_string) {
60  std::make_unique<DataTypeToStringConverter<T>>(element_to_string);
61  }
62 
63  const std::vector<std::string>& getStrings() { return buffer_; }
64 
65  void appendValue(const std::string& value) { buffer_.push_back(value); }
66 
67  private:
69  public:
70  virtual ~AbstractDataTypeToStringConverter() = default;
71  virtual std::vector<std::string> convert(const int8_t* bytes,
72  const size_t num_bytes) = 0;
73  };
74 
75  template <typename T>
77  public:
78  DataTypeToStringConverter(std::function<std::string(const T&)> element_to_string)
79  : element_to_string_(element_to_string) {}
80 
81  std::vector<std::string> convert(const int8_t* bytes,
82  const size_t num_bytes) override {
83  CHECK(num_bytes % sizeof(T) == 0);
84  const size_t num_elements = num_bytes / sizeof(T);
85  const auto elements = reinterpret_cast<const T*>(bytes);
86  std::vector<std::string> strings;
87  strings.reserve(num_elements);
88  for (size_t i = 0; i < num_elements; ++i) {
89  strings.emplace_back(element_to_string_(elements[i]));
90  }
91  return strings;
92  }
93 
94  private:
95  std::function<std::string(const T&)> element_to_string_;
96  };
97 
98  std::vector<std::string> buffer_;
99  std::unique_ptr<AbstractDataTypeToStringConverter> data_to_string_converter_;
100 };
101 
102 } // namespace foreign_storage
std::unique_ptr< AbstractDataTypeToStringConverter > data_to_string_converter_
void append(int8_t *source, const size_t num_bytes, const Data_Namespace::MemoryLevel source_buffer_type=Data_Namespace::CPU_LEVEL, const int device_id=-1) override
An AbstractBuffer is a unit of data management for a data manager.
void reserveNumElements(size_t additional_num_elements)
void write(int8_t *source, const size_t num_bytes, const size_t offset=0, const Data_Namespace::MemoryLevel source_buffer_type=Data_Namespace::CPU_LEVEL, const int source_device_id=-1) override
Data_Namespace::MemoryLevel getType() const override
void reserve(size_t additional_num_bytes) override
virtual std::vector< std::string > convert(const int8_t *bytes, const size_t num_bytes)=0
const std::vector< std::string > & getStrings()
void read(int8_t *const destination, const size_t num_bytes, const size_t offset=0, const Data_Namespace::MemoryLevel destination_buffer_type=Data_Namespace::CPU_LEVEL, const int destination_device_id=-1) override
#define CHECK(condition)
Definition: Logger.h:289
void setConverterType(std::function< std::string(const T &)> element_to_string)