OmniSciDB  5ade3759e0
Chunk.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
22 #ifndef _CHUNK_H_
23 #define _CHUNK_H_
24 
25 #include <list>
26 #include <memory>
27 #include "../Catalog/ColumnDescriptor.h"
28 #include "../DataMgr/AbstractBuffer.h"
29 #include "../DataMgr/ChunkMetadata.h"
30 #include "../DataMgr/DataMgr.h"
31 #include "../Shared/sqltypes.h"
32 #include "../Utils/ChunkIter.h"
33 
37 
38 namespace Chunk_NS {
39 class Chunk;
40 };
41 
42 namespace Chunk_NS {
43 
44 class Chunk {
45  public:
46  Chunk() : buffer(nullptr), index_buf(nullptr), column_desc(nullptr) {}
47  explicit Chunk(const ColumnDescriptor* td)
48  : buffer(nullptr), index_buf(nullptr), column_desc(td) {}
50  : buffer(b), index_buf(ib), column_desc(td){};
52  const ColumnDescriptor* get_column_desc() const { return column_desc; }
54  const std::list<const ColumnDescriptor*>& colDescs,
55  std::vector<Chunk>& chunkVec) {
56  for (auto cd : colDescs) {
57  chunkVec.emplace_back(cd);
58  }
59  }
60  ChunkIter begin_iterator(const ChunkMetadata&, int start_idx = 0, int skip = 1) const;
61  size_t getNumElemsForBytesInsertData(const DataBlockPtr& src_data,
62  const size_t num_elems,
63  const size_t start_idx,
64  const size_t byte_limit,
65  const bool replicating = false);
67  const size_t numAppendElems,
68  const size_t startIdx,
69  const bool replicating = false);
70  void createChunkBuffer(DataMgr* data_mgr,
71  const ChunkKey& key,
72  const MemoryLevel mem_level,
73  const int deviceId = 0,
74  const size_t page_size = 0);
75  void getChunkBuffer(DataMgr* data_mgr,
76  const ChunkKey& key,
77  const MemoryLevel mem_level,
78  const int deviceId = 0,
79  const size_t num_bytes = 0,
80  const size_t num_elems = 0);
81  static std::shared_ptr<Chunk> getChunk(const ColumnDescriptor* cd,
82  DataMgr* data_mgr,
83  const ChunkKey& key,
84  const MemoryLevel mem_level,
85  const int deviceId,
86  const size_t num_bytes,
87  const size_t num_elems);
88  bool isChunkOnDevice(DataMgr* data_mgr,
89  const ChunkKey& key,
90  const MemoryLevel mem_level,
91  const int device_id);
92 
93  // protected:
94  AbstractBuffer* get_buffer() const { return buffer; }
95  AbstractBuffer* get_index_buf() const { return index_buf; }
96  void set_buffer(AbstractBuffer* b) { buffer = b; }
98  void init_encoder();
99  void decompress(int8_t* compressed, VarlenDatum* result, Datum* datum) const;
100 
101  private:
105  void unpin_buffer();
106 };
107 } // namespace Chunk_NS
108 
109 #endif // _CHUNK_H_
Chunk(const ColumnDescriptor *td)
Definition: Chunk.h:47
Chunk(AbstractBuffer *b, AbstractBuffer *ib, const ColumnDescriptor *td)
Definition: Chunk.h:49
const ColumnDescriptor * get_column_desc() const
Definition: Chunk.h:52
AbstractBuffer * get_index_buf() const
Definition: Chunk.h:95
void set_index_buf(AbstractBuffer *ib)
Definition: Chunk.h:97
const ColumnDescriptor * column_desc
Definition: Chunk.h:104
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:57
void init_encoder()
Definition: Chunk.cpp:221
AbstractBuffer * index_buf
Definition: Chunk.h:103
static void translateColumnDescriptorsToChunkVec(const std::list< const ColumnDescriptor *> &colDescs, std::vector< Chunk > &chunkVec)
Definition: Chunk.h:53
AbstractBuffer * get_buffer() const
Definition: Chunk.h:94
void unpin_buffer()
Definition: Chunk.cpp:212
static unsigned skip
Definition: testing.h:31
void set_buffer(AbstractBuffer *b)
Definition: Chunk.h:96
ChunkMetadata appendData(DataBlockPtr &srcData, const size_t numAppendElems, const size_t startIdx, const bool replicating=false)
Definition: Chunk.cpp:168
bool isChunkOnDevice(DataMgr *data_mgr, const ChunkKey &key, const MemoryLevel mem_level, const int device_id)
Definition: Chunk.cpp:40
AbstractBuffer * buffer
Definition: Chunk.h:102
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
ChunkIter begin_iterator(const ChunkMetadata &, int start_idx=0, int skip=1) const
Definition: Chunk.cpp:255
void decompress(int8_t *compressed, VarlenDatum *result, Datum *datum) const
std::vector< int > ChunkKey
Definition: types.h:35
FileBuffer Chunk
A Chunk is the fundamental unit of execution in Map-D.
Definition: FileMgr.h:68
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:125
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:108