OmniSciDB  06b3bd477c
 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 "Utils/ChunkIter.h"
34 
38 
39 namespace Chunk_NS {
40 
41 class Chunk {
42  public:
43  Chunk() : buffer_(nullptr), index_buf_(nullptr), column_desc_(nullptr) {}
44 
45  explicit Chunk(const ColumnDescriptor* td)
46  : buffer_(nullptr), index_buf_(nullptr), column_desc_(td) {}
47 
49  : buffer_(b), index_buf_(ib), column_desc_(td){};
50 
52 
53  const ColumnDescriptor* getColumnDesc() const { return column_desc_; }
54 
56  const std::list<const ColumnDescriptor*>& colDescs,
57  std::vector<Chunk>& chunkVec) {
58  for (auto cd : colDescs) {
59  chunkVec.emplace_back(cd);
60  }
61  }
62 
63  ChunkIter begin_iterator(const std::shared_ptr<ChunkMetadata>&,
64  int start_idx = 0,
65  int skip = 1) const;
66 
67  size_t getNumElemsForBytesInsertData(const DataBlockPtr& src_data,
68  const size_t num_elems,
69  const size_t start_idx,
70  const size_t byte_limit,
71  const bool replicating = false);
72 
73  std::shared_ptr<ChunkMetadata> appendData(DataBlockPtr& srcData,
74  const size_t numAppendElems,
75  const size_t startIdx,
76  const bool replicating = false);
77 
78  void createChunkBuffer(DataMgr* data_mgr,
79  const ChunkKey& key,
80  const MemoryLevel mem_level,
81  const int deviceId = 0,
82  const size_t page_size = 0);
83 
84  void getChunkBuffer(DataMgr* data_mgr,
85  const ChunkKey& key,
86  const MemoryLevel mem_level,
87  const int deviceId = 0,
88  const size_t num_bytes = 0,
89  const size_t num_elems = 0);
90 
91  static std::shared_ptr<Chunk> getChunk(const ColumnDescriptor* cd,
92  DataMgr* data_mgr,
93  const ChunkKey& key,
94  const MemoryLevel mem_level,
95  const int deviceId,
96  const size_t num_bytes,
97  const size_t num_elems);
98 
99  bool isChunkOnDevice(DataMgr* data_mgr,
100  const ChunkKey& key,
101  const MemoryLevel mem_level,
102  const int device_id);
103 
104  AbstractBuffer* getBuffer() const { return buffer_; }
105 
106  AbstractBuffer* getIndexBuf() const { return index_buf_; }
107 
108  void setBuffer(AbstractBuffer* b) { buffer_ = b; }
109 
111 
112  void initEncoder();
113 
114  void decompress(int8_t* compressed, VarlenDatum* result, Datum* datum) const;
115 
116  private:
120 
121  void unpinBuffer();
122 };
123 
124 } // namespace Chunk_NS
AbstractBuffer * getIndexBuf() const
Definition: Chunk.h:106
Chunk(const ColumnDescriptor *td)
Definition: Chunk.h:45
std::vector< int > ChunkKey
Definition: types.h:35
Chunk(AbstractBuffer *b, AbstractBuffer *ib, const ColumnDescriptor *td)
Definition: Chunk.h:48
const ColumnDescriptor * column_desc_
Definition: Chunk.h:119
void setIndexBuffer(AbstractBuffer *ib)
Definition: Chunk.h:110
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:108
static unsigned skip
Definition: testing.h:31
const ColumnDescriptor * getColumnDesc() const
Definition: Chunk.h:53
AbstractBuffer * buffer_
Definition: Chunk.h:117
void unpinBuffer()
Definition: Chunk.cpp:215
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:55
AbstractBuffer * getBuffer() const
Definition: Chunk.h:104
void initEncoder()
Definition: Chunk.cpp:224
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:259
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:118
std::shared_ptr< ChunkMetadata > appendData(DataBlockPtr &srcData, const size_t numAppendElems, const size_t startIdx, const bool replicating=false)
Definition: Chunk.cpp:171