OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
57  const std::list<const ColumnDescriptor*>& colDescs,
58  std::vector<Chunk>& chunkVec) {
59  for (auto cd : colDescs) {
60  chunkVec.emplace_back(cd);
61  }
62  }
63 
64  ChunkIter begin_iterator(const std::shared_ptr<ChunkMetadata>&,
65  int start_idx = 0,
66  int skip = 1) const;
67 
68  size_t getNumElemsForBytesInsertData(const DataBlockPtr& src_data,
69  const size_t num_elems,
70  const size_t start_idx,
71  const size_t byte_limit,
72  const bool replicating = false);
73 
74  std::shared_ptr<ChunkMetadata> appendData(DataBlockPtr& srcData,
75  const size_t numAppendElems,
76  const size_t startIdx,
77  const bool replicating = false);
78 
79  void createChunkBuffer(DataMgr* data_mgr,
80  const ChunkKey& key,
81  const MemoryLevel mem_level,
82  const int deviceId = 0,
83  const size_t page_size = 0);
84 
85  void getChunkBuffer(DataMgr* data_mgr,
86  const ChunkKey& key,
87  const MemoryLevel mem_level,
88  const int deviceId = 0,
89  const size_t num_bytes = 0,
90  const size_t num_elems = 0);
91 
92  static std::shared_ptr<Chunk> getChunk(const ColumnDescriptor* cd,
93  DataMgr* data_mgr,
94  const ChunkKey& key,
95  const MemoryLevel mem_level,
96  const int deviceId,
97  const size_t num_bytes,
98  const size_t num_elems);
99 
100  bool isChunkOnDevice(DataMgr* data_mgr,
101  const ChunkKey& key,
102  const MemoryLevel mem_level,
103  const int device_id);
104 
105  AbstractBuffer* getBuffer() const { return buffer_; }
106 
107  AbstractBuffer* getIndexBuf() const { return index_buf_; }
108 
109  void setBuffer(AbstractBuffer* b) { buffer_ = b; }
110 
112 
113  void initEncoder();
114 
115  void decompress(int8_t* compressed, VarlenDatum* result, Datum* datum) const;
116 
117  std::string toString() const {
118  return ::typeName(this) + "(buffer=" + ::toString(buffer_) +
119  ", index_buf=" + ::toString(index_buf_) +
120  ", column_desc=" + ::toString(column_desc_) + ")";
121  }
122 
123  private:
127 
128  void unpinBuffer();
129 };
130 
131 } // namespace Chunk_NS
AbstractBuffer * getIndexBuf() const
Definition: Chunk.h:107
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:126
void setIndexBuffer(AbstractBuffer *ib)
Definition: Chunk.h:111
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:109
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:54
AbstractBuffer * buffer_
Definition: Chunk.h:124
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:56
AbstractBuffer * getBuffer() const
Definition: Chunk.h:105
std::string typeName(const T *v)
Definition: toString.h:82
void initEncoder()
Definition: Chunk.cpp:225
std::string toString() const
Definition: Chunk.h:117
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:125
std::shared_ptr< ChunkMetadata > appendData(DataBlockPtr &srcData, const size_t numAppendElems, const size_t startIdx, const bool replicating=false)
Definition: Chunk.cpp:171