OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Chunk.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 
23 #pragma once
24 
25 #include <list>
26 #include <memory>
27 
29 #include "DataMgr/AbstractBuffer.h"
30 #include "DataMgr/ChunkMetadata.h"
31 #include "DataMgr/DataMgr.h"
32 #include "Shared/sqltypes.h"
33 #include "Shared/toString.h"
34 #include "Utils/ChunkIter.h"
35 
39 
40 namespace Chunk_NS {
41 
42 class Chunk {
43  public:
44  Chunk() : buffer_(nullptr), index_buf_(nullptr), column_desc_(nullptr) {}
45 
46  explicit Chunk(const ColumnDescriptor* td)
47  : buffer_(nullptr), index_buf_(nullptr), column_desc_(td) {}
48 
50  : buffer_(b), index_buf_(ib), column_desc_(td){};
51 
53 
54  const ColumnDescriptor* getColumnDesc() const { return column_desc_; }
55 
56  void setColumnDesc(const ColumnDescriptor* cd) { column_desc_ = cd; }
57 
59  const std::list<const ColumnDescriptor*>& colDescs,
60  std::vector<Chunk>& chunkVec) {
61  for (auto cd : colDescs) {
62  chunkVec.emplace_back(cd);
63  }
64  }
65 
66  ChunkIter begin_iterator(const std::shared_ptr<ChunkMetadata>&,
67  int start_idx = 0,
68  int skip = 1) const;
69 
70  size_t getNumElemsForBytesInsertData(const DataBlockPtr& src_data,
71  const size_t num_elems,
72  const size_t start_idx,
73  const size_t byte_limit,
74  const bool replicating = false);
75 
76  std::shared_ptr<ChunkMetadata> appendData(DataBlockPtr& srcData,
77  const size_t numAppendElems,
78  const size_t startIdx,
79  const bool replicating = false);
80 
81  void createChunkBuffer(DataMgr* data_mgr,
82  const ChunkKey& key,
83  const MemoryLevel mem_level,
84  const int deviceId = 0,
85  const size_t page_size = 0);
86 
87  void getChunkBuffer(DataMgr* data_mgr,
88  const ChunkKey& key,
89  const MemoryLevel mem_level,
90  const int deviceId = 0,
91  const size_t num_bytes = 0,
92  const size_t num_elems = 0);
93 
94  static std::shared_ptr<Chunk> getChunk(const ColumnDescriptor* cd,
95  DataMgr* data_mgr,
96  const ChunkKey& key,
97  const MemoryLevel mem_level,
98  const int deviceId,
99  const size_t num_bytes,
100  const size_t num_elems);
101 
102  bool isChunkOnDevice(DataMgr* data_mgr,
103  const ChunkKey& key,
104  const MemoryLevel mem_level,
105  const int device_id);
106 
107  AbstractBuffer* getBuffer() const { return buffer_; }
108 
109  AbstractBuffer* getIndexBuf() const { return index_buf_; }
110 
111  void setBuffer(AbstractBuffer* b) { buffer_ = b; }
112 
114 
115  void initEncoder();
116 
117  void decompress(int8_t* compressed, VarlenDatum* result, Datum* datum) const;
118 
119  std::string toString() const {
120  return ::typeName(this) + "(buffer=" + ::toString(buffer_) +
121  ", index_buf=" + ::toString(index_buf_) +
122  ", column_desc=" + ::toString(column_desc_) + ")";
123  }
124 
125  private:
129 
130  void unpinBuffer();
131 };
132 
133 } // namespace Chunk_NS
AbstractBuffer * getIndexBuf() const
Definition: Chunk.h:109
Chunk(const ColumnDescriptor *td)
Definition: Chunk.h:46
std::vector< int > ChunkKey
Definition: types.h:37
Chunk(AbstractBuffer *b, AbstractBuffer *ib, const ColumnDescriptor *td)
Definition: Chunk.h:49
const ColumnDescriptor * column_desc_
Definition: Chunk.h:128
void setIndexBuffer(AbstractBuffer *ib)
Definition: Chunk.h:113
void getChunkBuffer(DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int deviceId=0, const size_t num_bytes=0, const size_t num_elems=0)
Definition: Chunk.cpp:58
Constants for Builtin SQL Types supported by OmniSci.
void setBuffer(AbstractBuffer *b)
Definition: Chunk.h:111
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:54
AbstractBuffer * buffer_
Definition: Chunk.h:126
void unpinBuffer()
Definition: Chunk.cpp:216
bool isChunkOnDevice(DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int device_id)
Definition: Chunk.cpp:40
static std::shared_ptr< Chunk > getChunk(const ColumnDescriptor *cd, DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int deviceId, const size_t num_bytes, const size_t num_elems)
Definition: Chunk.cpp:28
An AbstractBuffer is a unit of data management for a data manager.
specifies the content in-memory of a row in the column metadata table
static void translateColumnDescriptorsToChunkVec(const std::list< const ColumnDescriptor * > &colDescs, std::vector< Chunk > &chunkVec)
Definition: Chunk.h:58
AbstractBuffer * getBuffer() const
Definition: Chunk.h:107
std::string typeName(const T *v)
Definition: toString.h:88
void initEncoder()
Definition: Chunk.cpp:225
void setColumnDesc(const ColumnDescriptor *cd)
Definition: Chunk.h:56
std::string toString() const
Definition: Chunk.h:119
size_t getNumElemsForBytesInsertData(const DataBlockPtr &src_data, const size_t num_elems, const size_t start_idx, const size_t byte_limit, const bool replicating=false)
Definition: Chunk.cpp:128
ChunkIter begin_iterator(const std::shared_ptr< ChunkMetadata > &, int start_idx=0, int skip=1) const
Definition: Chunk.cpp:260
void createChunkBuffer(DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int deviceId=0, const size_t page_size=0)
Definition: Chunk.cpp:110
void decompress(int8_t *compressed, VarlenDatum *result, Datum *datum) const
AbstractBuffer * index_buf_
Definition: Chunk.h:127
std::shared_ptr< ChunkMetadata > appendData(DataBlockPtr &srcData, const size_t numAppendElems, const size_t startIdx, const bool replicating=false)
Definition: Chunk.cpp:171