OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableFunctionManager Struct Reference

#include <OmniSciTypes.h>

+ Collaboration diagram for TableFunctionManager:

Public Member Functions

void set_output_row_size (int64_t num_rows)
 
int32_t error_message (const char *message)
 
 TableFunctionManager (const TableFunctionExecutionUnit &exe_unit, Executor *executor, std::vector< const int8_t * > &col_buf_ptrs, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, bool is_singleton)
 
size_t get_ncols () const
 
size_t get_nrows () const
 
void check_thread_id () const
 
void set_output_column (int32_t index, int8_t *ptr)
 
void allocate_output_buffers (int64_t output_num_rows)
 
const char * get_error_message () const
 
void set_error_message (const char *msg)
 
bool isSingleton () const
 
 ~TableFunctionManager ()
 

Static Public Member Functions

static TableFunctionManagerget_singleton ()
 
static TableFunctionManager *& get_singleton ()
 

Public Attributes

std::unique_ptr
< QueryMemoryInitializer
query_buffers
 

Private Member Functions

void lock ()
 
void unlock ()
 

Static Private Member Functions

static void set_singleton (TableFunctionManager *instance)
 

Private Attributes

const TableFunctionExecutionUnitexe_unit_
 
Executorexecutor_
 
std::vector< const int8_t * > & col_buf_ptrs_
 
std::shared_ptr
< RowSetMemoryOwner
row_set_mem_owner_
 
std::vector< int64_t * > output_col_buf_ptrs
 
size_t output_num_rows_
 
std::vector< int8_t * > output_column_ptrs
 
bool is_singleton_
 
std::thread::id thread_id_
 
std::string error_message_
 

Detailed Description

Definition at line 319 of file OmniSciTypes.h.

Constructor & Destructor Documentation

TableFunctionManager::TableFunctionManager ( const TableFunctionExecutionUnit exe_unit,
Executor executor,
std::vector< const int8_t * > &  col_buf_ptrs,
std::shared_ptr< RowSetMemoryOwner row_set_mem_owner,
bool  is_singleton 
)
inline

Definition at line 57 of file TableFunctionManager.h.

References get_ncols(), i, isSingleton(), output_col_buf_ptrs, output_column_ptrs, and set_singleton().

62  : exe_unit_(exe_unit)
63  , executor_(executor)
64  , col_buf_ptrs_(col_buf_ptrs)
65  , row_set_mem_owner_(row_set_mem_owner)
66  , output_num_rows_(-1)
67  , is_singleton_(is_singleton)
68  , thread_id_(std::this_thread::get_id()) {
69  if (isSingleton()) {
70  set_singleton(this); // start of singleton life
71  }
72  auto num_out_columns = get_ncols();
73  output_col_buf_ptrs.reserve(num_out_columns);
74  output_column_ptrs.reserve(num_out_columns);
75  for (size_t i = 0; i < num_out_columns; i++) {
76  output_col_buf_ptrs.emplace_back(nullptr);
77  output_column_ptrs.emplace_back(nullptr);
78  }
79  }
std::vector< const int8_t * > & col_buf_ptrs_
const TableFunctionExecutionUnit & exe_unit_
std::vector< int8_t * > output_column_ptrs
std::vector< int64_t * > output_col_buf_ptrs
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
static void set_singleton(TableFunctionManager *instance)

+ Here is the call graph for this function:

TableFunctionManager::~TableFunctionManager ( )
inline

Definition at line 170 of file TableFunctionManager.h.

References isSingleton(), and set_singleton().

170  {
171  if (isSingleton()) {
172  set_singleton(nullptr); // end of singleton life
173  }
174  }
static void set_singleton(TableFunctionManager *instance)

+ Here is the call graph for this function:

Member Function Documentation

void TableFunctionManager::allocate_output_buffers ( int64_t  output_num_rows)
inline

Definition at line 102 of file TableFunctionManager.h.

References QueryMemoryDescriptor::addColSlotInfo(), CHECK, CHECK_EQ, check_thread_id(), col_buf_ptrs_, CPU, exe_unit_, executor_, get_ncols(), i, output_col_buf_ptrs, output_column_ptrs, output_num_rows_, Projection, query_buffers, query_mem_desc, row_set_mem_owner_, QueryMemoryDescriptor::setOutputColumnar(), Column< T >::size(), and toString().

102  {
103  check_thread_id();
105  size_t(-1)); // re-allocation of output buffers is not supported
106  output_num_rows_ = output_num_rows;
107  auto num_out_columns = get_ncols();
109  output_num_rows, // divide by row multiplier???
111  /*is_table_function=*/true);
112  query_mem_desc.setOutputColumnar(true);
113 
114  for (size_t i = 0; i < num_out_columns; i++) {
115  // All outputs padded to 8 bytes
116  query_mem_desc.addColSlotInfo({std::make_tuple(8, 8)});
117  }
118 
119  // The members layout of Column must match with Column defined in
120  // OmniSciTypes.h
121  struct Column {
122  int8_t* ptr;
123  int64_t size;
124  // just for debugging:
125  std::string toString() const {
126  return "Column{" + ::toString(ptr) + ", " + ::toString(size) + "}";
127  }
128  };
129 
130  query_buffers = std::make_unique<QueryMemoryInitializer>(
131  exe_unit_,
133  /*device_id=*/0,
135  (output_num_rows_ == 0 ? 1 : output_num_rows_),
136  std::vector<std::vector<const int8_t*>>{col_buf_ptrs_},
137  std::vector<std::vector<uint64_t>>{{0}}, // frag offsets
139  nullptr,
140  executor_);
141  if (output_num_rows_ != 0) {
142  auto group_by_buffers_ptr = query_buffers->getGroupByBuffersPtr();
143  CHECK(group_by_buffers_ptr);
144  auto output_buffers_ptr = reinterpret_cast<int64_t*>(group_by_buffers_ptr[0]);
145  for (size_t i = 0; i < num_out_columns; i++) {
146  Column* col = reinterpret_cast<Column*>(output_column_ptrs[i]);
147  CHECK(col);
148  // set the members of output Column instances:
149  output_col_buf_ptrs[i] = output_buffers_ptr + i * output_num_rows_;
150  col->ptr = reinterpret_cast<int8_t*>(output_col_buf_ptrs[i]);
151  col->size = output_num_rows_;
152  }
153  }
154  }
std::unique_ptr< QueryMemoryInitializer > query_buffers
#define CHECK_EQ(x, y)
Definition: Logger.h:219
std::vector< const int8_t * > & col_buf_ptrs_
std::string toString(const ExtArgumentType &sig_type)
const TableFunctionExecutionUnit & exe_unit_
DEVICE int64_t size() const
Definition: OmniSciTypes.h:238
std::vector< int8_t * > output_column_ptrs
std::vector< int64_t * > output_col_buf_ptrs
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

void TableFunctionManager::check_thread_id ( ) const
inline

Definition at line 87 of file TableFunctionManager.h.

References thread_id_.

Referenced by allocate_output_buffers(), get_error_message(), set_error_message(), and set_output_column().

87  {
88  if (std::this_thread::get_id() != thread_id_) {
89  throw std::runtime_error(
90  "TableFunctionManager instance accessed from an alien thread!");
91  }
92  }

+ Here is the caller graph for this function:

int32_t TableFunctionManager::error_message ( const char *  message)
inline

Definition at line 328 of file OmniSciTypes.h.

References TableFunctionManager_error_message().

328  {
329  return TableFunctionManager_error_message(reinterpret_cast<int8_t*>(this), message);
330  }
EXTENSION_NOINLINE int32_t TableFunctionManager_error_message(int8_t *mgr_ptr, const char *message)

+ Here is the call graph for this function:

const char* TableFunctionManager::get_error_message ( ) const
inline

Definition at line 156 of file TableFunctionManager.h.

References check_thread_id(), and error_message_.

156  {
157  check_thread_id();
158  return error_message_.c_str();
159  }

+ Here is the call graph for this function:

size_t TableFunctionManager::get_ncols ( ) const
inline

Definition at line 82 of file TableFunctionManager.h.

References exe_unit_, and TableFunctionExecutionUnit::target_exprs.

Referenced by allocate_output_buffers(), set_output_column(), and TableFunctionManager().

82 { return exe_unit_.target_exprs.size(); }
const TableFunctionExecutionUnit & exe_unit_
std::vector< Analyzer::Expr * > target_exprs

+ Here is the caller graph for this function:

size_t TableFunctionManager::get_nrows ( ) const
inline

Definition at line 85 of file TableFunctionManager.h.

References output_num_rows_.

85 { return output_num_rows_; }
static TableFunctionManager*& TableFunctionManager::get_singleton ( )
inlinestatic

Definition at line 176 of file TableFunctionManager.h.

176  {
177  static TableFunctionManager* instance = nullptr;
178  return instance;
179  }
static TableFunctionManager* TableFunctionManager::get_singleton ( )
inlinestatic

Definition at line 320 of file OmniSciTypes.h.

References TableFunctionManager_get_singleton().

Referenced by ct_sleep1(), ct_sleep2(), and set_singleton().

320  {
321  return reinterpret_cast<TableFunctionManager*>(TableFunctionManager_get_singleton());
322  }
EXTENSION_NOINLINE int8_t * TableFunctionManager_get_singleton()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool TableFunctionManager::isSingleton ( ) const
inline

Definition at line 168 of file TableFunctionManager.h.

References is_singleton_.

Referenced by TableFunctionManager(), and ~TableFunctionManager().

168 { return is_singleton_; }

+ Here is the caller graph for this function:

void TableFunctionManager::lock ( )
inlineprivate

Definition at line 182 of file TableFunctionManager.h.

References TableFunctionManager_singleton_mutex.

Referenced by set_singleton().

std::mutex TableFunctionManager_singleton_mutex

+ Here is the caller graph for this function:

void TableFunctionManager::set_error_message ( const char *  msg)
inline

Definition at line 161 of file TableFunctionManager.h.

References check_thread_id(), and error_message_.

161  {
162  check_thread_id();
163  error_message_ = std::string(msg);
164  }

+ Here is the call graph for this function:

void TableFunctionManager::set_output_column ( int32_t  index,
int8_t *  ptr 
)
inline

Definition at line 95 of file TableFunctionManager.h.

References CHECK, check_thread_id(), get_ncols(), and output_column_ptrs.

95  {
97  CHECK(index >= 0 && index < static_cast<int32_t>(get_ncols()));
98  CHECK(ptr);
99  output_column_ptrs[index] = ptr;
100  }
std::vector< int8_t * > output_column_ptrs
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the call graph for this function:

void TableFunctionManager::set_output_row_size ( int64_t  num_rows)
inline

Definition at line 324 of file OmniSciTypes.h.

References TableFunctionManager_set_output_row_size().

Referenced by ct_add_size_and_mul_alpha(), ct_copy_and_add_size(), ct_pushdown_projection__cpu_template(), ct_pushdown_stats__cpu_template(), ct_sleep2(), ct_sparse_add(), ct_throw_if_gt_100__cpu_template(), ct_union_pushdown_projection__cpu_template(), and ct_union_pushdown_stats__cpu_template().

324  {
325  TableFunctionManager_set_output_row_size(reinterpret_cast<int8_t*>(this), num_rows);
326  }
EXTENSION_NOINLINE void TableFunctionManager_set_output_row_size(int8_t *mgr_ptr, int64_t num_rows)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void TableFunctionManager::set_singleton ( TableFunctionManager instance)
inlinestaticprivate

Definition at line 185 of file TableFunctionManager.h.

References CHECK, get_singleton(), and lock().

Referenced by TableFunctionManager(), and ~TableFunctionManager().

185  {
186  auto& instance_ = get_singleton();
187  // ensure being singleton and lock/unlock
188  if (instance) {
189  instance->lock();
190  CHECK(instance_ == nullptr);
191  } else {
192  CHECK(instance_ != nullptr);
193  instance_->unlock();
194  }
195  instance_ = instance;
196  }
#define CHECK(condition)
Definition: Logger.h:211
static TableFunctionManager * get_singleton()
Definition: OmniSciTypes.h:320

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TableFunctionManager::unlock ( )
inlineprivate

Definition at line 183 of file TableFunctionManager.h.

References TableFunctionManager_singleton_mutex.

std::mutex TableFunctionManager_singleton_mutex

Member Data Documentation

std::vector<const int8_t*>& TableFunctionManager::col_buf_ptrs_
private

Definition at line 201 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

std::string TableFunctionManager::error_message_
private

Definition at line 215 of file TableFunctionManager.h.

Referenced by get_error_message(), and set_error_message().

const TableFunctionExecutionUnit& TableFunctionManager::exe_unit_
private

Definition at line 198 of file TableFunctionManager.h.

Referenced by allocate_output_buffers(), and get_ncols().

Executor* TableFunctionManager::executor_
private

Definition at line 199 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

bool TableFunctionManager::is_singleton_
private

Definition at line 211 of file TableFunctionManager.h.

Referenced by isSingleton().

std::vector<int64_t*> TableFunctionManager::output_col_buf_ptrs
private

Definition at line 205 of file TableFunctionManager.h.

Referenced by allocate_output_buffers(), and TableFunctionManager().

std::vector<int8_t*> TableFunctionManager::output_column_ptrs
private
size_t TableFunctionManager::output_num_rows_
private

Definition at line 207 of file TableFunctionManager.h.

Referenced by allocate_output_buffers(), and get_nrows().

std::unique_ptr<QueryMemoryInitializer> TableFunctionManager::query_buffers

Definition at line 55 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

std::shared_ptr<RowSetMemoryOwner> TableFunctionManager::row_set_mem_owner_
private

Definition at line 203 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

std::thread::id TableFunctionManager::thread_id_
private

Definition at line 213 of file TableFunctionManager.h.

Referenced by check_thread_id().


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