OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Encoder.cpp
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 #include "Encoder.h"
18 #include "ArrayNoneEncoder.h"
19 #include "DateDaysEncoder.h"
21 #include "FixedLengthEncoder.h"
22 #include "Logger/Logger.h"
23 #include "NoneEncoder.h"
24 #include "StringNoneEncoder.h"
25 
27  const SQLTypeInfo sqlType) {
28  switch (sqlType.get_compression()) {
29  case kENCODING_NONE: {
30  switch (sqlType.get_type()) {
31  case kBOOLEAN: {
32  return new NoneEncoder<int8_t>(buffer);
33  break;
34  }
35  case kTINYINT: {
36  return new NoneEncoder<int8_t>(buffer);
37  break;
38  }
39  case kSMALLINT: {
40  return new NoneEncoder<int16_t>(buffer);
41  break;
42  }
43  case kINT: {
44  return new NoneEncoder<int32_t>(buffer);
45  break;
46  }
47  case kBIGINT:
48  case kNUMERIC:
49  case kDECIMAL: {
50  return new NoneEncoder<int64_t>(buffer);
51  break;
52  }
53  case kFLOAT: {
54  return new NoneEncoder<float>(buffer);
55  break;
56  }
57  case kDOUBLE: {
58  return new NoneEncoder<double>(buffer);
59  break;
60  }
61  case kTEXT:
62  case kVARCHAR:
63  case kCHAR:
64  return new StringNoneEncoder(buffer);
65  case kARRAY: {
66  if (sqlType.get_size() > 0) {
67  return new FixedLengthArrayNoneEncoder(buffer, sqlType.get_size());
68  }
69  return new ArrayNoneEncoder(buffer);
70  }
71  case kTIME:
72  case kTIMESTAMP:
73  case kDATE:
74  return new NoneEncoder<int64_t>(buffer);
75  case kPOINT:
76  case kMULTIPOINT:
77  case kLINESTRING:
78  case kMULTILINESTRING:
79  case kPOLYGON:
80  case kMULTIPOLYGON:
81  return new StringNoneEncoder(buffer);
82  default: {
83  return 0;
84  }
85  }
86  break;
87  }
89  switch (sqlType.get_type()) {
90  case kDATE:
91  switch (sqlType.get_comp_param()) {
92  case 0:
93  case 32:
94  return new DateDaysEncoder<int64_t, int32_t>(buffer);
95  break;
96  case 16:
97  return new DateDaysEncoder<int64_t, int16_t>(buffer);
98  break;
99  default:
100  return 0;
101  break;
102  }
103  break;
104  default:
105  return 0;
106  break;
107  }
108  }
109  case kENCODING_FIXED: {
110  switch (sqlType.get_type()) {
111  case kSMALLINT: {
112  switch (sqlType.get_comp_param()) {
113  case 8:
114  return new FixedLengthEncoder<int16_t, int8_t>(buffer);
115  break;
116  case 16:
117  return new NoneEncoder<int16_t>(buffer);
118  break;
119  default:
120  return 0;
121  break;
122  }
123  break;
124  }
125  case kINT: {
126  switch (sqlType.get_comp_param()) {
127  case 8:
128  return new FixedLengthEncoder<int32_t, int8_t>(buffer);
129  break;
130  case 16:
131  return new FixedLengthEncoder<int32_t, int16_t>(buffer);
132  break;
133  case 32:
134  return new NoneEncoder<int32_t>(buffer);
135  break;
136  default:
137  return 0;
138  break;
139  }
140  break;
141  }
142  case kBIGINT:
143  case kNUMERIC:
144  case kDECIMAL: {
145  switch (sqlType.get_comp_param()) {
146  case 8:
147  return new FixedLengthEncoder<int64_t, int8_t>(buffer);
148  break;
149  case 16:
150  return new FixedLengthEncoder<int64_t, int16_t>(buffer);
151  break;
152  case 32:
153  return new FixedLengthEncoder<int64_t, int32_t>(buffer);
154  break;
155  case 64:
156  return new NoneEncoder<int64_t>(buffer);
157  break;
158  default:
159  return 0;
160  break;
161  }
162  break;
163  }
164  case kTIME:
165  case kTIMESTAMP:
166  case kDATE:
167  return new FixedLengthEncoder<int64_t, int32_t>(buffer);
168  break;
169  default: {
170  return 0;
171  break;
172  }
173  } // switch (sqlType)
174  break;
175  } // Case: kENCODING_FIXED
176  case kENCODING_DICT: {
177  if (sqlType.get_type() == kARRAY) {
178  CHECK(IS_STRING(sqlType.get_subtype()));
179  if (sqlType.get_size() > 0) {
180  return new FixedLengthArrayNoneEncoder(buffer, sqlType.get_size());
181  }
182  return new ArrayNoneEncoder(buffer);
183  } else {
184  CHECK(sqlType.is_string());
185  switch (sqlType.get_size()) {
186  case 1:
187  return new NoneEncoder<uint8_t>(buffer);
188  break;
189  case 2:
190  return new NoneEncoder<uint16_t>(buffer);
191  break;
192  case 4:
193  return new NoneEncoder<int32_t>(buffer);
194  break;
195  default:
196  CHECK(false);
197  break;
198  }
199  }
200  break;
201  }
202  case kENCODING_GEOINT: {
203  switch (sqlType.get_type()) {
204  case kPOINT:
205  case kMULTIPOINT:
206  case kLINESTRING:
207  case kMULTILINESTRING:
208  case kPOLYGON:
209  case kMULTIPOLYGON:
210  return new StringNoneEncoder(buffer);
211  default: {
212  return 0;
213  }
214  }
215  break;
216  }
217  default: {
218  return 0;
219  break;
220  }
221  } // switch (encodingType)
222  return 0;
223 }
224 
226  : num_elems_(0)
227  , buffer_(buffer)
228  , decimal_overflow_validator_(buffer ? buffer->getSqlType() : SQLTypeInfo())
229  , date_days_overflow_validator_(buffer ? buffer->getSqlType() : SQLTypeInfo()){};
230 
231 void Encoder::getMetadata(const std::shared_ptr<ChunkMetadata>& chunkMetadata) {
232  chunkMetadata->sqlType = buffer_->getSqlType();
233  chunkMetadata->numBytes = buffer_->size();
234  chunkMetadata->numElements = num_elems_;
235 }
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:381
HOST DEVICE int get_size() const
Definition: sqltypes.h:390
size_t num_elems_
Definition: Encoder.h:288
Definition: sqltypes.h:64
static Encoder * Create(Data_Namespace::AbstractBuffer *buffer, const SQLTypeInfo sqlType)
Definition: Encoder.cpp:26
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:380
virtual void getMetadata(const std::shared_ptr< ChunkMetadata > &chunkMetadata)
Definition: Encoder.cpp:231
Data_Namespace::AbstractBuffer * buffer_
Definition: Encoder.h:290
An AbstractBuffer is a unit of data management for a data manager.
Encoder(Data_Namespace::AbstractBuffer *buffer)
Definition: Encoder.cpp:225
Definition: sqltypes.h:67
Definition: sqltypes.h:68
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:388
Definition: sqltypes.h:56
#define IS_STRING(T)
Definition: sqltypes.h:297
unencoded fixed length array encoder
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:389
SQLTypeInfo getSqlType() const
#define CHECK(condition)
Definition: Logger.h:289
For unencoded strings.
Definition: sqltypes.h:60
bool is_string() const
Definition: sqltypes.h:576
unencoded array encoder