OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSetLogicalValuesBuilder Class Reference

#include <ResultSetBuilder.h>

+ Inheritance diagram for ResultSetLogicalValuesBuilder:
+ Collaboration diagram for ResultSetLogicalValuesBuilder:

Public Member Functions

 ResultSetLogicalValuesBuilder (const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
 ResultSetLogicalValuesBuilder (const RelLogicalValues *logical_values, 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)
 
ResultSetbuild () override
 

Static Public Member Functions

static ResultSetcreate (std::vector< TargetMetaInfo > &label_infos, std::vector< RelLogicalValues::RowValues > &logical_values)
 

Private Attributes

const RelLogicalValueslogical_values
 
const std::vector< TargetInfo > & targets
 
const ExecutorDeviceType device_type
 
const QueryMemoryDescriptorquery_mem_desc
 
const std::shared_ptr
< RowSetMemoryOwner
row_set_mem_owner
 
const Executorexecutor
 

Additional Inherited Members

- Protected Member Functions inherited from ResultSetBuilder
ResultSetmakeResultSet (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)
 
void addVarlenBuffer (ResultSet *result_set, std::vector< std::string > &varlen_storage)
 

Detailed Description

Definition at line 64 of file ResultSetBuilder.h.

Constructor & Destructor Documentation

ResultSetLogicalValuesBuilder::ResultSetLogicalValuesBuilder ( const std::vector< TargetInfo > &  targets,
const QueryMemoryDescriptor query_mem_desc,
const std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 67 of file ResultSetBuilder.cpp.

References CPU.

Referenced by create().

71  : logical_values(nullptr)
72  , targets(_targets)
74  , query_mem_desc(_query_mem_desc)
75  , row_set_mem_owner(_row_set_mem_owner)
76  , executor(nullptr) {}
const std::vector< TargetInfo > & targets
const ExecutorDeviceType device_type
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
const RelLogicalValues * logical_values
const QueryMemoryDescriptor & query_mem_desc

+ Here is the caller graph for this function:

ResultSetLogicalValuesBuilder::ResultSetLogicalValuesBuilder ( const RelLogicalValues logical_values,
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 
)

Definition at line 78 of file ResultSetBuilder.cpp.

85  : logical_values(_logical_values)
86  , targets(_targets)
87  , device_type(_device_type)
88  , query_mem_desc(_query_mem_desc)
89  , row_set_mem_owner(_row_set_mem_owner)
90  , executor(_executor) {}
const std::vector< TargetInfo > & targets
const ExecutorDeviceType device_type
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
const RelLogicalValues * logical_values
const QueryMemoryDescriptor & query_mem_desc

Member Function Documentation

ResultSet * ResultSetLogicalValuesBuilder::build ( )
overridevirtual

Implements ResultSetBuilder.

Definition at line 92 of file ResultSetBuilder.cpp.

References ResultSetBuilder::addVarlenBuffer(), CHECK, CHECK_EQ, CHECK_GE, device_type, EMPTY_KEY_64, executor, RelLogicalValues::getNumRows(), QueryMemoryDescriptor::getRowSize(), RelLogicalValues::getRowsSize(), RelLogicalValues::getValueAt(), RelLogicalValues::hasRows(), inline_int_null_val(), logical_values, ResultSetBuilder::makeResultSet(), query_mem_desc, row_set_mem_owner, RelLogicalValues::size(), targets, and RelAlgTranslator::translateLiteral().

Referenced by create().

92  {
93  ResultSet* rs = ResultSetBuilder::makeResultSet(
95 
98 
99  std::vector<std::string> separate_varlen_storage;
100 
101  auto storage = rs->allocateStorage();
102  auto buff = storage->getUnderlyingBuffer();
103 
104  for (size_t i = 0; i < logical_values->getNumRows(); i++) {
105  std::vector<std::shared_ptr<Analyzer::Expr>> row_literals;
106  int8_t* ptr = buff + i * query_mem_desc.getRowSize();
107 
108  for (size_t j = 0; j < logical_values->getRowsSize(); j++) {
109  auto rex_literal =
110  dynamic_cast<const RexLiteral*>(logical_values->getValueAt(i, j));
111  CHECK(rex_literal);
112  const auto expr = RelAlgTranslator::translateLiteral(rex_literal);
113  const auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(expr);
114  CHECK(constant);
115 
116  if (constant->get_is_null()) {
117  CHECK(!targets[j].sql_type.is_varlen());
118  *reinterpret_cast<int64_t*>(ptr) = inline_int_null_val(targets[j].sql_type);
119  } else {
120  const auto ti = constant->get_type_info();
121  const auto datum = constant->get_constval();
122 
123  if (ti.is_string()) {
124  // get string from datum and push to vector
125  separate_varlen_storage.push_back(*(datum.stringval));
126 
127  // store the index/offset in ResultSet's storage
128  // (the # of the string in the varlen_storage, not strLen)
129  *reinterpret_cast<int64_t*>(ptr) =
130  static_cast<int64_t>(separate_varlen_storage.size() - 1);
131 
132  } else {
133  // Initialize the entire 8-byte slot
134  *reinterpret_cast<int64_t*>(ptr) = EMPTY_KEY_64;
135 
136  const auto sz = ti.get_size();
137  CHECK_GE(sz, int(0));
138  std::memcpy(ptr, &datum, sz);
139  }
140  }
141  ptr += 8;
142  }
143  }
144 
145  // store the varlen data (ex. strings) into the ResultSet
146  if (separate_varlen_storage.size()) {
147  ResultSetBuilder::addVarlenBuffer(rs, separate_varlen_storage);
148  rs->setSeparateVarlenStorageValid(true);
149  }
150  }
151 
152  return rs;
153 }
bool hasRows() const
Definition: RelAlgDag.h:2227
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define EMPTY_KEY_64
size_t size() const override
Definition: RelAlgDag.h:2225
const std::vector< TargetInfo > & targets
size_t getNumRows() const
Definition: RelAlgDag.h:2223
#define CHECK_GE(x, y)
Definition: Logger.h:235
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
Definition: RelAlgDag.h:2215
static std::shared_ptr< Analyzer::Expr > translateLiteral(const RexLiteral *)
const ExecutorDeviceType device_type
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
Definition: RelAlgDag.h:2208
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
void addVarlenBuffer(ResultSet *result_set, std::vector< std::string > &varlen_storage)
const QueryMemoryDescriptor & query_mem_desc

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ResultSet * ResultSetLogicalValuesBuilder::create ( std::vector< TargetMetaInfo > &  label_infos,
std::vector< RelLogicalValues::RowValues > &  logical_values 
)
static

Definition at line 156 of file ResultSetBuilder.cpp.

References QueryMemoryDescriptor::addColSlotInfo(), build(), CHECK_EQ, CPU, SQLTypeInfo::get_size(), Executor::getArenaBlockSize(), kENCODING_NONE, kSAMPLE, kTEXT, logical_values, Projection, query_mem_desc, ResultSetLogicalValuesBuilder(), and row_set_mem_owner.

Referenced by ShowForeignServersCommand::execute(), ShowCreateServerCommand::execute(), ShowTablesCommand::execute(), ShowTableDetailsCommand::execute(), ShowDatabasesCommand::execute(), ShowFunctionsCommand::execute(), ShowRuntimeFunctionsCommand::execute(), ShowTableFunctionsCommand::execute(), ShowRuntimeTableFunctionsCommand::execute(), ShowDiskCacheUsageCommand::execute(), ShowUserDetailsCommand::execute(), ShowRolesCommand::execute(), DBHandler::getQueries(), and DBHandler::getUserSessions().

158  {
159  // check to see if number of columns matches (at least the first row)
160  size_t numCols =
161  logical_values.size() ? logical_values.front().size() : label_infos.size();
162  CHECK_EQ(label_infos.size(), numCols);
163 
164  size_t numRows = logical_values.size();
165 
166  QueryMemoryDescriptor query_mem_desc(/*executor=*/nullptr,
167  /*entry_count=*/numRows,
169  /*is_table_function=*/false);
170 
171  // target_infos -> defines the table columns
172  std::vector<TargetInfo> target_infos;
173  SQLTypeInfo str_ti(kTEXT, true, kENCODING_NONE);
174  for (size_t col = 0; col < numCols; col++) {
175  SQLTypeInfo colType = label_infos[col].get_type_info();
176  target_infos.push_back(TargetInfo{
177  false, kSAMPLE, colType, colType, true, false, /*is_varlen_projection=*/false});
178  query_mem_desc.addColSlotInfo({std::make_tuple(colType.get_size(), 8)});
179  }
180 
181  std::shared_ptr<RelLogicalValues> rel_logical_values =
182  std::make_shared<RelLogicalValues>(label_infos, logical_values);
183 
184  const auto row_set_mem_owner =
185  std::make_shared<RowSetMemoryOwner>(Executor::getArenaBlockSize());
186 
187  // Construct ResultSet
188  ResultSet* rsp(ResultSetLogicalValuesBuilder(rel_logical_values.get(),
189  target_infos,
193  nullptr)
194  .build());
195 
196  return rsp;
197 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
size_t size() const override
Definition: RelAlgDag.h:2225
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
Definition: sqltypes.h:52
const RelLogicalValues * logical_values
ResultSetLogicalValuesBuilder(const std::vector< TargetInfo > &targets, const QueryMemoryDescriptor &query_mem_desc, const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
void addColSlotInfo(const std::vector< std::tuple< int8_t, int8_t >> &slots_for_col)
static size_t getArenaBlockSize()
Definition: Execute.cpp:518
ResultSet * build() override
const QueryMemoryDescriptor & query_mem_desc

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const ExecutorDeviceType ResultSetLogicalValuesBuilder::device_type
private

Definition at line 68 of file ResultSetBuilder.h.

Referenced by build().

const Executor* ResultSetLogicalValuesBuilder::executor
private

Definition at line 71 of file ResultSetBuilder.h.

Referenced by build().

const RelLogicalValues* ResultSetLogicalValuesBuilder::logical_values
private

Definition at line 66 of file ResultSetBuilder.h.

Referenced by build(), and create().

const QueryMemoryDescriptor& ResultSetLogicalValuesBuilder::query_mem_desc
private

Definition at line 69 of file ResultSetBuilder.h.

Referenced by build(), and create().

const std::shared_ptr<RowSetMemoryOwner> ResultSetLogicalValuesBuilder::row_set_mem_owner
private

Definition at line 70 of file ResultSetBuilder.h.

Referenced by build(), and create().

const std::vector<TargetInfo>& ResultSetLogicalValuesBuilder::targets
private

Definition at line 67 of file ResultSetBuilder.h.

Referenced by build().


The documentation for this class was generated from the following files: