OmniSciDB  8a228a1076
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: {
60  chunkStats.min.tinyintval = min;
61  chunkStats.max.tinyintval = max;
62  break;
63  }
64  case kTINYINT: {
65  chunkStats.min.tinyintval = min;
66  chunkStats.max.tinyintval = max;
67  break;
68  }
69  case kSMALLINT: {
70  chunkStats.min.smallintval = min;
71  chunkStats.max.smallintval = max;
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:
106  if (sqlType.get_compression() == kENCODING_DICT) {
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 &&
126  DatumEqual(chunkStats.min, that.chunkStats.min, sqlType) &&
127  DatumEqual(chunkStats.max, that.chunkStats.max, sqlType) &&
128  chunkStats.has_nulls == that.chunkStats.has_nulls;
129  }
130 };
131 
132 using ChunkMetadataMap = std::map<int, std::shared_ptr<ChunkMetadata>>;
133 using ChunkMetadataVector =
134  std::vector<std::pair<ChunkKey, std::shared_ptr<ChunkMetadata>>>;
int8_t tinyintval
Definition: sqltypes.h:135
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:236
Definition: sqltypes.h:51
std::map< int, std::shared_ptr< ChunkMetadata > > ChunkMetadataMap
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 EncodingType get_compression() const
Definition: sqltypes.h:267
int32_t intval
Definition: sqltypes.h:137
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)
float floatval
Definition: sqltypes.h:139
bool operator==(const ChunkMetadata &that) const
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:190
int64_t bigintval
Definition: sqltypes.h:138
int16_t smallintval
Definition: sqltypes.h:136
Definition: sqltypes.h:54
Definition: sqltypes.h:55
std::string dump()
Definition: ChunkMetadata.h:37
Definition: sqltypes.h:43
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata > >> ChunkMetadataVector
Definition: sqltypes.h:47
SQLTypeInfo sqlType
Definition: ChunkMetadata.h:32
double doubleval
Definition: sqltypes.h:140
size_t numElements
Definition: ChunkMetadata.h:34