OmniSciDB  8a228a1076
StringNoneEncoder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
24 #ifndef STRING_NONE_ENCODER_H
25 #define STRING_NONE_ENCODER_H
26 #include "Logger/Logger.h"
27 
28 #include <cassert>
29 #include <string>
30 #include <vector>
31 #include "AbstractBuffer.h"
32 #include "ChunkMetadata.h"
33 #include "Encoder.h"
34 
36 
37 class StringNoneEncoder : public Encoder {
38  public:
40  : Encoder(buffer), index_buf(nullptr), last_offset(-1), has_nulls(false) {}
41 
42  size_t getNumElemsForBytesInsertData(const std::vector<std::string>* srcData,
43  const int start_idx,
44  const size_t numAppendElems,
45  const size_t byteLimit,
46  const bool replicating = false);
47 
48  std::shared_ptr<ChunkMetadata> appendData(int8_t*& src_data,
49  const size_t num_elems_to_append,
50  const SQLTypeInfo& ti,
51  const bool replicating = false,
52  const int64_t offset = -1) override {
53  UNREACHABLE(); // should never be called for strings
54  return nullptr;
55  }
56 
57  std::shared_ptr<ChunkMetadata> appendData(const std::vector<std::string>* srcData,
58  const int start_idx,
59  const size_t numAppendElems,
60  const bool replicating = false);
61 
62  void getMetadata(const std::shared_ptr<ChunkMetadata>& chunkMetadata) override {
63  Encoder::getMetadata(chunkMetadata); // call on parent class
64  chunkMetadata->chunkStats.min.stringval = nullptr;
65  chunkMetadata->chunkStats.max.stringval = nullptr;
66  chunkMetadata->chunkStats.has_nulls = has_nulls;
67  }
68 
69  // Only called from the executor for synthesized meta-information.
70  std::shared_ptr<ChunkMetadata> getMetadata(const SQLTypeInfo& ti) override {
71  auto chunk_stats = ChunkStats{};
72  chunk_stats.min.stringval = nullptr;
73  chunk_stats.max.stringval = nullptr;
74  chunk_stats.has_nulls = has_nulls;
75  return std::make_shared<ChunkMetadata>(ti, 0, 0, chunk_stats);
76  }
77 
78  void updateStats(const int64_t, const bool) override { CHECK(false); }
79 
80  void updateStats(const double, const bool) override { CHECK(false); }
81 
82  void updateStats(const int8_t* const src_data, const size_t num_elements) override {
83  UNREACHABLE();
84  }
85 
86  void updateStats(const std::vector<std::string>* const src_data,
87  const size_t start_idx,
88  const size_t num_elements) override;
89 
90  void updateStats(const std::vector<ArrayDatum>* const src_data,
91  const size_t start_idx,
92  const size_t num_elements) override {
93  UNREACHABLE();
94  }
95 
96  void reduceStats(const Encoder&) override { CHECK(false); }
97 
98  void writeMetadata(FILE* f) override {
99  // assumes pointer is already in right place
100  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
101  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
102  }
103 
104  void readMetadata(FILE* f) override {
105  // assumes pointer is already in right place
106  CHECK_NE(fread((int8_t*)&num_elems_, sizeof(size_t), size_t(1), f), size_t(0));
107  CHECK_NE(fread((int8_t*)&has_nulls, sizeof(bool), size_t(1), f), size_t(0));
108  }
109 
110  void copyMetadata(const Encoder* copyFromEncoder) override {
111  num_elems_ = copyFromEncoder->getNumElems();
112  has_nulls = static_cast<const StringNoneEncoder*>(copyFromEncoder)->has_nulls;
113  }
114 
115  AbstractBuffer* getIndexBuf() const { return index_buf; }
117 
118  private:
121  bool has_nulls;
122 
123  void update_elem_stats(const std::string& elem);
124 
125 }; // class StringNoneEncoder
126 
127 #endif // STRING_NONE_ENCODER_H
void copyMetadata(const Encoder *copyFromEncoder) override
size_t num_elems_
Definition: Encoder.h:218
void updateStats(const int64_t, const bool) override
void writeMetadata(FILE *f) override
std::shared_ptr< ChunkMetadata > getMetadata(const SQLTypeInfo &ti) override
std::shared_ptr< ChunkMetadata > appendData(int8_t *&src_data, const size_t num_elems_to_append, const SQLTypeInfo &ti, const bool replicating=false, const int64_t offset=-1) override
#define UNREACHABLE()
Definition: Logger.h:241
size_t getNumElemsForBytesInsertData(const std::vector< std::string > *srcData, const int start_idx, const size_t numAppendElems, const size_t byteLimit, const bool replicating=false)
int32_t StringOffsetT
Definition: sqltypes.h:867
virtual void getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata)
Definition: Encoder.cpp:227
AbstractBuffer * index_buf
AbstractBuffer * getIndexBuf() const
#define CHECK_NE(x, y)
Definition: Logger.h:206
void reduceStats(const Encoder &) override
StringNoneEncoder(AbstractBuffer *buffer)
An AbstractBuffer is a unit of data management for a data manager.
std::string * stringval
Definition: sqltypes.h:143
void update_elem_stats(const std::string &elem)
StringOffsetT last_offset
void getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata) override
void updateStats(const int8_t *const src_data, const size_t num_elements) override
void updateStats(const std::vector< ArrayDatum > *const src_data, const size_t start_idx, const size_t num_elements) override
size_t getNumElems() const
Definition: Encoder.h:214
#define CHECK(condition)
Definition: Logger.h:197
void setIndexBuffer(AbstractBuffer *buf)
void readMetadata(FILE *f) override
void updateStats(const double, const bool) override