OmniSciDB  c0231cc57d
 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

enum  WindowComparatorResult { WindowComparatorResult::LT, WindowComparatorResult::EQ, WindowComparatorResult::GT }
 
using Comparator = std::function< WindowFunctionContext::WindowComparatorResult(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, QueryPlanHash cache_key, const std::shared_ptr< HashJoin > &partitions, const size_t elem_count, const ExecutorDeviceType device_type, std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner, size_t aggregation_tree_fan_out=g_window_function_aggregation_tree_fanout)
 
 WindowFunctionContext (const WindowFunctionContext &)=delete
 
WindowFunctionContextoperator= (const WindowFunctionContext &)=delete
 
 ~WindowFunctionContext ()
 
void addOrderColumn (const int8_t *column, const SQLTypeInfo &ti, const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner)
 
void setSortedPartitionCacheKey (QueryPlanHash cache_key)
 
void addColumnBufferForWindowFunctionExpression (const int8_t *column, const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &chunks_owner)
 
std::vector< ComparatorcreateComparator (size_t partition_idx)
 
void compute (std::unordered_map< QueryPlanHash, size_t > &sorted_partition_key_ref_count_map, std::unordered_map< QueryPlanHash, std::shared_ptr< std::vector< int64_t >>> &sorted_partition_cache)
 
const Analyzer::WindowFunctiongetWindowFunction () const
 
const int8_t * output () const
 
const int64_t * sortedPartition () const
 
const int64_t * aggregateState () const
 
const int64_t * aggregateStateCount () const
 
int64_t aggregateStatePendingOutputs () const
 
const int64_t * partitionStartOffset () const
 
const int64_t * partitionNumCountBuf () const
 
const std::vector< const
int8_t * > & 
getColumnBufferForWindowFunctionExpressions () const
 
const std::vector< const
int8_t * > & 
getOrderKeyColumnBuffers () const
 
const std::vector< SQLTypeInfo > & getOrderKeyColumnBufferTypes () const
 
int64_t ** getAggregationTreesForIntegerTypeWindowExpr () const
 
double ** getAggregationTreesForDoubleTypeWindowExpr () const
 
SumAndCountPair< int64_t > ** getDerivedAggregationTreesForIntegerTypeWindowExpr () const
 
SumAndCountPair< double > ** getDerivedAggregationTreesForDoubleTypeWindowExpr () const
 
size_t * getAggregateTreeDepth () const
 
size_t getAggregateTreeFanout () const
 
int64_t * getNullValueStartPos () const
 
int64_t * getNullValueEndPos () const
 
const int8_t * partitionStart () const
 
const int8_t * partitionEnd () const
 
size_t elementCount () const
 
const int32_t * payload () const
 
const int32_t * offsets () const
 
const int32_t * counts () const
 
size_t partitionCount () const
 
const bool needsToBuildAggregateTree () const
 

Private Member Functions

void computePartitionBuffer (const size_t partition_idx, int64_t *output_for_partition_buff, const Analyzer::WindowFunction *window_func)
 
void sortPartition (const size_t partition_idx, int64_t *output_for_partition_buff, bool should_parallelize)
 
void computeNullRangeOfSortedPartition (const SQLTypeInfo &order_col_ti, size_t partition_idx, const int32_t *original_col_idx_buf, const int64_t *ordered_col_idx_buf)
 
void buildAggregationTreeForPartition (SqlWindowFunctionKind agg_type, size_t partition_idx, size_t partition_size, const int8_t *col_buf, const int32_t *original_rowid_buf, const int64_t *ordered_rowid_buf, const SQLTypeInfo &input_col_ti)
 
void fillPartitionStart ()
 
void fillPartitionEnd ()
 

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_
 
QueryPlanHash partition_cache_key_
 
QueryPlanHash sorted_partition_cache_key_
 
std::vector< std::vector
< std::shared_ptr
< Chunk_NS::Chunk > > > 
order_columns_owner_
 
std::vector< const int8_t * > order_columns_
 
std::vector< SQLTypeInfoorder_columns_ti_
 
std::shared_ptr< HashJoinpartitions_
 
size_t elem_count_
 
int8_t * output_
 
std::shared_ptr< std::vector
< int64_t > > 
sorted_partition_buf_
 
std::vector< std::vector
< std::shared_ptr
< Chunk_NS::Chunk > > > 
window_func_expr_columns_owner_
 
std::vector< const int8_t * > window_func_expr_columns_
 
std::vector< std::shared_ptr
< void > > 
segment_trees_owned_
 
AggregateTreeForWindowFraming aggregate_trees_
 
size_t aggregate_trees_fan_out_
 
size_t * aggregate_trees_depth_
 
int64_t * ordered_partition_null_start_pos_
 
int64_t * ordered_partition_null_end_pos_
 
int64_t * partition_start_offset_
 
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 75 of file WindowContext.h.

Member Typedef Documentation

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

Definition at line 113 of file WindowContext.h.

Member Enumeration Documentation

Enumerator
LT 
EQ 
GT 

Definition at line 110 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 50 of file WindowContext.cpp.

References aggregate_trees_depth_, CHECK_LE, checked_calloc(), checked_malloc(), dummy_payload_, elem_count_, Analyzer::WindowFunction::hasFraming(), gpu_enabled::iota(), ordered_partition_null_end_pos_, ordered_partition_null_start_pos_, partition_start_offset_, and window_func_.

55  : window_func_(window_func)
58  , partitions_(nullptr)
59  , elem_count_(elem_count)
60  , output_(nullptr)
61  , sorted_partition_buf_(nullptr)
63  , aggregate_trees_depth_(nullptr)
66  , partition_start_offset_(nullptr)
67  , partition_start_(nullptr)
68  , partition_end_(nullptr)
69  , device_type_(device_type)
70  , row_set_mem_owner_(row_set_mem_owner)
71  , dummy_count_(elem_count)
72  , dummy_offset_(0)
73  , dummy_payload_(nullptr) {
74  CHECK_LE(elem_count_, static_cast<size_t>(std::numeric_limits<int32_t>::max()));
76  reinterpret_cast<int32_t*>(checked_malloc(elem_count_ * sizeof(int32_t)));
78  if (window_func_->hasFraming()) {
79  // in this case, we consider all rows of the row belong to the same and only
80  // existing partition
82  reinterpret_cast<int64_t*>(checked_calloc(2, sizeof(int64_t)));
84  aggregate_trees_depth_ = reinterpret_cast<size_t*>(checked_calloc(1, sizeof(size_t)));
86  reinterpret_cast<int64_t*>(checked_calloc(1, sizeof(int64_t)));
88  reinterpret_cast<int64_t*>(checked_calloc(1, sizeof(int64_t)));
89  }
90 }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
int64_t * ordered_partition_null_start_pos_
const int32_t dummy_count_
const int32_t dummy_offset_
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
const Analyzer::WindowFunction * window_func_
std::shared_ptr< std::vector< int64_t > > sorted_partition_buf_
size_t g_window_function_aggregation_tree_fanout
QueryPlanHash sorted_partition_cache_key_
void * checked_malloc(const size_t size)
Definition: checked_alloc.h:45
QueryPlanHash partition_cache_key_
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
#define CHECK_LE(x, y)
Definition: Logger.h:233
DEVICE void iota(ARGS &&...args)
Definition: gpu_enabled.h:69
std::shared_ptr< HashJoin > partitions_
int64_t * partition_start_offset_
size_t * aggregate_trees_depth_
bool hasFraming() const
Definition: Analyzer.h:2442
const ExecutorDeviceType device_type_
int64_t * ordered_partition_null_end_pos_

+ Here is the call graph for this function:

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

Definition at line 93 of file WindowContext.cpp.

References aggregate_trees_depth_, CHECK, checked_calloc(), counts(), Analyzer::WindowFunction::hasFraming(), ordered_partition_null_end_pos_, ordered_partition_null_start_pos_, gpu_enabled::partial_sum(), partition_start_offset_, partitionCount(), partitions_, and window_func_.

101  : window_func_(window_func)
102  , partition_cache_key_(partition_cache_key)
104  , partitions_(partitions)
105  , elem_count_(elem_count)
106  , output_(nullptr)
107  , sorted_partition_buf_(nullptr)
108  , aggregate_trees_fan_out_(aggregation_tree_fan_out)
109  , aggregate_trees_depth_(nullptr)
112  , partition_start_offset_(nullptr)
113  , partition_start_(nullptr)
114  , partition_end_(nullptr)
115  , device_type_(device_type)
116  , row_set_mem_owner_(row_set_mem_owner)
117  , dummy_count_(elem_count)
118  , dummy_offset_(0)
119  , dummy_payload_(nullptr) {
120  CHECK(partitions_); // This version should have hash table
121  size_t partition_count = partitionCount();
123  reinterpret_cast<int64_t*>(checked_calloc(partition_count + 1, sizeof(int64_t)));
124  if (window_func_->hasFraming()) {
126  reinterpret_cast<size_t*>(checked_calloc(partition_count, sizeof(size_t)));
128  reinterpret_cast<int64_t*>(checked_calloc(partition_count, sizeof(int64_t)));
130  reinterpret_cast<int64_t*>(checked_calloc(partition_count, sizeof(int64_t)));
131  }
132  // the first partition starts at zero position
133  std::partial_sum(counts(), counts() + partition_count, partition_start_offset_ + 1);
134 }
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
int64_t * ordered_partition_null_start_pos_
const int32_t dummy_count_
const int32_t dummy_offset_
constexpr QueryPlanHash EMPTY_HASHED_PLAN_DAG_KEY
const Analyzer::WindowFunction * window_func_
const int32_t * counts() const
std::shared_ptr< std::vector< int64_t > > sorted_partition_buf_
size_t partitionCount() const
QueryPlanHash sorted_partition_cache_key_
DEVICE void partial_sum(ARGS &&...args)
Definition: gpu_enabled.h:87
QueryPlanHash partition_cache_key_
void * checked_calloc(const size_t nmemb, const size_t size)
Definition: checked_alloc.h:53
std::shared_ptr< HashJoin > partitions_
int64_t * partition_start_offset_
#define CHECK(condition)
Definition: Logger.h:222
size_t * aggregate_trees_depth_
bool hasFraming() const
Definition: Analyzer.h:2442
const ExecutorDeviceType device_type_
int64_t * ordered_partition_null_end_pos_

+ Here is the call graph for this function:

WindowFunctionContext::WindowFunctionContext ( const WindowFunctionContext )
delete
WindowFunctionContext::~WindowFunctionContext ( )

Member Function Documentation

void WindowFunctionContext::addColumnBufferForWindowFunctionExpression ( const int8_t *  column,
const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &  chunks_owner 
)

Definition at line 165 of file WindowContext.cpp.

References window_func_expr_columns_, and window_func_expr_columns_owner_.

167  {
168  window_func_expr_columns_owner_.push_back(chunks_owner);
169  window_func_expr_columns_.push_back(column);
170 };
std::vector< std::vector< std::shared_ptr< Chunk_NS::Chunk > > > window_func_expr_columns_owner_
std::vector< const int8_t * > window_func_expr_columns_
void WindowFunctionContext::addOrderColumn ( const int8_t *  column,
const SQLTypeInfo ti,
const std::vector< std::shared_ptr< Chunk_NS::Chunk >> &  chunks_owner 
)

Definition at line 156 of file WindowContext.cpp.

References order_columns_, order_columns_owner_, and order_columns_ti_.

159  {
160  order_columns_owner_.push_back(chunks_owner);
161  order_columns_.push_back(column);
162  order_columns_ti_.push_back(ti);
163 }
std::vector< const int8_t * > order_columns_
std::vector< SQLTypeInfo > order_columns_ti_
std::vector< std::vector< std::shared_ptr< Chunk_NS::Chunk > > > order_columns_owner_
const int64_t * WindowFunctionContext::aggregateState ( ) const

Definition at line 977 of file WindowContext.cpp.

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

977  {
979  return &aggregate_state_.val;
980 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2406
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:44
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

const int64_t * WindowFunctionContext::aggregateStateCount ( ) const

Definition at line 982 of file WindowContext.cpp.

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

982  {
984  return &aggregate_state_.count;
985 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2406
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:44
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

int64_t WindowFunctionContext::aggregateStatePendingOutputs ( ) const

Definition at line 997 of file WindowContext.cpp.

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

997  {
999  return reinterpret_cast<int64_t>(&aggregate_state_.outputs);
1000 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2406
const Analyzer::WindowFunction * window_func_
AggregateState aggregate_state_
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:44
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

void WindowFunctionContext::buildAggregationTreeForPartition ( SqlWindowFunctionKind  agg_type,
size_t  partition_idx,
size_t  partition_size,
const int8_t *  col_buf,
const int32_t *  original_rowid_buf,
const int64_t *  ordered_rowid_buf,
const SQLTypeInfo input_col_ti 
)
private

Definition at line 1268 of file WindowContext.cpp.

References AggregateTreeForWindowFraming::aggregate_tree_for_double_type_, AggregateTreeForWindowFraming::aggregate_tree_for_integer_type_, aggregate_trees_, aggregate_trees_depth_, aggregate_trees_fan_out_, AVG, CHECK, decimal_to_int_type(), AggregateTreeForWindowFraming::derived_aggregate_tree_for_double_type_, AggregateTreeForWindowFraming::derived_aggregate_tree_for_integer_type_, SQLTypeInfo::get_type(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_number(), kBIGINT, kDECIMAL, kDOUBLE, kFLOAT, kINT, kNUMERIC, kSMALLINT, kTINYINT, offsets(), ordered_partition_null_end_pos_, ordered_partition_null_start_pos_, segment_trees_owned_, toString(), run_benchmark_import::type, UNREACHABLE, and VLOG.

Referenced by compute().

1275  {
1276  CHECK(col_buf);
1277  if (!input_col_ti.is_number()) {
1278  throw QueryNotSupported("Window aggregate function over frame on a column type " +
1279  ::toString(input_col_ti.get_type()) + " is not supported.");
1280  }
1281  const auto type = input_col_ti.is_decimal() ? decimal_to_int_type(input_col_ti)
1282  : input_col_ti.get_type();
1283  if (partition_size > 0) {
1284  IndexPair order_col_null_range{ordered_partition_null_start_pos_[partition_idx],
1285  ordered_partition_null_end_pos_[partition_idx]};
1286  const int64_t* ordered_rowid_buf_for_partition =
1287  ordered_rowid_buf + offsets()[partition_idx];
1288  VLOG(2) << "Build Aggregation Tree For Partition-" << ::toString(partition_idx)
1289  << " (# elems: " << ::toString(partition_size)
1290  << ", null_range: " << order_col_null_range.first << " ~ "
1291  << order_col_null_range.second << ")";
1292  switch (type) {
1293  case kTINYINT: {
1294  const auto segment_tree = std::make_shared<SegmentTree<int8_t, int64_t>>(
1295  col_buf,
1296  input_col_ti,
1297  original_rowid_buf,
1298  ordered_rowid_buf_for_partition,
1299  order_col_null_range,
1300  partition_size,
1301  agg_type,
1303  aggregate_trees_depth_[partition_idx] =
1304  segment_tree ? segment_tree->getLeafDepth() : 0;
1305  if (agg_type == SqlWindowFunctionKind::AVG) {
1307  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1308  } else {
1310  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1311  }
1312  segment_trees_owned_.emplace_back(std::move(segment_tree));
1313  break;
1314  }
1315  case kSMALLINT: {
1316  const auto segment_tree = std::make_shared<SegmentTree<int16_t, int64_t>>(
1317  col_buf,
1318  input_col_ti,
1319  original_rowid_buf,
1320  ordered_rowid_buf_for_partition,
1321  order_col_null_range,
1322  partition_size,
1323  agg_type,
1325  aggregate_trees_depth_[partition_idx] =
1326  segment_tree ? segment_tree->getLeafDepth() : 0;
1327  if (agg_type == SqlWindowFunctionKind::AVG) {
1329  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1330  } else {
1332  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1333  }
1334  segment_trees_owned_.emplace_back(std::move(segment_tree));
1335  break;
1336  }
1337  case kINT: {
1338  const auto segment_tree = std::make_shared<SegmentTree<int32_t, int64_t>>(
1339  col_buf,
1340  input_col_ti,
1341  original_rowid_buf,
1342  ordered_rowid_buf_for_partition,
1343  order_col_null_range,
1344  partition_size,
1345  agg_type,
1347  aggregate_trees_depth_[partition_idx] =
1348  segment_tree ? segment_tree->getLeafDepth() : 0;
1349  if (agg_type == SqlWindowFunctionKind::AVG) {
1351  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1352  } else {
1354  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1355  }
1356  segment_trees_owned_.emplace_back(std::move(segment_tree));
1357  break;
1358  }
1359  case kDECIMAL:
1360  case kNUMERIC:
1361  case kBIGINT: {
1362  const auto segment_tree = std::make_shared<SegmentTree<int64_t, int64_t>>(
1363  col_buf,
1364  input_col_ti,
1365  original_rowid_buf,
1366  ordered_rowid_buf_for_partition,
1367  order_col_null_range,
1368  partition_size,
1369  agg_type,
1371  aggregate_trees_depth_[partition_idx] =
1372  segment_tree ? segment_tree->getLeafDepth() : 0;
1373  if (agg_type == SqlWindowFunctionKind::AVG) {
1375  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1376  } else {
1378  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1379  }
1380  segment_trees_owned_.emplace_back(std::move(segment_tree));
1381  break;
1382  }
1383  case kFLOAT: {
1384  const auto segment_tree =
1385  std::make_shared<SegmentTree<float, double>>(col_buf,
1386  input_col_ti,
1387  original_rowid_buf,
1388  ordered_rowid_buf_for_partition,
1389  order_col_null_range,
1390  partition_size,
1391  agg_type,
1393  aggregate_trees_depth_[partition_idx] =
1394  segment_tree ? segment_tree->getLeafDepth() : 0;
1395  if (agg_type == SqlWindowFunctionKind::AVG) {
1397  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1398  } else {
1400  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1401  }
1402  segment_trees_owned_.emplace_back(std::move(segment_tree));
1403  break;
1404  }
1405  case kDOUBLE: {
1406  const auto segment_tree =
1407  std::make_shared<SegmentTree<double, double>>(col_buf,
1408  input_col_ti,
1409  original_rowid_buf,
1410  ordered_rowid_buf_for_partition,
1411  order_col_null_range,
1412  partition_size,
1413  agg_type,
1415  aggregate_trees_depth_[partition_idx] =
1416  segment_tree ? segment_tree->getLeafDepth() : 0;
1417  if (agg_type == SqlWindowFunctionKind::AVG) {
1419  segment_tree ? segment_tree->getDerivedAggregatedValues() : nullptr);
1420  } else {
1422  segment_tree ? segment_tree->getAggregatedValues() : nullptr);
1423  }
1424  segment_trees_owned_.emplace_back(std::move(segment_tree));
1425  break;
1426  }
1427  default:
1428  UNREACHABLE();
1429  }
1430  } else {
1431  // handling a case of an empty partition
1432  aggregate_trees_depth_[partition_idx] = 0;
1433  if (input_col_ti.is_integer() || input_col_ti.is_decimal()) {
1434  if (agg_type == SqlWindowFunctionKind::AVG) {
1436  } else {
1438  }
1439  } else {
1440  CHECK(input_col_ti.is_fp());
1441  if (agg_type == SqlWindowFunctionKind::AVG) {
1443  } else {
1445  }
1446  }
1447  }
1448 }
std::vector< SumAndCountPair< double > * > derived_aggregate_tree_for_double_type_
Definition: WindowContext.h:66
int64_t * ordered_partition_null_start_pos_
std::vector< double * > aggregate_tree_for_double_type_
Definition: WindowContext.h:64
#define UNREACHABLE()
Definition: Logger.h:266
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
const int32_t * offsets() const
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
bool is_number() const
Definition: sqltypes.h:605
std::vector< std::shared_ptr< void > > segment_trees_owned_
std::pair< int64_t, int64_t > IndexPair
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:499
AggregateTreeForWindowFraming aggregate_trees_
#define CHECK(condition)
Definition: Logger.h:222
std::vector< SumAndCountPair< int64_t > * > derived_aggregate_tree_for_integer_type_
Definition: WindowContext.h:65
Definition: sqltypes.h:59
size_t * aggregate_trees_depth_
bool is_decimal() const
Definition: sqltypes.h:603
std::vector< int64_t * > aggregate_tree_for_integer_type_
Definition: WindowContext.h:63
#define VLOG(n)
Definition: Logger.h:316
int64_t * ordered_partition_null_end_pos_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WindowFunctionContext::compute ( std::unordered_map< QueryPlanHash, size_t > &  sorted_partition_key_ref_count_map,
std::unordered_map< QueryPlanHash, std::shared_ptr< std::vector< int64_t >>> &  sorted_partition_cache 
)

Definition at line 540 of file WindowContext.cpp.

References buildAggregationTreeForPartition(), CHECK, computeNullRangeOfSortedPartition(), computePartitionBuffer(), counts(), cpu_threads(), DEBUG_TIMER, elem_count_, fillPartitionEnd(), fillPartitionStart(), g_enable_parallel_window_partition_compute, g_parallel_window_partition_compute_threshold, Analyzer::WindowFunction::getArgs(), Analyzer::WindowFunction::getKind(), Analyzer::WindowFunction::getOrderKeys(), Analyzer::WindowFunction::hasFraming(), needsToBuildAggregateTree(), offsets(), output_, partitionCount(), payload(), row_set_mem_owner_, threading_std::task_group::run(), sorted_partition_buf_, sorted_partition_cache_key_, sortPartition(), toString(), VLOG, threading_std::task_group::wait(), window_func_, window_func_expr_columns_, anonymous_namespace{WindowContext.cpp}::window_function_buffer_element_size(), window_function_is_aggregate(), and window_function_requires_peer_handling().

543  {
544  auto timer = DEBUG_TIMER(__func__);
545  CHECK(!output_);
546  if (elem_count_ == 0) {
547  return;
548  }
549  size_t output_buf_sz =
551  output_ = static_cast<int8_t*>(row_set_mem_owner_->allocate(output_buf_sz,
552  /*thread_idx=*/0));
553  const bool is_window_function_aggregate_or_has_framing =
555  if (is_window_function_aggregate_or_has_framing) {
560  }
561  }
562  std::unique_ptr<int64_t[]> scratchpad;
563  int64_t* intermediate_output_buffer;
564  if (is_window_function_aggregate_or_has_framing) {
565  intermediate_output_buffer = reinterpret_cast<int64_t*>(output_);
566  } else {
567  output_buf_sz = sizeof(int64_t) * elem_count_;
568  scratchpad.reset(new int64_t[elem_count_]);
569  intermediate_output_buffer = scratchpad.get();
570  }
571  const bool should_parallelize{g_enable_parallel_window_partition_compute &&
572  elem_count_ >=
574 
575  auto cached_sorted_partition_it =
576  sorted_partition_cache.find(sorted_partition_cache_key_);
577  if (cached_sorted_partition_it != sorted_partition_cache.end()) {
578  auto& sorted_partition = cached_sorted_partition_it->second;
579  VLOG(1) << "Reuse cached sorted partition to compute window function context (key: "
581  << ", ordering condition: " << ::toString(window_func_->getOrderKeys())
582  << ")";
583  DEBUG_TIMER("Window Function Cached Sorted Partition Copy");
584  std::memcpy(intermediate_output_buffer, sorted_partition->data(), output_buf_sz);
585  if (window_func_->hasFraming()) {
586  sorted_partition_buf_ = sorted_partition;
587  }
588  } else {
589  // ordering partitions if necessary
590  const auto sort_partitions = [&](const size_t start, const size_t end) {
591  for (size_t partition_idx = start; partition_idx < end; ++partition_idx) {
592  sortPartition(partition_idx,
593  intermediate_output_buffer + offsets()[partition_idx],
594  should_parallelize);
595  }
596  };
597 
598  if (should_parallelize) {
599  auto sorted_partition_copy_timer =
600  DEBUG_TIMER("Window Function Partition Sorting Parallelized");
601  threading::task_group thread_pool;
602  for (auto interval : makeIntervals<size_t>(0, partitionCount(), cpu_threads())) {
603  thread_pool.run([=] { sort_partitions(interval.begin, interval.end); });
604  }
605  thread_pool.wait();
606  } else {
607  auto sorted_partition_copy_timer =
608  DEBUG_TIMER("Window Function Partition Sorting Non-Parallelized");
609  sort_partitions(0, partitionCount());
610  }
611  auto sorted_partition_ref_cnt_it =
612  sorted_partition_key_ref_count_map.find(sorted_partition_cache_key_);
613  bool can_access_sorted_partition =
614  sorted_partition_ref_cnt_it != sorted_partition_key_ref_count_map.end() &&
615  sorted_partition_ref_cnt_it->second > 1;
616  if (can_access_sorted_partition || window_func_->hasFraming()) {
617  // keep the sorted partition only if it will be reused from other window function
618  // context of this query
619  sorted_partition_buf_ = std::make_shared<std::vector<int64_t>>(elem_count_);
620  DEBUG_TIMER("Window Function Sorted Partition Copy For Caching");
621  std::memcpy(
622  sorted_partition_buf_->data(), intermediate_output_buffer, output_buf_sz);
623  auto it = sorted_partition_cache.emplace(sorted_partition_cache_key_,
625  if (it.second) {
626  VLOG(1) << "Put sorted partition to cache (key: " << sorted_partition_cache_key_
627  << ", ordering condition: " << ::toString(window_func_->getOrderKeys())
628  << ")";
629  }
630  }
631  }
632 
633  if (window_func_->hasFraming()) {
634  const auto compute_ordered_partition_null_range = [=](const size_t start,
635  const size_t end) {
636  for (size_t partition_idx = start; partition_idx < end; ++partition_idx) {
638  window_func_->getOrderKeys().front()->get_type_info(),
639  partition_idx,
640  payload() + offsets()[partition_idx],
641  intermediate_output_buffer + offsets()[partition_idx]);
642  }
643  };
644  auto partition_count = partitionCount();
645  if (should_parallelize) {
646  auto partition_compuation_timer =
647  DEBUG_TIMER("Window Function Ordered-Partition Null-Range Compute");
648  threading::task_group thread_pool;
649  for (auto interval : makeIntervals<size_t>(0, partitionCount(), cpu_threads())) {
650  thread_pool.run(
651  [=] { compute_ordered_partition_null_range(interval.begin, interval.end); });
652  }
653  thread_pool.wait();
654  } else {
655  auto partition_compuation_timer = DEBUG_TIMER(
656  "Window Function Non-Parallelized Ordered-Partition Null-Range Compute");
657  compute_ordered_partition_null_range(0, partitionCount());
658  }
659 
661  const auto build_aggregation_tree_for_partitions = [=](const size_t start,
662  const size_t end) {
663  for (size_t partition_idx = start; partition_idx < end; ++partition_idx) {
664  // build a segment tree for the partition
665  // todo (yoonmin) : support generic window function expression
666  // i.e., when window_func_expr_columns_.size() > 1
667  const auto partition_size = counts()[partition_idx];
670  partition_idx,
671  partition_size,
673  payload() + offsets()[partition_idx],
674  intermediate_output_buffer,
675  window_func_->getArgs().front()->get_type_info());
676  }
677  };
678  if (should_parallelize) {
679  auto partition_compuation_timer =
680  DEBUG_TIMER("Window Function Build Segment Tree for Partitions");
681  threading::task_group thread_pool;
682  for (auto interval : makeIntervals<size_t>(0, partition_count, cpu_threads())) {
683  thread_pool.run([=] {
684  build_aggregation_tree_for_partitions(interval.begin, interval.end);
685  });
686  }
687  thread_pool.wait();
688  } else {
689  auto partition_compuation_timer =
690  DEBUG_TIMER("Window Function Build Segment Tree for Partitions");
691  build_aggregation_tree_for_partitions(0, partition_count);
692  }
693  }
694  }
695 
696  const auto compute_partitions = [=](const size_t start, const size_t end) {
697  for (size_t partition_idx = start; partition_idx < end; ++partition_idx) {
698  computePartitionBuffer(partition_idx,
699  intermediate_output_buffer + offsets()[partition_idx],
700  window_func_);
701  }
702  };
703 
704  if (should_parallelize) {
705  auto partition_compuation_timer = DEBUG_TIMER("Window Function Partition Compute");
706  threading::task_group thread_pool;
707  for (auto interval : makeIntervals<size_t>(0, partitionCount(), cpu_threads())) {
708  thread_pool.run([=] { compute_partitions(interval.begin, interval.end); });
709  }
710  thread_pool.wait();
711  } else {
712  auto partition_compuation_timer =
713  DEBUG_TIMER("Window Function Non-Parallelized Partition Compute");
714  compute_partitions(0, partitionCount());
715  }
716 
717  if (is_window_function_aggregate_or_has_framing) {
718  // If window function is aggregate we were able to write to the final output buffer
719  // directly in computePartition and we are done.
720  return;
721  }
722 
723  auto output_i64 = reinterpret_cast<int64_t*>(output_);
724  const auto payload_copy = [=](const size_t start, const size_t end) {
725  for (size_t i = start; i < end; ++i) {
726  output_i64[payload()[i]] = intermediate_output_buffer[i];
727  }
728  };
729  if (should_parallelize) {
730  auto payload_copy_timer =
731  DEBUG_TIMER("Window Function Non-Aggregate Payload Copy Parallelized");
732  threading::task_group thread_pool;
733  for (auto interval : makeIntervals<size_t>(
734  0,
735  elem_count_,
736  std::min(static_cast<size_t>(cpu_threads()),
739  thread_pool.run([=] { payload_copy(interval.begin, interval.end); });
740  }
741  thread_pool.wait();
742  } else {
743  auto payload_copy_timer =
744  DEBUG_TIMER("Window Function Non-Aggregate Payload Copy Non-Parallelized");
745  payload_copy(0, elem_count_);
746  }
747 }
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2406
std::shared_ptr< RowSetMemoryOwner > row_set_mem_owner_
void computeNullRangeOfSortedPartition(const SQLTypeInfo &order_col_ti, size_t partition_idx, const int32_t *original_col_idx_buf, const int64_t *ordered_col_idx_buf)
const Analyzer::WindowFunction * window_func_
const int32_t * counts() const
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
const int32_t * offsets() const
size_t g_parallel_window_partition_compute_threshold
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:2414
const bool needsToBuildAggregateTree() const
std::shared_ptr< std::vector< int64_t > > sorted_partition_buf_
size_t partitionCount() const
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:2408
QueryPlanHash sorted_partition_cache_key_
void buildAggregationTreeForPartition(SqlWindowFunctionKind agg_type, size_t partition_idx, size_t partition_size, const int8_t *col_buf, const int32_t *original_rowid_buf, const int64_t *ordered_rowid_buf, const SQLTypeInfo &input_col_ti)
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
Definition: WindowContext.h:44
std::vector< const int8_t * > window_func_expr_columns_
void sortPartition(const size_t partition_idx, int64_t *output_for_partition_buff, bool should_parallelize)
bool window_function_requires_peer_handling(const Analyzer::WindowFunction *window_func)
size_t window_function_buffer_element_size(const SqlWindowFunctionKind)
bool g_enable_parallel_window_partition_compute
void computePartitionBuffer(const size_t partition_idx, int64_t *output_for_partition_buff, const Analyzer::WindowFunction *window_func)
#define CHECK(condition)
Definition: Logger.h:222
#define DEBUG_TIMER(name)
Definition: Logger.h:371
const int32_t * payload() const
int cpu_threads()
Definition: thread_count.h:25
bool hasFraming() const
Definition: Analyzer.h:2442
#define VLOG(n)
Definition: Logger.h:316

+ Here is the call graph for this function:

void WindowFunctionContext::computeNullRangeOfSortedPartition ( const SQLTypeInfo order_col_ti,
size_t  partition_idx,
const int32_t *  original_col_idx_buf,
const int64_t *  ordered_col_idx_buf 
)
private

Definition at line 749 of file WindowContext.cpp.

References counts(), logger::FATAL, SQLTypeInfo::get_size(), SQLTypeInfo::get_type(), Analyzer::WindowFunction::getCollation(), SQLTypeInfo::is_boolean(), SQLTypeInfo::is_decimal(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_time(), kDOUBLE, kFLOAT, LOG, null_val_bit_pattern(), order_columns_, ordered_partition_null_end_pos_, ordered_partition_null_start_pos_, and window_func_.

Referenced by compute().

753  {
754  IndexPair null_range{std::numeric_limits<int64_t>::max(),
755  std::numeric_limits<int64_t>::min()};
756  const auto& collation = window_func_->getCollation().front();
757  const auto partition_size = counts()[partition_idx];
758  if (partition_size > 0 && (order_col_ti.is_integer() || order_col_ti.is_decimal() ||
759  order_col_ti.is_time() || order_col_ti.is_boolean())) {
760  auto find_null_range_int = [&null_range,
761  &collation,
762  &original_col_idx_buf,
763  &ordered_col_idx_buf,
764  &partition_size](const auto order_col_buf,
765  const auto null_val) {
766  if (collation.nulls_first &&
767  order_col_buf[original_col_idx_buf[ordered_col_idx_buf[0]]] == null_val) {
768  int64_t null_range_max = 1;
769  while (null_range_max < partition_size &&
770  order_col_buf[original_col_idx_buf[ordered_col_idx_buf[null_range_max]]] ==
771  null_val) {
772  null_range_max++;
773  }
774  null_range.first = 0;
775  null_range.second = null_range_max - 1;
776  } else if (!collation.nulls_first &&
777  order_col_buf[original_col_idx_buf[ordered_col_idx_buf[partition_size -
778  1]]] ==
779  null_val) {
780  int64_t null_range_min = partition_size - 2;
781  while (null_range_min >= 0 &&
782  order_col_buf[original_col_idx_buf[ordered_col_idx_buf[null_range_min]]] ==
783  null_val) {
784  null_range_min--;
785  }
786  null_range.first = null_range_min + 1;
787  null_range.second = partition_size - 1;
788  }
789  };
790  switch (order_col_ti.get_size()) {
791  case 8: {
792  const auto order_col_buf =
793  reinterpret_cast<const int64_t*>(order_columns_.front());
794  find_null_range_int(order_col_buf, inline_int_null_value<int64_t>());
795  break;
796  }
797  case 4: {
798  const auto order_col_buf =
799  reinterpret_cast<const int32_t*>(order_columns_.front());
800  find_null_range_int(order_col_buf, inline_int_null_value<int32_t>());
801  break;
802  }
803  case 2: {
804  const auto order_col_buf =
805  reinterpret_cast<const int16_t*>(order_columns_.front());
806  find_null_range_int(order_col_buf, inline_int_null_value<int16_t>());
807  break;
808  }
809  case 1: {
810  const auto order_col_buf =
811  reinterpret_cast<const int8_t*>(order_columns_.front());
812  find_null_range_int(order_col_buf, inline_int_null_value<int8_t>());
813  break;
814  }
815  default: {
816  LOG(FATAL) << "Invalid type size: " << order_col_ti.get_size();
817  }
818  }
819  }
820  if (partition_size > 0 && order_col_ti.is_fp()) {
821  const auto null_bit_pattern =
822  null_val_bit_pattern(order_col_ti, order_col_ti.get_type() == kFLOAT);
823  switch (order_col_ti.get_type()) {
824  case kFLOAT: {
825  const auto order_col_buf = reinterpret_cast<const float*>(order_columns_.front());
826  auto check_null_val = [&null_bit_pattern,
827  &order_col_buf,
828  &original_col_idx_buf,
829  &ordered_col_idx_buf](size_t idx) {
830  return *reinterpret_cast<const int32_t*>(may_alias_ptr(
831  &order_col_buf[original_col_idx_buf[ordered_col_idx_buf[idx]]])) ==
832  null_bit_pattern;
833  };
834  if (collation.nulls_first && check_null_val(0)) {
835  int64_t null_range_max = 1;
836  while (null_range_max < partition_size && check_null_val(null_range_max)) {
837  null_range_max++;
838  }
839  null_range.first = 0;
840  null_range.second = null_range_max - 1;
841  } else if (!collation.nulls_first && check_null_val(partition_size - 1)) {
842  int64_t null_range_min = partition_size - 2;
843  while (null_range_min >= 0 && check_null_val(null_range_min)) {
844  null_range_min--;
845  }
846  null_range.first = null_range_min + 1;
847  null_range.second = partition_size - 1;
848  }
849  break;
850  }
851  case kDOUBLE: {
852  const auto order_col_buf =
853  reinterpret_cast<const double*>(order_columns_.front());
854  auto check_null_val = [&null_bit_pattern,
855  &order_col_buf,
856  &original_col_idx_buf,
857  &ordered_col_idx_buf](size_t idx) {
858  return *reinterpret_cast<const int64_t*>(may_alias_ptr(
859  &order_col_buf[original_col_idx_buf[ordered_col_idx_buf[idx]]])) ==
860  null_bit_pattern;
861  };
862  if (collation.nulls_first && check_null_val(0)) {
863  int64_t null_range_max = 1;
864  while (null_range_max < partition_size && check_null_val(null_range_max)) {
865  null_range_max++;
866  }
867  null_range.first = 0;
868  null_range.second = null_range_max - 1;
869  } else if (!collation.nulls_first && check_null_val(partition_size - 1)) {
870  int64_t null_range_min = partition_size - 2;
871  while (null_range_min >= 0 && check_null_val(null_range_min)) {
872  null_range_min--;
873  }
874  null_range.first = null_range_min + 1;
875  null_range.second = partition_size - 1;
876  }
877  break;
878  }
879  default: {
880  LOG(FATAL) << "Invalid float type";
881  }
882  }
883  }
884  ordered_partition_null_start_pos_[partition_idx] = null_range.first;
885  ordered_partition_null_end_pos_[partition_idx] = null_range.second + 1;
886 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:414
int64_t * ordered_partition_null_start_pos_
#define LOG(tag)
Definition: Logger.h:216
bool is_fp() const
Definition: sqltypes.h:604
const Analyzer::WindowFunction * window_func_
const int32_t * counts() const
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:404
int64_t null_val_bit_pattern(const SQLTypeInfo &ti, const bool float_argument_input)
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:2432
bool is_time() const
Definition: sqltypes.h:606
bool is_integer() const
Definition: sqltypes.h:602
bool is_boolean() const
Definition: sqltypes.h:607
std::pair< int64_t, int64_t > IndexPair
std::vector< const int8_t * > order_columns_
bool is_decimal() const
Definition: sqltypes.h:603
int64_t * ordered_partition_null_end_pos_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WindowFunctionContext::computePartitionBuffer ( const size_t  partition_idx,
int64_t *  output_for_partition_buff,
const Analyzer::WindowFunction window_func 
)
private

Definition at line 1151 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, counts(), createComparator(), 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(), GT, 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, LAG_IN_FRAME, LAST_VALUE, LEAD, LEAD_IN_FRAME, LT, MAX, MIN, anonymous_namespace{Utm.h}::n, NTILE, offsets(), partitionEnd(), payload(), PERCENT_RANK, RANK, ROW_NUMBER, SUM, toString(), and window_function_requires_peer_handling().

Referenced by compute().

1154  {
1155  const size_t partition_size{static_cast<size_t>(counts()[partition_idx])};
1156  if (partition_size == 0) {
1157  return;
1158  }
1159  const auto offset = offsets()[partition_idx];
1160  auto partition_comparator = createComparator(partition_idx);
1161  const auto col_tuple_comparator = [&partition_comparator](const int64_t lhs,
1162  const int64_t rhs) {
1163  for (const auto& comparator : partition_comparator) {
1164  const auto comparator_result = comparator(lhs, rhs);
1165  switch (comparator_result) {
1167  return true;
1169  return false;
1170  default:
1171  // WindowComparatorResult::EQ: continue to next comparator
1172  continue;
1173  }
1174  }
1175  // If here WindowFunctionContext::WindowComparatorResult::KEQ for all keys
1176  // return false as sort algo must enforce weak ordering
1177  return false;
1178  };
1179  switch (window_func->getKind()) {
1181  const auto row_numbers =
1182  index_to_row_number(output_for_partition_buff, partition_size);
1183  std::copy(row_numbers.begin(), row_numbers.end(), output_for_partition_buff);
1184  break;
1185  }
1187  const auto rank =
1188  index_to_rank(output_for_partition_buff, partition_size, col_tuple_comparator);
1189  std::copy(rank.begin(), rank.end(), output_for_partition_buff);
1190  break;
1191  }
1193  const auto dense_rank = index_to_dense_rank(
1194  output_for_partition_buff, partition_size, col_tuple_comparator);
1195  std::copy(dense_rank.begin(), dense_rank.end(), output_for_partition_buff);
1196  break;
1197  }
1199  const auto percent_rank = index_to_percent_rank(
1200  output_for_partition_buff, partition_size, col_tuple_comparator);
1201  std::copy(percent_rank.begin(),
1202  percent_rank.end(),
1203  reinterpret_cast<double*>(may_alias_ptr(output_for_partition_buff)));
1204  break;
1205  }
1207  const auto cume_dist = index_to_cume_dist(
1208  output_for_partition_buff, partition_size, col_tuple_comparator);
1209  std::copy(cume_dist.begin(),
1210  cume_dist.end(),
1211  reinterpret_cast<double*>(may_alias_ptr(output_for_partition_buff)));
1212  break;
1213  }
1215  const auto& args = window_func->getArgs();
1216  CHECK_EQ(args.size(), size_t(1));
1217  const auto n = get_int_constant_from_expr(args.front().get());
1218  const auto ntile = index_to_ntile(output_for_partition_buff, partition_size, n);
1219  std::copy(ntile.begin(), ntile.end(), output_for_partition_buff);
1220  break;
1221  }
1224  const auto lag_or_lead = get_lag_or_lead_argument(window_func);
1225  const auto partition_row_offsets = payload() + offset;
1227  lag_or_lead, partition_row_offsets, output_for_partition_buff, partition_size);
1228  break;
1229  }
1231  const auto partition_row_offsets = payload() + offset;
1233  partition_row_offsets, output_for_partition_buff, partition_size);
1234  break;
1235  }
1237  const auto partition_row_offsets = payload() + offset;
1239  partition_row_offsets, output_for_partition_buff, partition_size);
1240  break;
1241  }
1249  const auto partition_row_offsets = payload() + offset;
1250  if (window_function_requires_peer_handling(window_func)) {
1252  offset,
1253  output_for_partition_buff,
1254  partition_size,
1255  col_tuple_comparator);
1256  }
1258  output_for_partition_buff, partition_row_offsets, partition_size);
1259  break;
1260  }
1261  default: {
1262  throw std::runtime_error("Window function not supported yet: " +
1263  ::toString(window_func->getKind()));
1264  }
1265  }
1266 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2406
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)
const int32_t * counts() const
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
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)
const int32_t * offsets() const
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)
std::vector< Comparator > createComparator(size_t partition_idx)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:2408
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:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int32_t * WindowFunctionContext::counts ( ) const

Definition at line 1580 of file WindowContext.cpp.

References device_type_, dummy_count_, and partitions_.

Referenced by compute(), computeNullRangeOfSortedPartition(), computePartitionBuffer(), fillPartitionEnd(), fillPartitionStart(), partitionCount(), sortPartition(), and WindowFunctionContext().

1580  {
1581  if (partitions_) {
1582  return reinterpret_cast<const int32_t*>(
1583  partitions_->getJoinHashBuffer(device_type_, 0) + partitions_->countBufferOff());
1584  }
1585  return &dummy_count_;
1586 }
const int32_t dummy_count_
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the caller graph for this function:

std::vector< WindowFunctionContext::Comparator > WindowFunctionContext::createComparator ( size_t  partition_idx)

Definition at line 888 of file WindowContext.cpp.

References CHECK, CHECK_EQ, Analyzer::WindowFunction::getCollation(), Analyzer::WindowFunction::getOrderKeys(), makeComparator(), offsets(), order_columns_, payload(), and window_func_.

Referenced by computePartitionBuffer(), and sortPartition().

889  {
890  // create tuple comparator
891  std::vector<WindowFunctionContext::Comparator> partition_comparator;
892  const auto& order_keys = window_func_->getOrderKeys();
893  const auto& collation = window_func_->getCollation();
894  CHECK_EQ(order_keys.size(), collation.size());
895  for (size_t order_column_idx = 0; order_column_idx < order_columns_.size();
896  ++order_column_idx) {
897  auto order_column_buffer = order_columns_[order_column_idx];
898  const auto order_col =
899  dynamic_cast<const Analyzer::ColumnVar*>(order_keys[order_column_idx].get());
900  CHECK(order_col);
901  const auto& order_col_collation = collation[order_column_idx];
902  const auto asc_comparator = makeComparator(order_col,
903  order_column_buffer,
904  payload() + offsets()[partition_idx],
905  order_col_collation.nulls_first);
906  auto comparator = asc_comparator;
907  if (order_col_collation.is_desc) {
908  comparator = [asc_comparator](const int64_t lhs, const int64_t rhs) {
909  return asc_comparator(rhs, lhs);
910  };
911  }
912  partition_comparator.push_back(comparator);
913  }
914  return partition_comparator;
915 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const Analyzer::WindowFunction * window_func_
const int32_t * offsets() const
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:2414
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:2432
static Comparator makeComparator(const Analyzer::ColumnVar *col_var, const int8_t *partition_values, const int32_t *partition_indices, const bool nulls_first)
#define CHECK(condition)
Definition: Logger.h:222
std::vector< const int8_t * > order_columns_
const int32_t * payload() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t WindowFunctionContext::elementCount ( ) const

Definition at line 1010 of file WindowContext.cpp.

References elem_count_.

1010  {
1011  return elem_count_;
1012 }
void WindowFunctionContext::fillPartitionEnd ( )
private

Definition at line 1519 of file WindowContext.cpp.

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

Referenced by compute().

1519  {
1521  0,
1522  static_cast<int64_t>(elem_count_),
1523  false,
1525  1};
1526  auto bitmap_sz = partition_start_bitmap.bitmapPaddedSizeBytes();
1527  if (partitions_) {
1528  bitmap_sz += partitions_->isBitwiseEq() ? 1 : 0;
1529  }
1530  partition_end_ = static_cast<int8_t*>(checked_calloc(bitmap_sz, 1));
1531  auto partition_end_handle = reinterpret_cast<int64_t>(partition_end_);
1532  int64_t partition_count = partitionCount();
1534  // if we have `partition_start_offset_`, we can reuse it for this logic
1535  // but note that it has partition_count + 1 elements where the first element is zero
1536  // which means the first partition's start offset is zero
1537  // and rest of them can represent values required for this logic
1538  for (int64_t i = 0; i < partition_count - 1; ++i) {
1539  if (partition_start_offset_[i + 1] == 0) {
1540  continue;
1541  }
1543  &partition_end_handle, partition_start_offset_[i + 1] - 1, 0);
1544  }
1545  if (elem_count_) {
1546  agg_count_distinct_bitmap(&partition_end_handle, elem_count_ - 1, 0);
1547  }
1548  } else {
1549  std::vector<size_t> partition_offsets(partition_count);
1550  std::partial_sum(counts(), counts() + partition_count, partition_offsets.begin());
1551  for (int64_t i = 0; i < partition_count - 1; ++i) {
1552  if (partition_offsets[i] == 0) {
1553  continue;
1554  }
1555  agg_count_distinct_bitmap(&partition_end_handle, partition_offsets[i] - 1, 0);
1556  }
1557  if (elem_count_) {
1558  agg_count_distinct_bitmap(&partition_end_handle, elem_count_ - 1, 0);
1559  }
1560  }
1561 }
RUNTIME_EXPORT ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)
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
std::shared_ptr< HashJoin > partitions_
int64_t * partition_start_offset_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void WindowFunctionContext::fillPartitionStart ( )
private

Definition at line 1486 of file WindowContext.cpp.

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

Referenced by compute().

1486  {
1488  0,
1489  static_cast<int64_t>(elem_count_),
1490  false,
1492  1};
1493  auto bitmap_sz = partition_start_bitmap.bitmapPaddedSizeBytes();
1494  if (partitions_) {
1495  bitmap_sz += partitions_->isBitwiseEq() ? 1 : 0;
1496  }
1497  partition_start_ = static_cast<int8_t*>(checked_calloc(bitmap_sz, 1));
1498  int64_t partition_count = partitionCount();
1499  auto partition_start_handle = reinterpret_cast<int64_t>(partition_start_);
1500  agg_count_distinct_bitmap(&partition_start_handle, 0, 0);
1502  // if we have `partition_start_offset_`, we can reuse it for this logic
1503  // but note that it has partition_count + 1 elements where the first element is zero
1504  // which means the first partition's start offset is zero
1505  // and rest of them can represent values required for this logic
1506  for (int64_t i = 0; i < partition_count - 1; ++i) {
1508  &partition_start_handle, partition_start_offset_[i + 1], 0);
1509  }
1510  } else {
1511  std::vector<size_t> partition_offsets(partition_count);
1512  std::partial_sum(counts(), counts() + partition_count, partition_offsets.begin());
1513  for (int64_t i = 0; i < partition_count - 1; ++i) {
1514  agg_count_distinct_bitmap(&partition_start_handle, partition_offsets[i], 0);
1515  }
1516  }
1517 }
RUNTIME_EXPORT ALWAYS_INLINE void agg_count_distinct_bitmap(int64_t *agg, const int64_t val, const int64_t min_val)
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
std::shared_ptr< HashJoin > partitions_
int64_t * partition_start_offset_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t * WindowFunctionContext::getAggregateTreeDepth ( ) const

Definition at line 1470 of file WindowContext.cpp.

References aggregate_trees_depth_.

1470  {
1471  return aggregate_trees_depth_;
1472 }
size_t * aggregate_trees_depth_
size_t WindowFunctionContext::getAggregateTreeFanout ( ) const

Definition at line 1474 of file WindowContext.cpp.

References aggregate_trees_fan_out_.

1474  {
1475  return aggregate_trees_fan_out_;
1476 }
double ** WindowFunctionContext::getAggregationTreesForDoubleTypeWindowExpr ( ) const

Definition at line 1454 of file WindowContext.cpp.

References AggregateTreeForWindowFraming::aggregate_tree_for_double_type_, and aggregate_trees_.

1454  {
1455  return const_cast<double**>(aggregate_trees_.aggregate_tree_for_double_type_.data());
1456 }
std::vector< double * > aggregate_tree_for_double_type_
Definition: WindowContext.h:64
AggregateTreeForWindowFraming aggregate_trees_
int64_t ** WindowFunctionContext::getAggregationTreesForIntegerTypeWindowExpr ( ) const

Definition at line 1450 of file WindowContext.cpp.

References AggregateTreeForWindowFraming::aggregate_tree_for_integer_type_, and aggregate_trees_.

1450  {
1451  return const_cast<int64_t**>(aggregate_trees_.aggregate_tree_for_integer_type_.data());
1452 }
AggregateTreeForWindowFraming aggregate_trees_
std::vector< int64_t * > aggregate_tree_for_integer_type_
Definition: WindowContext.h:63
const std::vector< const int8_t * > & WindowFunctionContext::getColumnBufferForWindowFunctionExpressions ( ) const

Definition at line 173 of file WindowContext.cpp.

References window_func_expr_columns_.

173  {
175 }
std::vector< const int8_t * > window_func_expr_columns_
SumAndCountPair< double > ** WindowFunctionContext::getDerivedAggregationTreesForDoubleTypeWindowExpr ( ) const

Definition at line 1465 of file WindowContext.cpp.

References aggregate_trees_, and AggregateTreeForWindowFraming::derived_aggregate_tree_for_double_type_.

1465  {
1466  return const_cast<SumAndCountPair<double>**>(
1468 }
std::vector< SumAndCountPair< double > * > derived_aggregate_tree_for_double_type_
Definition: WindowContext.h:66
AggregateTreeForWindowFraming aggregate_trees_
SumAndCountPair< int64_t > ** WindowFunctionContext::getDerivedAggregationTreesForIntegerTypeWindowExpr ( ) const

Definition at line 1459 of file WindowContext.cpp.

References aggregate_trees_, and AggregateTreeForWindowFraming::derived_aggregate_tree_for_integer_type_.

1459  {
1460  return const_cast<SumAndCountPair<int64_t>**>(
1462 }
AggregateTreeForWindowFraming aggregate_trees_
std::vector< SumAndCountPair< int64_t > * > derived_aggregate_tree_for_integer_type_
Definition: WindowContext.h:65
int64_t * WindowFunctionContext::getNullValueEndPos ( ) const

Definition at line 1482 of file WindowContext.cpp.

References ordered_partition_null_end_pos_.

1482  {
1484 }
int64_t * ordered_partition_null_end_pos_
int64_t * WindowFunctionContext::getNullValueStartPos ( ) const

Definition at line 1478 of file WindowContext.cpp.

References ordered_partition_null_start_pos_.

1478  {
1480 }
int64_t * ordered_partition_null_start_pos_
const std::vector< const int8_t * > & WindowFunctionContext::getOrderKeyColumnBuffers ( ) const

Definition at line 177 of file WindowContext.cpp.

References order_columns_.

Referenced by Executor::codegenWindowFrameBound().

178  {
179  return order_columns_;
180 }
std::vector< const int8_t * > order_columns_

+ Here is the caller graph for this function:

const std::vector< SQLTypeInfo > & WindowFunctionContext::getOrderKeyColumnBufferTypes ( ) const

Definition at line 182 of file WindowContext.cpp.

References order_columns_ti_.

Referenced by CodeGenerator::codegenFixedLengthColVar(), and Executor::codegenWindowFrameBound().

183  {
184  return order_columns_ti_;
185 }
std::vector< SQLTypeInfo > order_columns_ti_

+ Here is the caller graph for this function:

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

Definition at line 964 of file WindowContext.cpp.

References window_func_.

Referenced by CodeGenerator::codegenFixedLengthColVar(), Executor::codegenWindowFrameBound(), and Executor::codegenWindowFunction().

964  {
965  return window_func_;
966 }
const Analyzer::WindowFunction * window_func_

+ Here is the caller graph for this function:

WindowFunctionContext::Comparator 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 1086 of file WindowContext.cpp.

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

Referenced by createComparator().

1090  {
1091  const auto& ti = col_var->get_type_info();
1092  if (ti.is_integer() || ti.is_decimal() || ti.is_time() || ti.is_boolean()) {
1093  switch (ti.get_size()) {
1094  case 8: {
1095  return [order_column_buffer, nulls_first, partition_indices, &ti](
1096  const int64_t lhs, const int64_t rhs) {
1097  return integer_comparator<int64_t>(
1098  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1099  };
1100  }
1101  case 4: {
1102  return [order_column_buffer, nulls_first, partition_indices, &ti](
1103  const int64_t lhs, const int64_t rhs) {
1104  return integer_comparator<int32_t>(
1105  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1106  };
1107  }
1108  case 2: {
1109  return [order_column_buffer, nulls_first, partition_indices, &ti](
1110  const int64_t lhs, const int64_t rhs) {
1111  return integer_comparator<int16_t>(
1112  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1113  };
1114  }
1115  case 1: {
1116  return [order_column_buffer, nulls_first, partition_indices, &ti](
1117  const int64_t lhs, const int64_t rhs) {
1118  return integer_comparator<int8_t>(
1119  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1120  };
1121  }
1122  default: {
1123  LOG(FATAL) << "Invalid type size: " << ti.get_size();
1124  }
1125  }
1126  }
1127  if (ti.is_fp()) {
1128  switch (ti.get_type()) {
1129  case kFLOAT: {
1130  return [order_column_buffer, nulls_first, partition_indices, &ti](
1131  const int64_t lhs, const int64_t rhs) {
1132  return fp_comparator<float, int32_t>(
1133  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1134  };
1135  }
1136  case kDOUBLE: {
1137  return [order_column_buffer, nulls_first, partition_indices, &ti](
1138  const int64_t lhs, const int64_t rhs) {
1139  return fp_comparator<double, int64_t>(
1140  order_column_buffer, ti, partition_indices, lhs, rhs, nulls_first);
1141  };
1142  }
1143  default: {
1144  LOG(FATAL) << "Invalid float type";
1145  }
1146  }
1147  }
1148  throw std::runtime_error("Type not supported yet");
1149 }
#define LOG(tag)
Definition: Logger.h:216
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const bool WindowFunctionContext::needsToBuildAggregateTree ( ) const

Definition at line 1597 of file WindowContext.cpp.

References elem_count_, Analyzer::WindowFunction::hasAggregateTreeRequiredWindowFunc(), Analyzer::WindowFunction::hasFraming(), and window_func_.

Referenced by compute().

1597  {
1598  return window_func_->hasFraming() &&
1600 }
bool hasAggregateTreeRequiredWindowFunc() const
Definition: Analyzer.h:2454
const Analyzer::WindowFunction * window_func_
bool hasFraming() const
Definition: Analyzer.h:2442

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const int32_t * WindowFunctionContext::offsets ( ) const

Definition at line 1572 of file WindowContext.cpp.

References device_type_, dummy_offset_, and partitions_.

Referenced by buildAggregationTreeForPartition(), compute(), computePartitionBuffer(), createComparator(), and partitionCount().

1572  {
1573  if (partitions_) {
1574  return reinterpret_cast<const int32_t*>(
1575  partitions_->getJoinHashBuffer(device_type_, 0) + partitions_->offsetBufferOff());
1576  }
1577  return &dummy_offset_;
1578 }
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 968 of file WindowContext.cpp.

References output_.

Referenced by CodeGenerator::codegenWindowPosition().

968  {
969  return output_;
970 }

+ Here is the caller graph for this function:

size_t WindowFunctionContext::partitionCount ( ) const

Definition at line 1588 of file WindowContext.cpp.

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

Referenced by Executor::codegenCurrentPartitionIndex(), compute(), fillPartitionEnd(), fillPartitionStart(), and WindowFunctionContext().

1588  {
1589  if (partitions_) {
1590  const auto partition_count = counts() - offsets();
1591  CHECK_GE(partition_count, 0);
1592  return partition_count;
1593  }
1594  return 1; // non-partitioned window function
1595 }
#define CHECK_GE(x, y)
Definition: Logger.h:235
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 1006 of file WindowContext.cpp.

References partition_end_.

Referenced by computePartitionBuffer().

1006  {
1007  return partition_end_;
1008 }

+ Here is the caller graph for this function:

const int64_t * WindowFunctionContext::partitionNumCountBuf ( ) const

Definition at line 992 of file WindowContext.cpp.

References CHECK, and partition_start_offset_.

Referenced by Executor::codegenCurrentPartitionIndex().

992  {
994  return partition_start_offset_ + 1;
995 }
int64_t * partition_start_offset_
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

const int8_t * WindowFunctionContext::partitionStart ( ) const

Definition at line 1002 of file WindowContext.cpp.

References partition_start_.

1002  {
1003  return partition_start_;
1004 }
const int64_t * WindowFunctionContext::partitionStartOffset ( ) const

Definition at line 987 of file WindowContext.cpp.

References CHECK, and partition_start_offset_.

987  {
990 }
int64_t * partition_start_offset_
#define CHECK(condition)
Definition: Logger.h:222
const int32_t * WindowFunctionContext::payload ( ) const

Definition at line 1563 of file WindowContext.cpp.

References device_type_, dummy_payload_, and partitions_.

Referenced by compute(), computePartitionBuffer(), and createComparator().

1563  {
1564  if (partitions_) {
1565  return reinterpret_cast<const int32_t*>(
1566  partitions_->getJoinHashBuffer(device_type_, 0) +
1567  partitions_->payloadBufferOff());
1568  }
1569  return dummy_payload_; // non-partitioned window function
1570 }
std::shared_ptr< HashJoin > partitions_
const ExecutorDeviceType device_type_

+ Here is the caller graph for this function:

void WindowFunctionContext::setSortedPartitionCacheKey ( QueryPlanHash  cache_key)

Definition at line 187 of file WindowContext.cpp.

References sorted_partition_cache_key_.

187  {
188  sorted_partition_cache_key_ = cache_key;
189 }
QueryPlanHash sorted_partition_cache_key_
const int64_t * WindowFunctionContext::sortedPartition ( ) const

Definition at line 972 of file WindowContext.cpp.

References CHECK, and sorted_partition_buf_.

972  {
974  return sorted_partition_buf_->data();
975 }
std::shared_ptr< std::vector< int64_t > > sorted_partition_buf_
#define CHECK(condition)
Definition: Logger.h:222
void WindowFunctionContext::sortPartition ( const size_t  partition_idx,
int64_t *  output_for_partition_buff,
bool  should_parallelize 
)
private

Definition at line 917 of file WindowContext.cpp.

References counts(), createComparator(), GT, gpu_enabled::iota(), LT, and gpu_enabled::sort().

Referenced by compute().

919  {
920  const size_t partition_size{static_cast<size_t>(counts()[partition_idx])};
921  if (partition_size == 0) {
922  return;
923  }
924  std::iota(
925  output_for_partition_buff, output_for_partition_buff + partition_size, int64_t(0));
926  auto partition_comparator = createComparator(partition_idx);
927  if (!partition_comparator.empty()) {
928  const auto col_tuple_comparator = [&partition_comparator](const int64_t lhs,
929  const int64_t rhs) {
930  for (const auto& comparator : partition_comparator) {
931  const auto comparator_result = comparator(lhs, rhs);
932  switch (comparator_result) {
934  return true;
936  return false;
937  default:
938  // WindowComparatorResult::EQ: continue to next comparator
939  continue;
940  }
941  }
942  // If here WindowFunctionContext::WindowComparatorResult::KEQ for all keys
943  // return false as sort algo must enforce weak ordering
944  return false;
945  };
946  if (should_parallelize) {
947 #ifdef HAVE_TBB
948  tbb::parallel_sort(output_for_partition_buff,
949  output_for_partition_buff + partition_size,
950  col_tuple_comparator);
951 #else
952  thrust::sort(output_for_partition_buff,
953  output_for_partition_buff + partition_size,
954  col_tuple_comparator);
955 #endif
956  } else {
957  std::sort(output_for_partition_buff,
958  output_for_partition_buff + partition_size,
959  col_tuple_comparator);
960  }
961  }
962 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
const int32_t * counts() const
std::vector< Comparator > createComparator(size_t partition_idx)
DEVICE void iota(ARGS &&...args)
Definition: gpu_enabled.h:69

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

AggregateState WindowFunctionContext::aggregate_state_
private
size_t* WindowFunctionContext::aggregate_trees_depth_
private
size_t WindowFunctionContext::aggregate_trees_fan_out_
private

Definition at line 248 of file WindowContext.h.

Referenced by buildAggregationTreeForPartition(), and getAggregateTreeFanout().

const ExecutorDeviceType WindowFunctionContext::device_type_
private

Definition at line 261 of file WindowContext.h.

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

const int32_t WindowFunctionContext::dummy_count_
private

Definition at line 265 of file WindowContext.h.

Referenced by counts().

const int32_t WindowFunctionContext::dummy_offset_
private

Definition at line 266 of file WindowContext.h.

Referenced by offsets().

int32_t* WindowFunctionContext::dummy_payload_
private

Definition at line 271 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
std::vector<std::vector<std::shared_ptr<Chunk_NS::Chunk> > > WindowFunctionContext::order_columns_owner_
private

Definition at line 229 of file WindowContext.h.

Referenced by addOrderColumn().

std::vector<SQLTypeInfo> WindowFunctionContext::order_columns_ti_
private

Definition at line 232 of file WindowContext.h.

Referenced by addOrderColumn(), and getOrderKeyColumnBufferTypes().

int64_t* WindowFunctionContext::ordered_partition_null_end_pos_
private
int64_t* WindowFunctionContext::ordered_partition_null_start_pos_
private
int8_t* WindowFunctionContext::output_
private

Definition at line 238 of file WindowContext.h.

Referenced by compute(), and output().

QueryPlanHash WindowFunctionContext::partition_cache_key_
private

Definition at line 226 of file WindowContext.h.

int8_t* WindowFunctionContext::partition_end_
private

Definition at line 258 of file WindowContext.h.

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

int8_t* WindowFunctionContext::partition_start_
private

Definition at line 255 of file WindowContext.h.

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

int64_t* WindowFunctionContext::partition_start_offset_
private
std::shared_ptr<HashJoin> WindowFunctionContext::partitions_
private
std::shared_ptr<RowSetMemoryOwner> WindowFunctionContext::row_set_mem_owner_
private

Definition at line 262 of file WindowContext.h.

Referenced by compute().

std::vector<std::shared_ptr<void> > WindowFunctionContext::segment_trees_owned_
private

Definition at line 246 of file WindowContext.h.

Referenced by buildAggregationTreeForPartition().

std::shared_ptr<std::vector<int64_t> > WindowFunctionContext::sorted_partition_buf_
private

Definition at line 239 of file WindowContext.h.

Referenced by compute(), and sortedPartition().

QueryPlanHash WindowFunctionContext::sorted_partition_cache_key_
private

Definition at line 227 of file WindowContext.h.

Referenced by compute(), and setSortedPartitionCacheKey().

std::vector<const int8_t*> WindowFunctionContext::window_func_expr_columns_
private
std::vector<std::vector<std::shared_ptr<Chunk_NS::Chunk> > > WindowFunctionContext::window_func_expr_columns_owner_
private

Definition at line 242 of file WindowContext.h.

Referenced by addColumnBufferForWindowFunctionExpression().


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