OmniSciDB  c07336695a
ColumnarResults.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 #ifndef COLUMNAR_RESULTS_H
18 #define COLUMNAR_RESULTS_H
19 #include "ResultSet.h"
20 #include "Shared/SqlTypesLayout.h"
21 
22 #include "../Shared/checked_alloc.h"
23 
24 #include <memory>
25 #include <unordered_map>
26 
27 class ColumnarConversionNotSupported : public std::runtime_error {
28  public:
30  : std::runtime_error(
31  "Columnar conversion not supported for variable length types") {}
32 };
33 
35  public:
36  ColumnarResults(const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
37  const ResultSet& rows,
38  const size_t num_columns,
39  const std::vector<SQLTypeInfo>& target_types);
40 
41  ColumnarResults(const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
42  const int8_t* one_col_buffer,
43  const size_t num_rows,
44  const SQLTypeInfo& target_type);
45 
46  static std::unique_ptr<ColumnarResults> mergeResults(
47  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
48  const std::vector<std::unique_ptr<ColumnarResults>>& sub_results);
49 
50  const std::vector<const int8_t*>& getColumnBuffers() const { return column_buffers_; }
51 
52  const size_t size() const { return num_rows_; }
53 
54  const SQLTypeInfo& getColumnType(const int col_id) const {
55  CHECK_GE(col_id, 0);
56  CHECK_LT(static_cast<size_t>(col_id), target_types_.size());
57  return target_types_[col_id];
58  }
59 
60  template <typename EntryT>
61  EntryT getEntryAt(const size_t row_idx, const size_t column_idx) const;
62 
63  void setParallelConversion(const bool is_parallel) {
64  parallel_conversion_ = is_parallel;
65  }
66  bool isParallelConversion() const { return parallel_conversion_; }
67 
68  private:
69  ColumnarResults(const size_t num_rows, const std::vector<SQLTypeInfo>& target_types)
70  : num_rows_(num_rows), target_types_(target_types) {}
71  inline void writeBackCell(const TargetValue& col_val,
72  const size_t row_idx,
73  const size_t column_idx);
74  void materializeAllColumns(const ResultSet& rows, const size_t num_columns);
75  void copyAllNonLazyColumns(const std::vector<ColumnLazyFetchInfo>& lazy_fetch_info,
76  const ResultSet& rows,
77  const size_t num_columns);
78  void materializeAllLazyColumns(const std::vector<ColumnLazyFetchInfo>& lazy_fetch_info,
79  const ResultSet& rows,
80  const size_t num_columns);
81 
82  std::vector<const int8_t*> column_buffers_;
83  size_t num_rows_;
84  const std::vector<SQLTypeInfo> target_types_;
85  bool parallel_conversion_; // multi-threaded execution of columnar conversion
86 };
87 
88 typedef std::
89  unordered_map<int, std::unordered_map<int, std::shared_ptr<const ColumnarResults>>>
91 #endif // COLUMNAR_RESULTS_H
bool isParallelConversion() const
const int8_t const int64_t * num_rows
#define CHECK_GE(x, y)
Definition: Logger.h:200
std::vector< const int8_t * > column_buffers_
void setParallelConversion(const bool is_parallel)
ColumnarResults(const size_t num_rows, const std::vector< SQLTypeInfo > &target_types)
const size_t size() const
#define CHECK_LT(x, y)
Definition: Logger.h:197
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
Basic constructors and methods of the row set interface.
boost::variant< ScalarTargetValue, ArrayTargetValue, GeoTargetValue, GeoTargetValuePtr > TargetValue
Definition: TargetValue.h:167
const std::vector< const int8_t * > & getColumnBuffers() const
const std::vector< SQLTypeInfo > target_types_
const SQLTypeInfo & getColumnType(const int col_id) const