OmniSciDB  dfae7c3b14
ColumnFetcher.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 
17 #pragma once
18 
23 
24 namespace std {
25 template <>
26 struct hash<std::vector<int>> {
27  size_t operator()(const std::vector<int>& vec) const {
28  return vec.size() ^ boost::hash_range(vec.begin(), vec.end());
29  }
30 };
31 
32 template <>
33 struct hash<std::pair<int, int>> {
34  size_t operator()(const std::pair<int, int>& p) const {
35  return boost::hash<std::pair<int, int>>()(p);
36  }
37 };
38 
39 } // namespace std
40 
41 struct FetchResult {
42  std::vector<std::vector<const int8_t*>> col_buffers;
43  std::vector<std::vector<int64_t>> num_rows;
44  std::vector<std::vector<uint64_t>> frag_offsets;
45 };
46 
48  public:
49  ColumnFetcher(Executor* executor, const ColumnCacheMap& column_cache);
50 
52  static std::pair<const int8_t*, size_t> getOneColumnFragment(
53  Executor* executor,
54  const Analyzer::ColumnVar& hash_col,
55  const Fragmenter_Namespace::FragmentInfo& fragment,
56  const Data_Namespace::MemoryLevel effective_mem_lvl,
57  const int device_id,
58  DeviceAllocator* device_allocator,
59  std::vector<std::shared_ptr<Chunk_NS::Chunk>>& chunks_owner,
60  ColumnCacheMap& column_cache);
61 
63  static JoinColumn makeJoinColumn(
64  Executor* executor,
65  const Analyzer::ColumnVar& hash_col,
66  const std::vector<Fragmenter_Namespace::FragmentInfo>& fragments,
67  const Data_Namespace::MemoryLevel effective_mem_lvl,
68  const int device_id,
69  DeviceAllocator* device_allocator,
70  std::vector<std::shared_ptr<Chunk_NS::Chunk>>& chunks_owner,
71  std::vector<std::shared_ptr<void>>& malloc_owner,
72  ColumnCacheMap& column_cache);
73 
74  const int8_t* getOneTableColumnFragment(
75  const int table_id,
76  const int frag_id,
77  const int col_id,
78  const std::map<int, const TableFragments*>& all_tables_fragments,
79  std::list<std::shared_ptr<Chunk_NS::Chunk>>& chunk_holder,
80  std::list<ChunkIter>& chunk_iter_holder,
81  const Data_Namespace::MemoryLevel memory_level,
82  const int device_id,
83  DeviceAllocator* device_allocator) const;
84 
85  const int8_t* getAllTableColumnFragments(
86  const int table_id,
87  const int col_id,
88  const std::map<int, const TableFragments*>& all_tables_fragments,
89  const Data_Namespace::MemoryLevel memory_level,
90  const int device_id,
91  DeviceAllocator* device_allocator) const;
92 
93  const int8_t* getResultSetColumn(const InputColDescriptor* col_desc,
94  const Data_Namespace::MemoryLevel memory_level,
95  const int device_id,
96  DeviceAllocator* device_allocator) const;
97 
98  private:
99  static const int8_t* transferColumnIfNeeded(
100  const ColumnarResults* columnar_results,
101  const int col_id,
102  Data_Namespace::DataMgr* data_mgr,
103  const Data_Namespace::MemoryLevel memory_level,
104  const int device_id,
105  DeviceAllocator* device_allocator);
106 
107  const int8_t* getResultSetColumn(const ResultSetPtr& buffer,
108  const int table_id,
109  const int col_id,
110  const Data_Namespace::MemoryLevel memory_level,
111  const int device_id,
112  DeviceAllocator* device_allocator) const;
113 
114  Executor* executor_;
115  using CacheKey = std::vector<int>;
116  mutable std::mutex columnar_conversion_mutex_;
118  mutable std::unordered_map<
120  std::unordered_map<CacheKey, std::unique_ptr<const ColumnarResults>>>
122  mutable std::unordered_map<InputColDescriptor, std::unique_ptr<const ColumnarResults>>
124 
126  friend class TableFunctionExecutionContext; // TODO(adb)
127 };
std::unordered_map< InputColDescriptor, std::unordered_map< CacheKey, std::unique_ptr< const ColumnarResults > > > columnarized_ref_table_cache_
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > >> ColumnCacheMap
ColumnCacheMap columnarized_table_cache_
size_t operator()(const std::pair< int, int > &p) const
Definition: ColumnFetcher.h:34
std::shared_ptr< ResultSet > ResultSetPtr
Executor * executor_
std::unordered_map< InputColDescriptor, std::unique_ptr< const ColumnarResults > > columnarized_scan_table_cache_
std::mutex columnar_conversion_mutex_
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:78
size_t operator()(const std::vector< int > &vec) const
Definition: ColumnFetcher.h:27
Abstract class for managing device memory allocations.
std::vector< int > CacheKey
std::vector< std::vector< const int8_t * > > col_buffers
Definition: ColumnFetcher.h:42
std::vector< std::vector< int64_t > > num_rows
Definition: ColumnFetcher.h:43
std::vector< std::vector< uint64_t > > frag_offsets
Definition: ColumnFetcher.h:44
Descriptor for the fragments required for an execution kernel.