OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 ()
 

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 66 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 69 of file ResultSetBuilder.cpp.

References CPU.

Referenced by create().

73  : logical_values(nullptr)
74  , targets(_targets)
76  , query_mem_desc(_query_mem_desc)
77  , row_set_mem_owner(_row_set_mem_owner)
78  , 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 80 of file ResultSetBuilder.cpp.

87  : logical_values(_logical_values)
88  , targets(_targets)
89  , device_type(_device_type)
90  , query_mem_desc(_query_mem_desc)
91  , row_set_mem_owner(_row_set_mem_owner)
92  , 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 ( )
virtual

Implements ResultSetBuilder.

Definition at line 94 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(), i, inline_int_null_val(), generate_TableFunctionsFactory_init::j, logical_values, ResultSetBuilder::makeResultSet(), query_mem_desc, row_set_mem_owner, RelLogicalValues::size(), targets, and RelAlgTranslator::translateLiteral().

Referenced by create().

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

160  {
161  // check to see if number of columns matches (at least the first row)
162  size_t numCols =
163  logical_values.size() ? logical_values.front().size() : label_infos.size();
164  CHECK_EQ(label_infos.size(), numCols);
165 
166  size_t numRows = logical_values.size();
167 
168  QueryMemoryDescriptor query_mem_desc(/*executor=*/nullptr,
169  /*entry_count=*/numRows,
171  /*is_table_function=*/false);
172 
173  // target_infos -> defines the table columns
174  std::vector<TargetInfo> target_infos;
175  SQLTypeInfo str_ti(kTEXT, true, kENCODING_NONE);
176  for (size_t col = 0; col < numCols; col++) {
177  SQLTypeInfo colType = label_infos[col].get_type_info();
178  target_infos.push_back(TargetInfo{false, kSAMPLE, colType, colType, true, false});
179  query_mem_desc.addColSlotInfo({std::make_tuple(colType.get_size(), 8)});
180  }
181 
182  std::shared_ptr<RelLogicalValues> rel_logical_values =
183  std::make_shared<RelLogicalValues>(label_infos, logical_values);
184 
185  const auto row_set_mem_owner =
186  std::make_shared<RowSetMemoryOwner>(Executor::getArenaBlockSize());
187 
188  // Construct ResultSet
189  ResultSet* rsp(ResultSetLogicalValuesBuilder(rel_logical_values.get(),
190  target_infos,
194  nullptr)
195  .build());
196 
197  return rsp;
198 }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
HOST DEVICE int get_size() const
Definition: sqltypes.h:324
size_t size() const override
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
Definition: sqltypes.h:51
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:213
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 70 of file ResultSetBuilder.h.

Referenced by build().

const Executor* ResultSetLogicalValuesBuilder::executor
private

Definition at line 73 of file ResultSetBuilder.h.

Referenced by build().

const RelLogicalValues* ResultSetLogicalValuesBuilder::logical_values
private

Definition at line 68 of file ResultSetBuilder.h.

Referenced by build(), and create().

const QueryMemoryDescriptor& ResultSetLogicalValuesBuilder::query_mem_desc
private

Definition at line 71 of file ResultSetBuilder.h.

Referenced by build(), and create().

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

Definition at line 72 of file ResultSetBuilder.h.

Referenced by build(), and create().

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

Definition at line 69 of file ResultSetBuilder.h.

Referenced by build().


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