OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChunkMetadata.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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 <cstddef>
20 #include "../Shared/sqltypes.h"
21 #include "Shared/types.h"
22 
23 #include "Logger/Logger.h"
24 
25 struct ChunkStats {
28  bool has_nulls;
29 };
30 
31 struct ChunkMetadata {
33  size_t numBytes;
34  size_t numElements;
36 
37  std::string dump() {
38  return "numBytes: " + to_string(numBytes) + " numElements " + to_string(numElements) +
39  " min: " + DatumToString(chunkStats.min, sqlType) +
40  " max: " + DatumToString(chunkStats.max, sqlType) +
41  " has_nulls: " + to_string(chunkStats.has_nulls);
42  }
43 
44  ChunkMetadata(const SQLTypeInfo& sql_type,
45  const size_t num_bytes,
46  const size_t num_elements,
47  const ChunkStats& chunk_stats)
48  : sqlType(sql_type)
49  , numBytes(num_bytes)
50  , numElements(num_elements)
51  , chunkStats(chunk_stats) {}
52 
54 
55  template <typename T>
56  void fillChunkStats(const T min, const T max, const bool has_nulls) {
57  chunkStats.has_nulls = has_nulls;
58  switch (sqlType.get_type()) {
59  case kBOOLEAN: {
62  break;
63  }
64  case kTINYINT: {
67  break;
68  }
69  case kSMALLINT: {
72  break;
73  }
74  case kINT: {
75  chunkStats.min.intval = min;
76  chunkStats.max.intval = max;
77  break;
78  }
79  case kBIGINT:
80  case kNUMERIC:
81  case kDECIMAL: {
82  chunkStats.min.bigintval = min;
83  chunkStats.max.bigintval = max;
84  break;
85  }
86  case kTIME:
87  case kTIMESTAMP:
88  case kDATE: {
89  chunkStats.min.bigintval = min;
90  chunkStats.max.bigintval = max;
91  break;
92  }
93  case kFLOAT: {
94  chunkStats.min.floatval = min;
95  chunkStats.max.floatval = max;
96  break;
97  }
98  case kDOUBLE: {
99  chunkStats.min.doubleval = min;
100  chunkStats.max.doubleval = max;
101  break;
102  }
103  case kVARCHAR:
104  case kCHAR:
105  case kTEXT:
107  chunkStats.min.intval = min;
108  chunkStats.max.intval = max;
109  }
110  break;
111  default: {
112  break;
113  }
114  }
115  }
116 
117  void fillChunkStats(const Datum min, const Datum max, const bool has_nulls) {
118  chunkStats.has_nulls = has_nulls;
119  chunkStats.min = min;
120  chunkStats.max = max;
121  }
122 
123  bool operator==(const ChunkMetadata& that) const {
124  return sqlType == that.sqlType && numBytes == that.numBytes &&
125  numElements == that.numElements &&
127  that.chunkStats.min,
130  that.chunkStats.max,
133  }
134 };
135 
136 using ChunkMetadataMap = std::map<int, std::shared_ptr<ChunkMetadata>>;
137 using ChunkMetadataVector =
138  std::vector<std::pair<ChunkKey, std::shared_ptr<ChunkMetadata>>>;
int8_t tinyintval
Definition: sqltypes.h:206
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:239
Definition: sqltypes.h:51
ChunkMetadata(const SQLTypeInfo &sql_type, const size_t num_bytes, const size_t num_elements, const ChunkStats &chunk_stats)
Definition: ChunkMetadata.h:44
void fillChunkStats(const T min, const T max, const bool has_nulls)
Definition: ChunkMetadata.h:56
bool has_nulls
Definition: ChunkMetadata.h:28
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:330
int32_t intval
Definition: sqltypes.h:208
std::string to_string(char const *&&v)
ChunkStats chunkStats
Definition: ChunkMetadata.h:35
void fillChunkStats(const Datum min, const Datum max, const bool has_nulls)
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
float floatval
Definition: sqltypes.h:210
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:189
int64_t bigintval
Definition: sqltypes.h:209
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
int16_t smallintval
Definition: sqltypes.h:207
Definition: sqltypes.h:54
Definition: sqltypes.h:55
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:338
std::string dump()
Definition: ChunkMetadata.h:37
Definition: sqltypes.h:43
Definition: sqltypes.h:47
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:703
SQLTypeInfo sqlType
Definition: ChunkMetadata.h:32
bool operator==(const ChunkMetadata &that) const
bool is_array() const
Definition: sqltypes.h:495
double doubleval
Definition: sqltypes.h:211
size_t numElements
Definition: ChunkMetadata.h:34