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

References CPU.

Referenced by create().

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

84  : logical_values(_logical_values)
85  , targets(_targets)
86  , device_type(_device_type)
87  , query_mem_desc(_query_mem_desc)
88  , row_set_mem_owner(_row_set_mem_owner)
89  , 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 91 of file ResultSetBuilder.cpp.

References ResultSetBuilder::addVarlenBuffer(), CHECK, CHECK_EQ, CHECK_GE, device_type, 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, TRANSIENT_DICT_DB_ID, TRANSIENT_DICT_ID, and RelAlgTranslator::translateLiteral().

Referenced by create().

91  {
92  ResultSet* rs = ResultSetBuilder::makeResultSet(
94 
97 
98  std::vector<std::string> separate_varlen_storage;
99 
100  auto storage = rs->allocateStorage();
101  auto buff = storage->getUnderlyingBuffer();
102 
103  for (size_t i = 0; i < logical_values->getNumRows(); i++) {
104  std::vector<std::shared_ptr<Analyzer::Expr>> row_literals;
105  int8_t* ptr = buff + i * query_mem_desc.getRowSize();
106 
107  for (size_t j = 0; j < logical_values->getRowsSize(); j++) {
108  auto rex_literal =
109  dynamic_cast<const RexLiteral*>(logical_values->getValueAt(i, j));
110  CHECK(rex_literal);
111  const auto expr = RelAlgTranslator::translateLiteral(rex_literal);
112  const auto constant = std::dynamic_pointer_cast<Analyzer::Constant>(expr);
113  CHECK(constant);
114 
115  if (constant->get_is_null()) {
116  CHECK(!targets[j].sql_type.is_varlen());
117  *reinterpret_cast<int64_t*>(ptr) = inline_int_null_val(targets[j].sql_type);
118  } else {
119  const auto ti = constant->get_type_info();
120  const auto datum = constant->get_constval();
121 
122  if (ti.is_string()) {
123  CHECK(ti.is_none_encoded_string());
124  if (targets[j].sql_type.is_dict_encoded_string()) {
125  // Translate none-encoded string literal to entry in transient string
126  // dictionary. All proper DML queries go down this path
127  CHECK_EQ(targets[j].sql_type.get_comp_param(), TRANSIENT_DICT_ID);
128  CHECK_EQ(targets[j].sql_type.get_size(), 4);
129  const auto sdp = executor->getStringDictionaryProxy(
131  executor->getRowSetMemoryOwner(),
132  true);
133  const auto string_id = sdp->getOrAddTransient(*datum.stringval);
134  // Initialize the entire 8-byte slot
135  std::memset(ptr, 0, 8);
136  std::memcpy(ptr, &string_id, 4);
137  } else {
138  // Project none-encoded string - used for various psuedo-query
139  // outputs like SHOW TABLE, SHOW TABLE DETAILS, etc
140  CHECK(targets[j].sql_type.is_none_encoded_string());
141  // get string from datum and push to vector
142  separate_varlen_storage.push_back(*(datum.stringval));
143  // store the index/offset in ResultSet's storage
144  // (the # of the string in the varlen_storage, not strLen)
145  *reinterpret_cast<int64_t*>(ptr) =
146  static_cast<int64_t>(separate_varlen_storage.size() - 1);
147  }
148  } else {
149  // Initialize the entire 8-byte slot
150  std::memset(ptr, 0, 8);
151  const auto sz = ti.get_size();
152  CHECK_GE(sz, int(0));
153  std::memcpy(ptr, &datum, sz);
154  }
155  }
156  ptr += 8;
157  }
158  }
159 
160  // store the varlen data (ex. strings) into the ResultSet
161  if (separate_varlen_storage.size()) {
162  ResultSetBuilder::addVarlenBuffer(rs, separate_varlen_storage);
163  rs->setSeparateVarlenStorageValid(true);
164  }
165  }
166 
167  return rs;
168 }
bool hasRows() const
Definition: RelAlgDag.h:2724
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t size() const override
Definition: RelAlgDag.h:2722
const std::vector< TargetInfo > & targets
size_t getNumRows() const
Definition: RelAlgDag.h:2720
#define CHECK_GE(x, y)
Definition: Logger.h:306
#define TRANSIENT_DICT_DB_ID
Definition: DbObjectKeys.h:25
#define TRANSIENT_DICT_ID
Definition: DbObjectKeys.h:24
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:2712
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:2705
#define CHECK(condition)
Definition: Logger.h:291
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 171 of file ResultSetBuilder.cpp.

References QueryMemoryDescriptor::addColSlotInfo(), build(), CHECK_EQ, CPU, SQLTypeInfo::get_size(), Executor::getArenaBlockSize(), kENCODING_NONE, kSAMPLE, kTEXT, logical_values, heavyai::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(), ShowModelsCommand::execute(), ShowModelDetailsCommand::execute(), ShowModelFeatureDetailsCommand::execute(), EvaluateModelCommand::execute(), ShowDiskCacheUsageCommand::execute(), ShowUserDetailsCommand::execute(), ShowRolesCommand::execute(), DBHandler::getQueries(), and DBHandler::getUserSessions().

173  {
174  // check to see if number of columns matches (at least the first row)
175  size_t numCols =
176  logical_values.size() ? logical_values.front().size() : label_infos.size();
177  CHECK_EQ(label_infos.size(), numCols);
178 
179  size_t numRows = logical_values.size();
180 
181  QueryMemoryDescriptor query_mem_desc(/*executor=*/nullptr,
182  /*entry_count=*/numRows,
184 
185  // target_infos -> defines the table columns
186  std::vector<TargetInfo> target_infos;
187  SQLTypeInfo str_ti(kTEXT, true, kENCODING_NONE);
188  for (size_t col = 0; col < numCols; col++) {
189  SQLTypeInfo colType = label_infos[col].get_type_info();
190  target_infos.push_back(TargetInfo{
191  false, kSAMPLE, colType, colType, true, false, /*is_varlen_projection=*/false});
192  query_mem_desc.addColSlotInfo({std::make_tuple(colType.get_size(), 8)});
193  }
194 
195  std::shared_ptr<RelLogicalValues> rel_logical_values =
196  std::make_shared<RelLogicalValues>(label_infos, logical_values);
197 
198  const auto row_set_mem_owner =
199  std::make_shared<RowSetMemoryOwner>(Executor::getArenaBlockSize(), 0);
200 
201  // Construct ResultSet
202  ResultSet* rsp(ResultSetLogicalValuesBuilder(rel_logical_values.get(),
203  target_infos,
207  nullptr)
208  .build());
209 
210  return rsp;
211 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
size_t size() const override
Definition: RelAlgDag.h:2722
Projection
Definition: enums.h:58
const std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner
Definition: sqltypes.h:79
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:562
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: