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

#include <WindowContext.h>

+ Collaboration diagram for WindowFunctionContext:

Classes

struct  AggregateState
 

Public Types

using Comparator = std::function< bool(const int64_t lhs, const int64_t rhs)>
 

Public Member Functions

 WindowFunctionContext (const Analyzer::WindowFunction *window_func, const size_t elem_count, const ExecutorDeviceType device_type, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
 WindowFunctionContext (const Analyzer::WindowFunction *window_func, const std::shared_ptr< HashJoin > &partitions, const size_t elem_count, const ExecutorDeviceType device_type, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner)
 
 WindowFunctionContext (const WindowFunctionContext &)=delete
 
WindowFunctionContextoperator= (const WindowFunctionContext &)=delete
 
 ~WindowFunctionContext ()
 
void addOrderColumn (const int8_t *column, const Analyzer::ColumnVar *col_var, const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner)
 
void compute ()
 
const Analyzer::WindowFunctiongetWindowFunction () const
 
const int8_t * output () const
 
const int64_t * aggregateState () const
 
const int64_t * aggregateStateCount () const
 
int64_t aggregateStatePendingOutputs () const
 
const int8_t * partitionStart () const
 
const int8_t * partitionEnd () const
 
size_t elementCount () const
 

Private Member Functions

void computePartition (int64_t *output_for_partition_buff, const size_t partition_size, const size_t off, const Analyzer::WindowFunction *window_func, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
 
void fillPartitionStart ()
 
void fillPartitionEnd ()
 
const int32_t * payload () const
 
const int32_t * offsets () const
 
const int32_t * counts () const
 
size_t partitionCount () const
 

Static Private Member Functions

static Comparator makeComparator (const Analyzer::ColumnVar *col_var, const int8_t *partition_values, const int32_t *partition_indices, const bool nulls_first)
 

Private Attributes

const Analyzer::WindowFunctionwindow_func_
 
std::vector< std::vector
< std::shared_ptr
< Chunk_NS::Chunk > > > 
order_columns_owner_
 
std::vector< const int8_t * > order_columns_
 
std::shared_ptr< HashJoinpartitions_
 
size_t elem_count_
 
int8_t * output_
 
int8_t * partition_start_
 
int8_t * partition_end_
 
AggregateState aggregate_state_
 
const ExecutorDeviceType device_type_
 
std::shared_ptr
< RowSetMemoryOwner
row_set_mem_owner_
 
const int32_t dummy_count_
 
const int32_t dummy_offset_
 
int32_t * dummy_payload_
 

Detailed Description

Definition at line 66 of file WindowContext.h.

Member Typedef Documentation

using WindowFunctionContext::Comparator = std::function<bool(const int64_t lhs, const int64_t rhs)>

Definition at line 119 of file WindowContext.h.

Constructor & Destructor Documentation

WindowFunctionContext::WindowFunctionContext ( const Analyzer::WindowFunction window_func,
const size_t  elem_count,
const ExecutorDeviceType  device_type,
std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 31 of file WindowContext.cpp.

References CHECK_LE, checked_malloc(), dummy_payload_, elem_count_, and gpu_enabled::iota().

36  : window_func_(window_func)
37  , partitions_(nullptr)
38  , elem_count_(elem_count)
39  , output_(nullptr)
40  , partition_start_(nullptr)
41  , partition_end_(nullptr)
42  , device_type_(device_type)
43  , row_set_mem_owner_(row_set_mem_owner)
44  , dummy_count_(elem_count)
45  , dummy_offset_(0)
46  , dummy_payload_(nullptr) {
47  CHECK_LE(elem_count_, static_cast<size_t>(std::numeric_limits<int32_t>::max()));
48  if (elem_count_ > 0) {
50  reinterpret_cast<int32_t*>(checked_malloc(elem_count_ * sizeof(int32_t)));
52  }
53 }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
const int32_t dummy_count_
const int32_t dummy_offset_
const Analyzer::WindowFunction * window_func_
void * checked_malloc(const size_t size)
Definition: checked_alloc.h:45
#define CHECK_LE(x, y)
Definition: Logger.h:220
DEVICE void iota(ARGS &&...args)
Definition: gpu_enabled.h:69
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the call graph for this function:

WindowFunctionContext::WindowFunctionContext ( const Analyzer::WindowFunction window_func,
const std::shared_ptr< HashJoin > &  partitions,
const size_t  elem_count,
const ExecutorDeviceType  device_type,
std::shared_ptr< RowSetMemoryOwner row_set_mem_owner 
)

Definition at line 56 of file WindowContext.cpp.

References CHECK, and partitions_.

62  : window_func_(window_func)
63  , partitions_(partitions)
64  , elem_count_(elem_count)
65  , output_(nullptr)
66  , partition_start_(nullptr)
67  , partition_end_(nullptr)
68  , device_type_(device_type)
69  , row_set_mem_owner_(row_set_mem_owner)
70  , dummy_count_(elem_count)
71  , dummy_offset_(0)
72  , dummy_payload_(nullptr) {
73  CHECK(partitions_); // This version should have hash table
74 }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
const int32_t dummy_count_
const int32_t dummy_offset_
const Analyzer::WindowFunction * window_func_
std::shared_ptr< HashJoin > partitions_
#define CHECK(condition)
Definition: Logger.h:209
const ExecutorDeviceType device_type_
WindowFunctionContext::WindowFunctionContext ( const WindowFunctionContext )
delete
WindowFunctionContext::~WindowFunctionContext ( )

Definition at line 76 of file WindowContext.cpp.

References dummy_payload_, partition_end_, and partition_start_.

76  {
77  free(partition_start_);
78  free(partition_end_);
79  if (dummy_payload_) {
80  free(dummy_payload_);
81  }
82 }

Member Function Documentation

void WindowFunctionContext::addOrderColumn ( const int8_t *  column,
const Analyzer::ColumnVar col_var,
const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &  chunks_owner 
)

Definition at line 84 of file WindowContext.cpp.

References order_columns_, and order_columns_owner_.

87  {
88  order_columns_owner_.push_back(chunks_owner);
89  order_columns_.push_back(column);
90 }
std::vector< const int8_t * > order_columns_
std::vector< std::vector< std::shared_ptr< Chunk_NS::Chunk > > > order_columns_owner_
const int64_t * WindowFunctionContext::aggregateState ( ) const

Definition at line 531 of file WindowContext.cpp.

References aggregate_state_, CHECK, Analyzer::WindowFunction::getKind(), WindowFunctionContext::AggregateState::val, window_func_, and window_function_is_aggregate().

531  {
533  return &aggregate_state_.val;
534 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1595
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:42
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

const int64_t * WindowFunctionContext::aggregateStateCount ( ) const

Definition at line 536 of file WindowContext.cpp.

References aggregate_state_, CHECK, WindowFunctionContext::AggregateState::count, Analyzer::WindowFunction::getKind(), window_func_, and window_function_is_aggregate().

536  {
538  return &aggregate_state_.count;
539 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1595
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:42
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

int64_t WindowFunctionContext::aggregateStatePendingOutputs ( ) const

Definition at line 541 of file WindowContext.cpp.

References aggregate_state_, CHECK, Analyzer::WindowFunction::getKind(), WindowFunctionContext::AggregateState::outputs, window_func_, and window_function_is_aggregate().

541  {
543  return reinterpret_cast<int64_t>(&aggregate_state_.outputs);
544 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1595
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:42
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the call graph for this function:

void WindowFunctionContext::compute ( )

Definition at line 441 of file WindowContext.cpp.

References CHECK, CHECK_EQ, computePartition(), gpu_enabled::copy(), counts(), elem_count_, fillPartitionEnd(), fillPartitionStart(), Analyzer::WindowFunction::getCollation(), Analyzer::WindowFunction::getKind(), Analyzer::WindowFunction::getOrderKeys(), i, gpu_enabled::iota(), makeComparator(), offsets(), order_columns_, output_, partitionCount(), payload(), row_set_mem_owner_, gpu_enabled::sort(), window_func_, anonymous_namespace{WindowContext.cpp}::window_function_buffer_element_size(), window_function_is_aggregate(), window_function_is_value(), and window_function_requires_peer_handling().

441  {
442  CHECK(!output_);
443  output_ = static_cast<int8_t*>(row_set_mem_owner_->allocate(
445  /*thread_idx=*/0));
450  }
451  }
452  std::unique_ptr<int64_t[]> scratchpad(new int64_t[elem_count_]);
453  int64_t off = 0;
454  const size_t partition_count{partitionCount()};
455  for (size_t i = 0; i < partition_count; ++i) {
456  auto partition_size = counts()[i];
457  if (partition_size == 0) {
458  continue;
459  }
460  auto output_for_partition_buff = scratchpad.get() + offsets()[i];
461  std::iota(output_for_partition_buff,
462  output_for_partition_buff + partition_size,
463  int64_t(0));
464  std::vector<Comparator> comparators;
465  const auto& order_keys = window_func_->getOrderKeys();
466  const auto& collation = window_func_->getCollation();
467  CHECK_EQ(order_keys.size(), collation.size());
468  for (size_t order_column_idx = 0; order_column_idx < order_columns_.size();
469  ++order_column_idx) {
470  auto order_column_buffer = order_columns_[order_column_idx];
471  const auto order_col =
472  dynamic_cast<const Analyzer::ColumnVar*>(order_keys[order_column_idx].get());
473  CHECK(order_col);
474  const auto& order_col_collation = collation[order_column_idx];
475  const auto asc_comparator = makeComparator(order_col,
476  order_column_buffer,
477  payload() + offsets()[i],
478  order_col_collation.nulls_first);
479  auto comparator = asc_comparator;
480  if (order_col_collation.is_desc) {
481  comparator = [asc_comparator](const int64_t lhs, const int64_t rhs) {
482  return asc_comparator(rhs, lhs);
483  };
484  }
485  comparators.push_back(comparator);
486  }
487  const auto col_tuple_comparator = [&comparators](const int64_t lhs,
488  const int64_t rhs) {
489  for (const auto& comparator : comparators) {
490  if (comparator(lhs, rhs)) {
491  return true;
492  }
493  }
494  return false;
495  };
496  std::sort(output_for_partition_buff,
497  output_for_partition_buff + partition_size,
498  col_tuple_comparator);
499  computePartition(output_for_partition_buff,
500  partition_size,
501  off,
502  window_func_,
503  col_tuple_comparator);
506  off += partition_size;
507  }
508  }
511  CHECK_EQ(static_cast<size_t>(off), elem_count_);
512  }
513  auto output_i64 = reinterpret_cast<int64_t*>(output_);
515  std::copy(scratchpad.get(), scratchpad.get() + elem_count_, output_i64);
516  } else {
517  for (size_t i = 0; i < elem_count_; ++i) {
518  output_i64[payload()[i]] = scratchpad[i];
519  }
520  }
521 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1595
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
const Analyzer::WindowFunction * window_func_
const int32_t * counts() const
const int32_t * offsets() const
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:1603
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:1607
void computePartition(int64_t *output_for_partition_buff, const size_t partition_size, const size_t off, const Analyzer::WindowFunction *window_func, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
size_t partitionCount() const
bool window_function_is_value(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:27
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
static Comparator makeComparator(const Analyzer::ColumnVar *col_var, const int8_t *partition_values, const int32_t *partition_indices, const bool nulls_first)
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:42
DEVICE void iota(ARGS &&...args)
Definition: gpu_enabled.h:69
bool window_function_requires_peer_handling(const Analyzer::WindowFunction *window_func)
size_t window_function_buffer_element_size(const SqlWindowFunctionKind)
#define CHECK(condition)
Definition: Logger.h:209
std::vector< const int8_t * > order_columns_
const int32_t * payload() const

+ Here is the call graph for this function:

void WindowFunctionContext::computePartition ( int64_t *  output_for_partition_buff,
const size_t  partition_size,
const size_t  off,
const Analyzer::WindowFunction window_func,
const std::function< bool(const int64_t lhs, const int64_t rhs)> &  comparator 
)
private

Definition at line 677 of file WindowContext.cpp.

References anonymous_namespace{WindowContext.cpp}::apply_first_value_to_partition(), anonymous_namespace{WindowContext.cpp}::apply_lag_to_partition(), anonymous_namespace{WindowContext.cpp}::apply_last_value_to_partition(), anonymous_namespace{WindowContext.cpp}::apply_permutation_to_partition(), run_benchmark_import::args, AVG, CHECK_EQ, gpu_enabled::copy(), COUNT, CUME_DIST, DENSE_RANK, FIRST_VALUE, anonymous_namespace{WindowContext.cpp}::get_int_constant_from_expr(), anonymous_namespace{WindowContext.cpp}::get_lag_or_lead_argument(), Analyzer::WindowFunction::getArgs(), Analyzer::WindowFunction::getKind(), anonymous_namespace{WindowContext.cpp}::index_to_cume_dist(), anonymous_namespace{WindowContext.cpp}::index_to_dense_rank(), anonymous_namespace{WindowContext.cpp}::index_to_ntile(), anonymous_namespace{WindowContext.cpp}::index_to_partition_end(), anonymous_namespace{WindowContext.cpp}::index_to_percent_rank(), anonymous_namespace{WindowContext.cpp}::index_to_rank(), anonymous_namespace{WindowContext.cpp}::index_to_row_number(), LAG, LAST_VALUE, LEAD, MAX, MIN, anonymous_namespace{Utm.h}::n, NTILE, partitionEnd(), payload(), PERCENT_RANK, RANK, ROW_NUMBER, SUM, toString(), and window_function_requires_peer_handling().

Referenced by compute().

682  {
683  switch (window_func->getKind()) {
685  const auto row_numbers =
686  index_to_row_number(output_for_partition_buff, partition_size);
687  std::copy(row_numbers.begin(), row_numbers.end(), output_for_partition_buff);
688  break;
689  }
691  const auto rank =
692  index_to_rank(output_for_partition_buff, partition_size, comparator);
693  std::copy(rank.begin(), rank.end(), output_for_partition_buff);
694  break;
695  }
697  const auto dense_rank =
698  index_to_dense_rank(output_for_partition_buff, partition_size, comparator);
699  std::copy(dense_rank.begin(), dense_rank.end(), output_for_partition_buff);
700  break;
701  }
703  const auto percent_rank =
704  index_to_percent_rank(output_for_partition_buff, partition_size, comparator);
705  std::copy(percent_rank.begin(),
706  percent_rank.end(),
707  reinterpret_cast<double*>(may_alias_ptr(output_for_partition_buff)));
708  break;
709  }
711  const auto cume_dist =
712  index_to_cume_dist(output_for_partition_buff, partition_size, comparator);
713  std::copy(cume_dist.begin(),
714  cume_dist.end(),
715  reinterpret_cast<double*>(may_alias_ptr(output_for_partition_buff)));
716  break;
717  }
719  const auto& args = window_func->getArgs();
720  CHECK_EQ(args.size(), size_t(1));
721  const auto n = get_int_constant_from_expr(args.front().get());
722  const auto ntile = index_to_ntile(output_for_partition_buff, partition_size, n);
723  std::copy(ntile.begin(), ntile.end(), output_for_partition_buff);
724  break;
725  }
728  const auto lag_or_lead = get_lag_or_lead_argument(window_func);
729  const auto partition_row_offsets = payload() + off;
731  lag_or_lead, partition_row_offsets, output_for_partition_buff, partition_size);
732  break;
733  }
735  const auto partition_row_offsets = payload() + off;
737  partition_row_offsets, output_for_partition_buff, partition_size);
738  break;
739  }
741  const auto partition_row_offsets = payload() + off;
743  partition_row_offsets, output_for_partition_buff, partition_size);
744  break;
745  }
751  const auto partition_row_offsets = payload() + off;
752  if (window_function_requires_peer_handling(window_func)) {
754  partitionEnd(), off, output_for_partition_buff, partition_size, comparator);
755  }
757  output_for_partition_buff, partition_row_offsets, partition_size);
758  break;
759  }
760  default: {
761  throw std::runtime_error("Window function not supported yet: " +
762  ::toString(window_func->getKind()));
763  }
764  }
765 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1595
std::string toString(const ExtArgumentType &sig_type)
std::vector< int64_t > index_to_ntile(const int64_t *index, const size_t index_size, const size_t n)
std::vector< double > index_to_percent_rank(const int64_t *index, const size_t index_size, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
void apply_permutation_to_partition(int64_t *output_for_partition_buff, const int32_t *original_indices, const size_t partition_size)
int64_t get_lag_or_lead_argument(const Analyzer::WindowFunction *window_func)
void index_to_partition_end(const int8_t *partition_end, const size_t off, const int64_t *index, const size_t index_size, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
std::vector< int64_t > index_to_row_number(const int64_t *index, const size_t index_size)
std::vector< int64_t > index_to_dense_rank(const int64_t *index, const size_t index_size, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
void apply_last_value_to_partition(const int32_t *original_indices, int64_t *output_for_partition_buff, const size_t partition_size)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:1597
const int8_t * partitionEnd() const
DEVICE auto copy(ARGS &&...args)
Definition: gpu_enabled.h:51
void apply_first_value_to_partition(const int32_t *original_indices, int64_t *output_for_partition_buff, const size_t partition_size)
void apply_lag_to_partition(const int64_t lag, const int32_t *original_indices, int64_t *sorted_indices, const size_t partition_size)
bool window_function_requires_peer_handling(const Analyzer::WindowFunction *window_func)
std::vector< double > index_to_cume_dist(const int64_t *index, const size_t index_size, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
std::vector< int64_t > index_to_rank(const int64_t *index, const size_t index_size, const std::function< bool(const int64_t lhs, const int64_t rhs)> &comparator)
const int32_t * payload() const
size_t get_int_constant_from_expr(const Analyzer::Expr *expr)
constexpr double n
Definition: Utm.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int32_t * WindowFunctionContext::counts ( ) const
private

Definition at line 827 of file WindowContext.cpp.

References device_type_, dummy_count_, and partitions_.

Referenced by compute(), fillPartitionEnd(), fillPartitionStart(), and partitionCount().

827  {
828  if (partitions_) {
829  return reinterpret_cast<const int32_t*>(
830  partitions_->getJoinHashBuffer(device_type_, 0) + partitions_->countBufferOff());
831  }
832  return &dummy_count_;
833 }
const int32_t dummy_count_
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the caller graph for this function:

size_t WindowFunctionContext::elementCount ( ) const

Definition at line 554 of file WindowContext.cpp.

References elem_count_.

554  {
555  return elem_count_;
556 }
void WindowFunctionContext::fillPartitionEnd ( )
private

Definition at line 786 of file WindowContext.cpp.

References agg_count_distinct_bitmap(), Bitmap, checked_calloc(), counts(), CPU, elem_count_, i, gpu_enabled::partial_sum(), partition_end_, and partitionCount().

Referenced by compute().

786  {
788  0,
789  static_cast<int64_t>(elem_count_),
790  false,
792  1};
793  partition_end_ = static_cast<int8_t*>(
794  checked_calloc(partition_start_bitmap.bitmapPaddedSizeBytes(), 1));
795  int64_t partition_count = partitionCount();
796  std::vector<size_t> partition_offsets(partition_count);
797  std::partial_sum(counts(), counts() + partition_count, partition_offsets.begin());
798  auto partition_end_handle = reinterpret_cast<int64_t>(partition_end_);
799  for (int64_t i = 0; i < partition_count - 1; ++i) {
800  if (partition_offsets[i] == 0) {
801  continue;
802  }
803  agg_count_distinct_bitmap(&partition_end_handle, partition_offsets[i] - 1, 0);
804  }
805  if (elem_count_) {
806  agg_count_distinct_bitmap(&partition_end_handle, elem_count_ - 1, 0);
807  }
808 }
const int32_t * counts() const
size_t partitionCount() const
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WindowFunctionContext::fillPartitionStart ( )
private

Definition at line 767 of file WindowContext.cpp.

References agg_count_distinct_bitmap(), Bitmap, checked_calloc(), counts(), CPU, elem_count_, i, gpu_enabled::partial_sum(), partition_start_, and partitionCount().

Referenced by compute().

767  {
769  0,
770  static_cast<int64_t>(elem_count_),
771  false,
773  1};
774  partition_start_ = static_cast<int8_t*>(
775  checked_calloc(partition_start_bitmap.bitmapPaddedSizeBytes(), 1));
776  int64_t partition_count = partitionCount();
777  std::vector<size_t> partition_offsets(partition_count);
778  std::partial_sum(counts(), counts() + partition_count, partition_offsets.begin());
779  auto partition_start_handle = reinterpret_cast<int64_t>(partition_start_);
780  agg_count_distinct_bitmap(&partition_start_handle, 0, 0);
781  for (int64_t i = 0; i < partition_count - 1; ++i) {
782  agg_count_distinct_bitmap(&partition_start_handle, partition_offsets[i], 0);
783  }
784 }
const int32_t * counts() const
size_t partitionCount() const
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Analyzer::WindowFunction * WindowFunctionContext::getWindowFunction ( ) const

Definition at line 523 of file WindowContext.cpp.

References window_func_.

Referenced by Executor::codegenWindowFunction().

523  {
524  return window_func_;
525 }
const Analyzer::WindowFunction * window_func_

+ Here is the caller graph for this function:

std::function< bool(const int64_t lhs, const int64_t rhs)> WindowFunctionContext::makeComparator ( const Analyzer::ColumnVar col_var,
const int8_t *  partition_values,
const int32_t *  partition_indices,
const bool  nulls_first 
)
staticprivate

Definition at line 613 of file WindowContext.cpp.

References logger::FATAL, Analyzer::Expr::get_type_info(), kDOUBLE, kFLOAT, and LOG.

Referenced by compute().

616  {
617  const auto& ti = col_var->get_type_info();
618  if (ti.is_integer() || ti.is_decimal() || ti.is_time() || ti.is_boolean()) {
619  switch (ti.get_size()) {
620  case 8: {
621  return [order_column_buffer, nulls_first, partition_indices, &ti](
622  const int64_t lhs, const int64_t rhs) {
623  return integer_comparator<int64_t>(
624  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
625  };
626  }
627  case 4: {
628  return [order_column_buffer, nulls_first, partition_indices, &ti](
629  const int64_t lhs, const int64_t rhs) {
630  return integer_comparator<int32_t>(
631  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
632  };
633  }
634  case 2: {
635  return [order_column_buffer, nulls_first, partition_indices, &ti](
636  const int64_t lhs, const int64_t rhs) {
637  return integer_comparator<int16_t>(
638  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
639  };
640  }
641  case 1: {
642  return [order_column_buffer, nulls_first, partition_indices, &ti](
643  const int64_t lhs, const int64_t rhs) {
644  return integer_comparator<int8_t>(
645  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
646  };
647  }
648  default: {
649  LOG(FATAL) << "Invalid type size: " << ti.get_size();
650  }
651  }
652  }
653  if (ti.is_fp()) {
654  switch (ti.get_type()) {
655  case kFLOAT: {
656  return [order_column_buffer, nulls_first, partition_indices, &ti](
657  const int64_t lhs, const int64_t rhs) {
658  return fp_comparator<float, int32_t>(
659  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
660  };
661  }
662  case kDOUBLE: {
663  return [order_column_buffer, nulls_first, partition_indices, &ti](
664  const int64_t lhs, const int64_t rhs) {
665  return fp_comparator<double, int64_t>(
666  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
667  };
668  }
669  default: {
670  LOG(FATAL) << "Invalid float type";
671  }
672  }
673  }
674  throw std::runtime_error("Type not supported yet");
675 }
#define LOG(tag)
Definition: Logger.h:203
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int32_t * WindowFunctionContext::offsets ( ) const
private

Definition at line 819 of file WindowContext.cpp.

References device_type_, dummy_offset_, and partitions_.

Referenced by compute(), and partitionCount().

819  {
820  if (partitions_) {
821  return reinterpret_cast<const int32_t*>(
822  partitions_->getJoinHashBuffer(device_type_, 0) + partitions_->offsetBufferOff());
823  }
824  return &dummy_offset_;
825 }
const int32_t dummy_offset_
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the caller graph for this function:

WindowFunctionContext& WindowFunctionContext::operator= ( const WindowFunctionContext )
delete
const int8_t * WindowFunctionContext::output ( ) const

Definition at line 527 of file WindowContext.cpp.

References output_.

Referenced by CodeGenerator::codegenWindowPosition().

527  {
528  return output_;
529 }

+ Here is the caller graph for this function:

size_t WindowFunctionContext::partitionCount ( ) const
private

Definition at line 835 of file WindowContext.cpp.

References CHECK_GE, counts(), offsets(), and partitions_.

Referenced by compute(), fillPartitionEnd(), and fillPartitionStart().

835  {
836  if (partitions_) {
837  const auto partition_count = counts() - offsets();
838  CHECK_GE(partition_count, 0);
839  return partition_count;
840  }
841  return 1; // non-partitioned window function
842 }
#define CHECK_GE(x, y)
Definition: Logger.h:222
const int32_t * counts() const
const int32_t * offsets() const
std::shared_ptr< HashJoin > partitions_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int8_t * WindowFunctionContext::partitionEnd ( ) const

Definition at line 550 of file WindowContext.cpp.

References partition_end_.

Referenced by computePartition().

550  {
551  return partition_end_;
552 }

+ Here is the caller graph for this function:

const int8_t * WindowFunctionContext::partitionStart ( ) const

Definition at line 546 of file WindowContext.cpp.

References partition_start_.

546  {
547  return partition_start_;
548 }
const int32_t * WindowFunctionContext::payload ( ) const
private

Definition at line 810 of file WindowContext.cpp.

References device_type_, dummy_payload_, and partitions_.

Referenced by compute(), and computePartition().

810  {
811  if (partitions_) {
812  return reinterpret_cast<const int32_t*>(
813  partitions_->getJoinHashBuffer(device_type_, 0) +
814  partitions_->payloadBufferOff());
815  }
816  return dummy_payload_; // non-partitioned window function
817 }
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the caller graph for this function:

Member Data Documentation

AggregateState WindowFunctionContext::aggregate_state_
private
const ExecutorDeviceType WindowFunctionContext::device_type_
private

Definition at line 173 of file WindowContext.h.

Referenced by counts(), offsets(), and payload().

const int32_t WindowFunctionContext::dummy_count_
private

Definition at line 177 of file WindowContext.h.

Referenced by counts().

const int32_t WindowFunctionContext::dummy_offset_
private

Definition at line 178 of file WindowContext.h.

Referenced by offsets().

int32_t* WindowFunctionContext::dummy_payload_
private

Definition at line 183 of file WindowContext.h.

Referenced by payload(), WindowFunctionContext(), and ~WindowFunctionContext().

size_t WindowFunctionContext::elem_count_
private
std::vector<const int8_t*> WindowFunctionContext::order_columns_
private

Definition at line 158 of file WindowContext.h.

Referenced by addOrderColumn(), and compute().

std::vector<std::vector<std::shared_ptr<Chunk_NS::Chunk> > > WindowFunctionContext::order_columns_owner_
private

Definition at line 156 of file WindowContext.h.

Referenced by addOrderColumn().

int8_t* WindowFunctionContext::output_
private

Definition at line 164 of file WindowContext.h.

Referenced by compute(), and output().

int8_t* WindowFunctionContext::partition_end_
private

Definition at line 170 of file WindowContext.h.

Referenced by fillPartitionEnd(), partitionEnd(), and ~WindowFunctionContext().

int8_t* WindowFunctionContext::partition_start_
private

Definition at line 167 of file WindowContext.h.

Referenced by fillPartitionStart(), partitionStart(), and ~WindowFunctionContext().

std::shared_ptr<HashJoin> WindowFunctionContext::partitions_
private

Definition at line 160 of file WindowContext.h.

Referenced by counts(), offsets(), partitionCount(), payload(), and WindowFunctionContext().

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

Definition at line 174 of file WindowContext.h.

Referenced by compute().

const Analyzer::WindowFunction* WindowFunctionContext::window_func_
private

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