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

#include <heavydbTypes.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 650 of file heavydbTypes.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(), 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 176 of file TableFunctionManager.h.

References isSingleton(), and set_singleton().

176  {
177  if (isSingleton()) {
178  set_singleton(nullptr); // end of singleton life
179  }
180  }
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(), align_to_int64(), CHECK, CHECK_EQ, check_thread_id(), col_buf_ptrs_, CPU, exe_unit_, executor_, get_ncols(), output_col_buf_ptrs, output_column_ptrs, output_num_rows_, query_buffers, query_mem_desc, row_set_mem_owner_, QueryMemoryDescriptor::setOutputColumnar(), Column< T >::size(), TableFunction, TableFunctionExecutionUnit::target_exprs, 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 have padded width set to logical column width
116  const size_t col_width = exe_unit_.target_exprs[i]->get_type_info().get_size();
117  query_mem_desc.addColSlotInfo({std::make_tuple(col_width, col_width)});
118  }
119 
120  // The members layout of Column must match with Column defined in
121  // heavydbTypes.h
122  struct Column {
123  int8_t* ptr;
124  int64_t size;
125  // just for debugging:
126  std::string toString() const {
127  return "Column{" + ::toString(ptr) + ", " + ::toString(size) + "}";
128  }
129  };
130  // We do not init output buffers for CPU currently, so CPU
131  // table functions are expected to handle their own initialization
132  query_buffers = std::make_unique<QueryMemoryInitializer>(
133  exe_unit_,
135  /*device_id=*/0,
137  (output_num_rows_ == 0 ? 1 : output_num_rows_),
138  std::vector<std::vector<const int8_t*>>{col_buf_ptrs_},
139  std::vector<std::vector<uint64_t>>{{0}}, // frag offsets
141  nullptr,
142  executor_);
143  if (output_num_rows_ != 0) {
144  auto group_by_buffers_ptr = query_buffers->getGroupByBuffersPtr();
145  CHECK(group_by_buffers_ptr);
146  auto output_buffers_ptr = reinterpret_cast<int8_t*>(group_by_buffers_ptr[0]);
147  for (size_t i = 0; i < num_out_columns; i++) {
148  Column* col = reinterpret_cast<Column*>(output_column_ptrs[i]);
149  CHECK(col);
150  // set the members of output Column instances:
151  output_col_buf_ptrs[i] = reinterpret_cast<int64_t*>(output_buffers_ptr);
152  col->ptr = output_buffers_ptr;
153  col->size = output_num_rows_;
154 
155  const size_t col_width = exe_unit_.target_exprs[i]->get_type_info().get_size();
156  output_buffers_ptr =
157  align_to_int64(output_buffers_ptr + col_width * output_num_rows_);
158  }
159  }
160  }
std::unique_ptr< QueryMemoryInitializer > query_buffers
#define CHECK_EQ(x, y)
Definition: Logger.h:231
std::vector< const int8_t * > & col_buf_ptrs_
const TableFunctionExecutionUnit & exe_unit_
DEVICE int64_t size() const
Definition: heavydbTypes.h:445
std::vector< int8_t * > output_column_ptrs
std::vector< int64_t * > output_col_buf_ptrs
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1453
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
#define CHECK(condition)
Definition: Logger.h:223
std::vector< Analyzer::Expr * > target_exprs
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)

+ 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 659 of file heavydbTypes.h.

References TableFunctionManager_error_message().

659  {
660  return TableFunctionManager_error_message(reinterpret_cast<int8_t*>(this), message);
661  }
EXTENSION_NOINLINE_HOST 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 162 of file TableFunctionManager.h.

References check_thread_id(), and error_message_.

162  {
163  check_thread_id();
164  return error_message_.c_str();
165  }

+ 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 182 of file TableFunctionManager.h.

182  {
183  static TableFunctionManager* instance = nullptr;
184  return instance;
185  }
static TableFunctionManager* TableFunctionManager::get_singleton ( )
inlinestatic

Definition at line 651 of file heavydbTypes.h.

References TableFunctionManager_get_singleton().

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

651  {
652  return reinterpret_cast<TableFunctionManager*>(TableFunctionManager_get_singleton());
653  }
EXTENSION_NOINLINE_HOST 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 174 of file TableFunctionManager.h.

References is_singleton_.

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

174 { return is_singleton_; }

+ Here is the caller graph for this function:

void TableFunctionManager::lock ( )
inlineprivate

Definition at line 188 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 167 of file TableFunctionManager.h.

References check_thread_id(), and error_message_.

167  {
168  check_thread_id();
169  error_message_ = std::string(msg);
170  }

+ 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:223

+ Here is the call graph for this function:

void TableFunctionManager::set_output_row_size ( int64_t  num_rows)
inline

Definition at line 655 of file heavydbTypes.h.

References TableFunctionManager_set_output_row_size().

Referenced by ct_add_size_and_mul_alpha(), ct_copy_and_add_size(), ct_cursor_named_args__cpu_(), ct_pushdown_projection__cpu_template(), ct_pushdown_stats__cpu_template(), ct_scalar_named_args__cpu_(), ct_sleep2(), ct_sparse_add(), ct_string_concat__cpu_(), ct_substr__cpu_(), ct_synthesize_new_dict__cpu_(), ct_test_preflight_multicursor_qe227__cpu_(), ct_test_preflight_singlecursor_qe227__cpu_(), ct_throw_if_gt_100__cpu_template(), ct_timestamp_add_offset(), ct_timestamp_column_list_input(), ct_timestamp_extract(), ct_timestamp_truncate(), ct_union_pushdown_projection__cpu_template(), ct_union_pushdown_stats__cpu_template(), generate_random_strings__cpu_(), generate_series__cpu_1(), Mandelbrot::mandelbrot_cpu_template(), and GeoRaster< T, Z >::outputDenseColumns().

655  {
656  TableFunctionManager_set_output_row_size(reinterpret_cast<int8_t*>(this), num_rows);
657  }
EXTENSION_NOINLINE_HOST 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 191 of file TableFunctionManager.h.

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

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

191  {
192  auto& instance_ = get_singleton();
193  // ensure being singleton and lock/unlock
194  if (instance) {
195  instance->lock();
196  CHECK(instance_ == nullptr);
197  } else {
198  CHECK(instance_ != nullptr);
199  instance_->unlock();
200  }
201  instance_ = instance;
202  }
#define CHECK(condition)
Definition: Logger.h:223
static TableFunctionManager * get_singleton()
Definition: heavydbTypes.h:651

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TableFunctionManager::unlock ( )
inlineprivate

Definition at line 189 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 207 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

std::string TableFunctionManager::error_message_
private

Definition at line 221 of file TableFunctionManager.h.

Referenced by get_error_message(), and set_error_message().

const TableFunctionExecutionUnit& TableFunctionManager::exe_unit_
private

Definition at line 204 of file TableFunctionManager.h.

Referenced by allocate_output_buffers(), and get_ncols().

Executor* TableFunctionManager::executor_
private

Definition at line 205 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

bool TableFunctionManager::is_singleton_
private

Definition at line 217 of file TableFunctionManager.h.

Referenced by isSingleton().

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

Definition at line 211 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 213 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 209 of file TableFunctionManager.h.

Referenced by allocate_output_buffers().

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

Definition at line 219 of file TableFunctionManager.h.

Referenced by check_thread_id().


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