OmniSciDB  94e8789169
 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() {
39  // Unencoded strings have no min/max.
40  if (type.is_string() && type.get_compression() == kENCODING_NONE) {
41  return "type: " + sqlType.get_type_name() + " numBytes: " + to_string(numBytes) +
42  " numElements " + to_string(numElements) + " min: <invalid>" +
43  " max: <invalid>" + " has_nulls: " + to_string(chunkStats.has_nulls);
44  } else if (type.is_string()) {
45  return "type: " + sqlType.get_type_name() + " numBytes: " + to_string(numBytes) +
46  " numElements " + to_string(numElements) +
47  " min: " + to_string(chunkStats.min.intval) +
48  " max: " + to_string(chunkStats.max.intval) +
49  " has_nulls: " + to_string(chunkStats.has_nulls);
50  } else {
51  return "type: " + sqlType.get_type_name() + " numBytes: " + to_string(numBytes) +
52  " numElements " + to_string(numElements) +
53  " min: " + DatumToString(chunkStats.min, type) +
54  " max: " + DatumToString(chunkStats.max, type) +
55  " has_nulls: " + to_string(chunkStats.has_nulls);
56  }
57  }
58 
59  ChunkMetadata(const SQLTypeInfo& sql_type,
60  const size_t num_bytes,
61  const size_t num_elements,
62  const ChunkStats& chunk_stats)
63  : sqlType(sql_type)
64  , numBytes(num_bytes)
65  , numElements(num_elements)
66  , chunkStats(chunk_stats) {}
67 
69 
70  template <typename T>
71  void fillChunkStats(const T min, const T max, const bool has_nulls) {
72  chunkStats.has_nulls = has_nulls;
73  switch (sqlType.get_type()) {
74  case kBOOLEAN: {
77  break;
78  }
79  case kTINYINT: {
82  break;
83  }
84  case kSMALLINT: {
87  break;
88  }
89  case kINT: {
90  chunkStats.min.intval = min;
91  chunkStats.max.intval = max;
92  break;
93  }
94  case kBIGINT:
95  case kNUMERIC:
96  case kDECIMAL: {
97  chunkStats.min.bigintval = min;
98  chunkStats.max.bigintval = max;
99  break;
100  }
101  case kTIME:
102  case kTIMESTAMP:
103  case kDATE: {
104  chunkStats.min.bigintval = min;
105  chunkStats.max.bigintval = max;
106  break;
107  }
108  case kFLOAT: {
109  chunkStats.min.floatval = min;
110  chunkStats.max.floatval = max;
111  break;
112  }
113  case kDOUBLE: {
114  chunkStats.min.doubleval = min;
115  chunkStats.max.doubleval = max;
116  break;
117  }
118  case kVARCHAR:
119  case kCHAR:
120  case kTEXT:
122  chunkStats.min.intval = min;
123  chunkStats.max.intval = max;
124  }
125  break;
126  default: {
127  break;
128  }
129  }
130  }
131 
132  void fillChunkStats(const Datum min, const Datum max, const bool has_nulls) {
133  chunkStats.has_nulls = has_nulls;
134  chunkStats.min = min;
135  chunkStats.max = max;
136  }
137 
138  bool operator==(const ChunkMetadata& that) const {
139  return sqlType == that.sqlType && numBytes == that.numBytes &&
140  numElements == that.numElements &&
142  that.chunkStats.min,
145  that.chunkStats.max,
148  }
149 };
150 
151 using ChunkMetadataMap = std::map<int, std::shared_ptr<ChunkMetadata>>;
152 using ChunkMetadataVector =
153  std::vector<std::pair<ChunkKey, std::shared_ptr<ChunkMetadata>>>;
int8_t tinyintval
Definition: sqltypes.h:203
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:240
Definition: sqltypes.h:48
ChunkMetadata(const SQLTypeInfo &sql_type, const size_t num_bytes, const size_t num_elements, const ChunkStats &chunk_stats)
Definition: ChunkMetadata.h:59
void fillChunkStats(const T min, const T max, const bool has_nulls)
Definition: ChunkMetadata.h:71
bool has_nulls
Definition: ChunkMetadata.h:28
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
int32_t intval
Definition: sqltypes.h:205
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:207
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:190
int64_t bigintval
Definition: sqltypes.h:206
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
int16_t smallintval
Definition: sqltypes.h:204
Definition: sqltypes.h:51
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
std::string dump()
Definition: ChunkMetadata.h:37
std::string get_type_name() const
Definition: sqltypes.h:414
Definition: sqltypes.h:40
Definition: sqltypes.h:44
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
SQLTypeInfo sqlType
Definition: ChunkMetadata.h:32
bool operator==(const ChunkMetadata &that) const
bool is_array() const
Definition: sqltypes.h:486
double doubleval
Definition: sqltypes.h:208
size_t numElements
Definition: ChunkMetadata.h:34