OmniSciDB  340b00dbf6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSetBuilder.cpp
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 
25 #include "ResultSetBuilder.h"
26 #include "RelAlgTranslator.h"
27 
29  const std::vector<TargetInfo>& targets,
30  const ExecutorDeviceType device_type,
32  const std::shared_ptr<RowSetMemoryOwner> row_set_mem_owner,
33  const Executor* executor) {
34  return new ResultSet(targets, device_type, query_mem_desc, row_set_mem_owner, executor);
35 }
36 
38  const QueryMemoryDescriptor& _query_mem_desc,
39  const std::shared_ptr<RowSetMemoryOwner> _row_set_mem_owner)
40  : query_mem_desc(_query_mem_desc), row_set_mem_owner(_row_set_mem_owner) {}
41 
43  ResultSet* st = ResultSetBuilder::makeResultSet(std::vector<TargetInfo>{},
47  nullptr);
48  return st;
49 }
50 
52  const std::vector<TargetInfo>& _targets,
53  const QueryMemoryDescriptor& _query_mem_desc,
54  const std::shared_ptr<RowSetMemoryOwner> _row_set_mem_owner)
55  : logical_values(nullptr)
56  , targets(_targets)
57  , device_type(ExecutorDeviceType::CPU)
58  , query_mem_desc(_query_mem_desc)
59  , row_set_mem_owner(_row_set_mem_owner)
60  , executor(nullptr) {}
61 
63  const RelLogicalValues* _logical_values,
64  const std::vector<TargetInfo>& _targets,
65  const ExecutorDeviceType _device_type,
66  const QueryMemoryDescriptor& _query_mem_desc,
67  const std::shared_ptr<RowSetMemoryOwner> _row_set_mem_owner,
68  const Executor* _executor)
69  : logical_values(_logical_values)
70  , targets(_targets)
71  , device_type(_device_type)
72  , query_mem_desc(_query_mem_desc)
73  , row_set_mem_owner(_row_set_mem_owner)
74  , executor(_executor) {}
75 
77  ResultSet* rs = ResultSetBuilder::makeResultSet(
79 
82 
83  auto storage = rs->allocateStorage();
84  auto buff = storage->getUnderlyingBuffer();
85 
86  for (size_t i = 0; i < logical_values->getNumRows(); i++) {
87  std::vector<std::shared_ptr<Analyzer::Expr>> row_literals;
88  int8_t* ptr = buff + i * query_mem_desc.getRowSize();
89 
90  for (size_t j = 0; j < logical_values->getRowsSize(); j++) {
91  auto rex_literal =
92  dynamic_cast<const RexLiteral*>(logical_values->getValueAt(i, j));
93  CHECK(rex_literal);
94  const auto expr = RelAlgTranslator::translateLiteral(rex_literal);
95  const auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(expr);
96  CHECK(constant);
97 
98  if (constant->get_is_null()) {
99  CHECK(!targets[j].sql_type.is_varlen());
100  *reinterpret_cast<int64_t*>(ptr) = inline_int_null_val(targets[j].sql_type);
101  } else {
102  const auto ti = constant->get_type_info();
103  const auto datum = constant->get_constval();
104 
105  // Initialize the entire 8-byte slot
106  *reinterpret_cast<int64_t*>(ptr) = EMPTY_KEY_64;
107 
108  const auto sz = ti.get_size();
109  CHECK_GE(sz, int(0));
110  std::memcpy(ptr, &datum, sz);
111  }
112  ptr += 8;
113  }
114  }
115  }
116 
117  return rs;
118 }
bool hasRows() const
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define EMPTY_KEY_64
size_t size() const override
ExecutorDeviceType
const std::vector< TargetInfo > & targets
size_t getNumRows() const
#define CHECK_GE(x, y)
Definition: Logger.h:210
ResultSet * makeResultSet(const std::vector< TargetInfo > &targets, const ExecutorDeviceType device_type, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, const Executor *executor)
size_t getRowsSize() const
static std::shared_ptr< Analyzer::Expr > translateLiteral(const RexLiteral *)
const ExecutorDeviceType device_type
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
Basic constructors and methods of the row set interface.
const QueryMemoryDescriptor & query_mem_desc
ResultSetDefaultBuilder(const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
const RelLogicalValues * logical_values
const RexScalar * getValueAt(const size_t row_idx, const size_t col_idx) const
#define CHECK(condition)
Definition: Logger.h:197
ResultSetLogicalValuesBuilder(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
const QueryMemoryDescriptor & query_mem_desc