OmniSciDB  fe05a0c208
 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() const {
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  std::string toString() const { return dump(); }
60 
61  ChunkMetadata(const SQLTypeInfo& sql_type,
62  const size_t num_bytes,
63  const size_t num_elements,
64  const ChunkStats& chunk_stats)
65  : sqlType(sql_type)
66  , numBytes(num_bytes)
67  , numElements(num_elements)
68  , chunkStats(chunk_stats) {}
69 
71 
72  template <typename T>
73  void fillChunkStats(const T min, const T max, const bool has_nulls) {
74  chunkStats.has_nulls = has_nulls;
75  switch (sqlType.get_type()) {
76  case kBOOLEAN: {
79  break;
80  }
81  case kTINYINT: {
84  break;
85  }
86  case kSMALLINT: {
89  break;
90  }
91  case kINT: {
92  chunkStats.min.intval = min;
93  chunkStats.max.intval = max;
94  break;
95  }
96  case kBIGINT:
97  case kNUMERIC:
98  case kDECIMAL: {
99  chunkStats.min.bigintval = min;
100  chunkStats.max.bigintval = max;
101  break;
102  }
103  case kTIME:
104  case kTIMESTAMP:
105  case kDATE: {
106  chunkStats.min.bigintval = min;
107  chunkStats.max.bigintval = max;
108  break;
109  }
110  case kFLOAT: {
111  chunkStats.min.floatval = min;
112  chunkStats.max.floatval = max;
113  break;
114  }
115  case kDOUBLE: {
116  chunkStats.min.doubleval = min;
117  chunkStats.max.doubleval = max;
118  break;
119  }
120  case kVARCHAR:
121  case kCHAR:
122  case kTEXT:
124  chunkStats.min.intval = min;
125  chunkStats.max.intval = max;
126  }
127  break;
128  default: {
129  break;
130  }
131  }
132  }
133 
134  void fillChunkStats(const Datum min, const Datum max, const bool has_nulls) {
135  chunkStats.has_nulls = has_nulls;
136  chunkStats.min = min;
137  chunkStats.max = max;
138  }
139 
140  bool operator==(const ChunkMetadata& that) const {
141  return sqlType == that.sqlType && numBytes == that.numBytes &&
142  numElements == that.numElements &&
144  that.chunkStats.min,
147  that.chunkStats.max,
150  }
151 };
152 
153 using ChunkMetadataMap = std::map<int, std::shared_ptr<ChunkMetadata>>;
154 using ChunkMetadataVector =
155  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:356
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:61
void fillChunkStats(const T min, const T max, const bool has_nulls)
Definition: ChunkMetadata.h:73
bool has_nulls
Definition: ChunkMetadata.h:28
std::string dump() const
Definition: ChunkMetadata.h:37
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
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:306
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:51
Definition: sqltypes.h:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
std::string toString() const
Definition: ChunkMetadata.h:59
std::string get_type_name() const
Definition: sqltypes.h:417
Definition: sqltypes.h:40
Definition: sqltypes.h:44
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
SQLTypeInfo sqlType
Definition: ChunkMetadata.h:32
bool operator==(const ChunkMetadata &that) const
bool is_array() const
Definition: sqltypes.h:497
double doubleval
Definition: sqltypes.h:211
size_t numElements
Definition: ChunkMetadata.h:34