OmniSciDB  c07336695a
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 "Shared/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  ChunkMetadata appendData(int8_t*& srcData,
49  const size_t numAppendElems,
50  const SQLTypeInfo&,
51  const bool replicating = false) override {
52  CHECK(false); // should never be called for strings
53  return ChunkMetadata{};
54  }
55 
56  ChunkMetadata appendData(const std::vector<std::string>* srcData,
57  const int start_idx,
58  const size_t numAppendElems,
59  const bool replicating = false);
60 
61  void getMetadata(ChunkMetadata& chunkMetadata) override {
62  Encoder::getMetadata(chunkMetadata); // call on parent class
63  chunkMetadata.chunkStats.min.stringval = nullptr;
64  chunkMetadata.chunkStats.max.stringval = nullptr;
65  chunkMetadata.chunkStats.has_nulls = has_nulls;
66  }
67 
68  // Only called from the executor for synthesized meta-information.
69  ChunkMetadata getMetadata(const SQLTypeInfo& ti) override {
70  auto chunk_stats = ChunkStats{};
71  chunk_stats.min.stringval = nullptr;
72  chunk_stats.max.stringval = nullptr;
73  chunk_stats.has_nulls = has_nulls;
74  ChunkMetadata chunk_metadata{ti, 0, 0, chunk_stats};
75  return chunk_metadata;
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 reduceStats(const Encoder&) override { CHECK(false); }
83 
84  void writeMetadata(FILE* f) override {
85  // assumes pointer is already in right place
86  fwrite((int8_t*)&num_elems_, sizeof(size_t), 1, f);
87  fwrite((int8_t*)&has_nulls, sizeof(bool), 1, f);
88  }
89 
90  void readMetadata(FILE* f) override {
91  // assumes pointer is already in right place
92  CHECK_NE(fread((int8_t*)&num_elems_, sizeof(size_t), size_t(1), f), size_t(0));
93  CHECK_NE(fread((int8_t*)&has_nulls, sizeof(bool), size_t(1), f), size_t(0));
94  }
95 
96  void copyMetadata(const Encoder* copyFromEncoder) override {
97  num_elems_ = copyFromEncoder->getNumElems();
98  has_nulls = static_cast<const StringNoneEncoder*>(copyFromEncoder)->has_nulls;
99  }
100 
102  void set_index_buf(AbstractBuffer* buf) { index_buf = buf; }
103 
104  private:
107  bool has_nulls;
108 
109 }; // class StringNoneEncoder
110 
111 #endif // STRING_NONE_ENCODER_H
void copyMetadata(const Encoder *copyFromEncoder) override
size_t num_elems_
Definition: Encoder.h:179
void updateStats(const int64_t, const bool) override
void writeMetadata(FILE *f) override
bool has_nulls
Definition: ChunkMetadata.h:28
void set_index_buf(AbstractBuffer *buf)
ChunkStats chunkStats
Definition: ChunkMetadata.h:35
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:873
AbstractBuffer * index_buf
#define CHECK_NE(x, y)
Definition: Logger.h:196
virtual void getMetadata(ChunkMetadata &chunkMetadata)
Definition: Encoder.cpp:227
void reduceStats(const Encoder &) override
AbstractBuffer * get_index_buf() const
StringNoneEncoder(AbstractBuffer *buffer)
An AbstractBuffer is a unit of data management for a data manager.
std::string * stringval
Definition: sqltypes.h:131
ChunkMetadata getMetadata(const SQLTypeInfo &ti) override
StringOffsetT last_offset
void getMetadata(ChunkMetadata &chunkMetadata) override
size_t getNumElems() const
Definition: Encoder.h:175
#define CHECK(condition)
Definition: Logger.h:187
void readMetadata(FILE *f) override
ChunkMetadata appendData(int8_t *&srcData, const size_t numAppendElems, const SQLTypeInfo &, const bool replicating=false) override
void updateStats(const double, const bool) override