OmniSciDB  ab4938a6a3
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 "Shared/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  ChunkMetadata(const SQLTypeInfo& sql_type,
38  const size_t num_bytes,
39  const size_t num_elements,
40  const ChunkStats& chunk_stats)
41  : sqlType(sql_type)
42  , numBytes(num_bytes)
43  , numElements(num_elements)
44  , chunkStats(chunk_stats) {}
45 
47 
48  template <typename T>
49  void fillChunkStats(const T min, const T max, const bool has_nulls) {
50  chunkStats.has_nulls = has_nulls;
51  switch (sqlType.get_type()) {
52  case kBOOLEAN: {
53  chunkStats.min.tinyintval = min;
54  chunkStats.max.tinyintval = max;
55  break;
56  }
57  case kTINYINT: {
58  chunkStats.min.tinyintval = min;
59  chunkStats.max.tinyintval = max;
60  break;
61  }
62  case kSMALLINT: {
63  chunkStats.min.smallintval = min;
64  chunkStats.max.smallintval = max;
65  break;
66  }
67  case kINT: {
68  chunkStats.min.intval = min;
69  chunkStats.max.intval = max;
70  break;
71  }
72  case kBIGINT:
73  case kNUMERIC:
74  case kDECIMAL: {
75  chunkStats.min.bigintval = min;
76  chunkStats.max.bigintval = max;
77  break;
78  }
79  case kTIME:
80  case kTIMESTAMP:
81  case kDATE: {
82  chunkStats.min.bigintval = min;
83  chunkStats.max.bigintval = max;
84  break;
85  }
86  case kFLOAT: {
87  chunkStats.min.floatval = min;
88  chunkStats.max.floatval = max;
89  break;
90  }
91  case kDOUBLE: {
92  chunkStats.min.doubleval = min;
93  chunkStats.max.doubleval = max;
94  break;
95  }
96  case kVARCHAR:
97  case kCHAR:
98  case kTEXT:
99  if (sqlType.get_compression() == kENCODING_DICT) {
100  chunkStats.min.intval = min;
101  chunkStats.max.intval = max;
102  }
103  break;
104  default: {
105  break;
106  }
107  }
108  }
109 
110  void fillChunkStats(const Datum min, const Datum max, const bool has_nulls) {
111  chunkStats.has_nulls = has_nulls;
112  chunkStats.min = min;
113  chunkStats.max = max;
114  }
115 
116  bool operator==(const ChunkMetadata& that) const {
117  return sqlType == that.sqlType && numBytes == that.numBytes &&
118  numElements == that.numElements &&
119  DatumEqual(chunkStats.min, that.chunkStats.min, sqlType) &&
120  DatumEqual(chunkStats.max, that.chunkStats.max, sqlType) &&
121  chunkStats.has_nulls == that.chunkStats.has_nulls;
122  }
123 };
124 
125 using ChunkMetadataMap = std::map<int, std::shared_ptr<ChunkMetadata>>;
126 using ChunkMetadataVector =
127  std::vector<std::pair<ChunkKey, std::shared_ptr<ChunkMetadata>>>;
int8_t tinyintval
Definition: sqltypes.h:133
Definition: sqltypes.h:50
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:37
void fillChunkStats(const T min, const T max, const bool has_nulls)
Definition: ChunkMetadata.h:49
bool has_nulls
Definition: ChunkMetadata.h:28
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
int32_t intval
Definition: sqltypes.h:135
ChunkStats chunkStats
Definition: ChunkMetadata.h:35
void fillChunkStats(const Datum min, const Datum max, const bool has_nulls)
float floatval
Definition: sqltypes.h:137
bool operator==(const ChunkMetadata &that) const
bool DatumEqual(const Datum a, const Datum b, const SQLTypeInfo &ti)
Definition: Datum.cpp:187
int64_t bigintval
Definition: sqltypes.h:136
int16_t smallintval
Definition: sqltypes.h:134
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Definition: sqltypes.h:42
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata > >> ChunkMetadataVector
Definition: sqltypes.h:46
SQLTypeInfo sqlType
Definition: ChunkMetadata.h:32
double doubleval
Definition: sqltypes.h:138
size_t numElements
Definition: ChunkMetadata.h:34