OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::WindowFunction Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::WindowFunction:
+ Collaboration diagram for Analyzer::WindowFunction:

Public Types

enum  FrameBoundType { FrameBoundType::NONE, FrameBoundType::ROW, FrameBoundType::RANGE }
 

Public Member Functions

 WindowFunction (const SQLTypeInfo &ti, const SqlWindowFunctionKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::vector< std::shared_ptr< Analyzer::Expr >> &partition_keys, const std::vector< std::shared_ptr< Analyzer::Expr >> &order_keys, const FrameBoundType frame_bound_type, const std::shared_ptr< Expr > frame_start_bound, const std::shared_ptr< Expr > frame_end_bound, const std::vector< OrderEntry > &collation)
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
SqlWindowFunctionKind getKind () const
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > & 
getArgs () const
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > & 
getPartitionKeys () const
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > & 
getOrderKeys () const
 
const Analyzer::WindowFramegetFrameStartBound () const
 
const Analyzer::WindowFramegetFrameEndBound () const
 
const std::vector< OrderEntry > & getCollation () const
 
Analyzer::WindowFunction::FrameBoundType getFrameBoundType () const
 
bool hasRowModeFraming () const
 
bool hasRangeModeFraming () const
 
bool hasFraming () const
 
bool hasAggregateTreeRequiredWindowFunc () const
 
bool isFrameNavigateWindowFunction () const
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual std::shared_ptr
< Analyzer::Expr
add_cast (const SQLTypeInfo &new_type_info)
 
virtual void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
 
virtual std::shared_ptr
< Analyzer::Expr
normalize_simple_predicate (int &rte_idx) const
 
virtual void group_predicates (std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const
 
virtual void collect_rte_idx (std::set< int > &rte_idx_set) const
 
virtual void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
 
virtual size_t get_num_column_vars (const bool include_agg) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual std::shared_ptr
< Analyzer::Expr
rewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr * > &expr_list) const
 
virtual void find_expr (std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Static Public Member Functions

static bool isFramingAvailableWindowFunc (SqlWindowFunctionKind kind)
 

Static Public Attributes

static constexpr std::array
< SqlWindowFunctionKind, 11 > 
FRAMING_ALLOWED_WINDOW_FUNCS
 
static constexpr std::array
< SqlWindowFunctionKind, 8 > 
AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
 
static constexpr std::array
< SqlWindowFunctionKind, 3 > 
REQUIRE_HASH_TABLE_FOR_FRAMING
 

Private Attributes

const SqlWindowFunctionKind kind_
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > 
args_
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > 
partition_keys_
 
const std::vector
< std::shared_ptr
< Analyzer::Expr > > 
order_keys_
 
const FrameBoundType frame_bound_type_ {FrameBoundType::NONE}
 
const std::shared_ptr
< Analyzer::Expr
frame_start_bound_
 
const std::shared_ptr
< Analyzer::Expr
frame_end_bound_
 
const std::vector< OrderEntrycollation_
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 2522 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
NONE 
ROW 
RANGE 

Definition at line 2524 of file Analyzer.h.

2524 { NONE, ROW, RANGE };

Constructor & Destructor Documentation

Analyzer::WindowFunction::WindowFunction ( const SQLTypeInfo ti,
const SqlWindowFunctionKind  kind,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  args,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  partition_keys,
const std::vector< std::shared_ptr< Analyzer::Expr >> &  order_keys,
const FrameBoundType  frame_bound_type,
const std::shared_ptr< Expr frame_start_bound,
const std::shared_ptr< Expr frame_end_bound,
const std::vector< OrderEntry > &  collation 
)
inline

Definition at line 2552 of file Analyzer.h.

2561  : Expr(ti)
2562  , kind_(kind)
2563  , args_(args)
2564  , partition_keys_(partition_keys)
2565  , order_keys_(order_keys)
2566  , frame_bound_type_(frame_bound_type)
2567  , frame_start_bound_(frame_start_bound)
2568  , frame_end_bound_(frame_end_bound)
2569  , collation_(collation){};
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2644
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2641
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2640
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2639
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2643
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2645
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Analyzer::WindowFunction::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 222 of file Analyzer.cpp.

References args_, collation_, frame_bound_type_, frame_end_bound_, frame_start_bound_, kind_, order_keys_, partition_keys_, and Analyzer::Expr::type_info.

222  {
223  return makeExpr<WindowFunction>(type_info,
224  kind_,
225  args_,
227  order_keys_,
229  frame_start_bound_->deep_copy(),
230  frame_end_bound_->deep_copy(),
231  collation_);
232 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2644
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2641
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2640
SQLTypeInfo type_info
Definition: Analyzer.h:180
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2639
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2643
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2645
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638
const std::vector<OrderEntry>& Analyzer::WindowFunction::getCollation ( ) const
inline

Definition at line 2602 of file Analyzer.h.

References collation_.

Referenced by WindowFunctionContext::computeAggregateTreeCacheKey(), WindowFunctionContext::createComparator(), RelAlgExecutor::createWindowFunctionContext(), ScalarExprToSql::visitWindowFunction(), and DeepCopyVisitor::visitWindowFunction().

2602 { return collation_; }
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2645

+ Here is the caller graph for this function:

Analyzer::WindowFunction::FrameBoundType Analyzer::WindowFunction::getFrameBoundType ( ) const
inline

Definition at line 2604 of file Analyzer.h.

References frame_bound_type_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2604  {
2605  return frame_bound_type_;
2606  }
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642

+ Here is the caller graph for this function:

const Analyzer::WindowFrame* Analyzer::WindowFunction::getFrameEndBound ( ) const
inline

Definition at line 2595 of file Analyzer.h.

References CHECK, and frame_end_bound_.

Referenced by Executor::codegenFrameBoundRange(), and DeepCopyVisitor::visitWindowFunction().

2595  {
2596  std::shared_ptr<WindowFrame> frame_end_bound =
2597  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2598  CHECK(frame_end_bound);
2599  return frame_end_bound.get();
2600  }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2644
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

const Analyzer::WindowFrame* Analyzer::WindowFunction::getFrameStartBound ( ) const
inline

Definition at line 2588 of file Analyzer.h.

References CHECK, and frame_start_bound_.

Referenced by Executor::codegenFrameBoundRange(), and DeepCopyVisitor::visitWindowFunction().

2588  {
2589  std::shared_ptr<WindowFrame> frame_start_bound =
2590  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2591  CHECK(frame_start_bound);
2592  return frame_start_bound.get();
2593  }
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2643
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

const std::vector<std::shared_ptr<Analyzer::Expr> >& Analyzer::WindowFunction::getOrderKeys ( ) const
inline
const std::vector<std::shared_ptr<Analyzer::Expr> >& Analyzer::WindowFunction::getPartitionKeys ( ) const
inline

Definition at line 2580 of file Analyzer.h.

References partition_keys_.

Referenced by WindowFunctionContext::computeAggregateTreeCacheKey(), RelAlgExecutor::computeWindow(), ScalarExprToSql::visitWindowFunction(), DeepCopyVisitor::visitWindowFunction(), and ScalarExprVisitor< std::set< shared::TableKey > >::visitWindowFunction().

2580  {
2581  return partition_keys_;
2582  }
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2640

+ Here is the caller graph for this function:

bool Analyzer::WindowFunction::hasAggregateTreeRequiredWindowFunc ( ) const
inline

Definition at line 2624 of file Analyzer.h.

References AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING, anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of(), and kind_.

Referenced by WindowFunctionContext::needsToBuildAggregateTree().

2624  {
2625  return std::any_of(
2628  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2629  }
static constexpr std::array< SqlWindowFunctionKind, 8 > AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
Definition: Analyzer.h:2538
SqlWindowFunctionKind
Definition: sqldefs.h:120
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Analyzer::WindowFunction::hasFraming ( ) const
inline

Definition at line 2612 of file Analyzer.h.

References frame_bound_type_, isFramingAvailableWindowFunc(), kind_, and NONE.

Referenced by WindowFunctionContext::compute(), WindowFunctionContext::needsToBuildAggregateTree(), toString(), and WindowFunctionContext::WindowFunctionContext().

2612  {
2615  }
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2617
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Analyzer::WindowFunction::hasRangeModeFraming ( ) const
inline

Definition at line 2610 of file Analyzer.h.

References frame_bound_type_, and RANGE.

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

+ Here is the caller graph for this function:

bool Analyzer::WindowFunction::hasRowModeFraming ( ) const
inline

Definition at line 2608 of file Analyzer.h.

References frame_bound_type_, and ROW.

bool Analyzer::WindowFunction::isFrameNavigateWindowFunction ( ) const
inline

Definition at line 2630 of file Analyzer.h.

References anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of(), kind_, and REQUIRE_HASH_TABLE_FOR_FRAMING.

Referenced by Executor::codegenCurrentPartitionIndex(), Executor::codegenLoadCurrentValueFromColBuf(), and RelAlgExecutor::createWindowFunctionContext().

2630  {
2631  return std::any_of(
2634  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2635  }
static constexpr std::array< SqlWindowFunctionKind, 3 > REQUIRE_HASH_TABLE_FOR_FRAMING
Definition: Analyzer.h:2547
SqlWindowFunctionKind
Definition: sqldefs.h:120
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool Analyzer::WindowFunction::isFramingAvailableWindowFunc ( SqlWindowFunctionKind  kind)
inlinestatic

Definition at line 2617 of file Analyzer.h.

References anonymous_namespace{QueryMemoryDescriptor.cpp}::any_of(), and FRAMING_ALLOWED_WINDOW_FUNCS.

Referenced by hasFraming(), and RelAlgTranslator::translateWindowFunction().

2617  {
2618  return std::any_of(
2621  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2622  }
SqlWindowFunctionKind
Definition: sqldefs.h:120
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)
static constexpr std::array< SqlWindowFunctionKind, 11 > FRAMING_ALLOWED_WINDOW_FUNCS
Definition: Analyzer.h:2525

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Analyzer::WindowFunction::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2548 of file Analyzer.cpp.

References args_, expr_list_match(), frame_bound_type_, frame_end_bound_, frame_start_bound_, kind_, order_keys_, and partition_keys_.

2548  {
2549  const auto rhs_window = dynamic_cast<const WindowFunction*>(&rhs);
2550  if (!rhs_window) {
2551  return false;
2552  }
2553  if (kind_ != rhs_window->kind_ || args_.size() != rhs_window->args_.size() ||
2554  partition_keys_.size() != rhs_window->partition_keys_.size() ||
2555  order_keys_.size() != rhs_window->order_keys_.size() ||
2556  frame_bound_type_ != rhs_window->frame_bound_type_ ||
2557  frame_start_bound_.get() != rhs_window->frame_start_bound_.get() ||
2558  frame_end_bound_.get() != rhs_window->frame_end_bound_.get()) {
2559  return false;
2560  }
2561  return expr_list_match(args_, rhs_window->args_) &&
2562  expr_list_match(partition_keys_, rhs_window->partition_keys_) &&
2563  expr_list_match(order_keys_, rhs_window->order_keys_);
2564 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2644
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2641
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2640
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2639
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2643
bool expr_list_match(const std::vector< std::shared_ptr< Analyzer::Expr >> &lhs, const std::vector< std::shared_ptr< Analyzer::Expr >> &rhs)
Definition: Analyzer.cpp:4326
WindowFunction(const SQLTypeInfo &ti, const SqlWindowFunctionKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::vector< std::shared_ptr< Analyzer::Expr >> &partition_keys, const std::vector< std::shared_ptr< Analyzer::Expr >> &order_keys, const FrameBoundType frame_bound_type, const std::shared_ptr< Expr > frame_start_bound, const std::shared_ptr< Expr > frame_end_bound, const std::vector< OrderEntry > &collation)
Definition: Analyzer.h:2552
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638

+ Here is the call graph for this function:

std::string Analyzer::WindowFunction::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2985 of file Analyzer.cpp.

References args_, frame_bound_type_, frame_end_bound_, frame_start_bound_, hasFraming(), kind_, order_keys_, RANGE, run_benchmark_import::result, ROW, and UNREACHABLE.

2985  {
2986  std::string result = "WindowFunction(" + ::toString(kind_);
2987  for (const auto& arg : args_) {
2988  result += " " + arg->toString();
2989  }
2990  if (hasFraming()) {
2991  result += " Frame{";
2992  switch (frame_bound_type_) {
2993  case FrameBoundType::ROW: {
2994  result += "ROW";
2995  break;
2996  }
2997  case FrameBoundType::RANGE: {
2998  result += "RANGE";
2999  break;
3000  }
3001  default: {
3002  UNREACHABLE()
3003  << "Two bound types are supported for window framing: ROW and RANGE.";
3004  break;
3005  }
3006  }
3007  result += " BETWEEN : " + frame_start_bound_->toString();
3008  result += " AND : " + frame_end_bound_->toString();
3009  } else {
3010  if (!order_keys_.empty()) {
3011  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
3012  } else {
3013  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
3014  }
3015  }
3016  result += "} ";
3017  return result + ") ";
3018 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2644
#define UNREACHABLE()
Definition: Logger.h:337
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2641
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2639
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2642
std::string toString() const override
Definition: Analyzer.cpp:2985
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2643
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2638
bool hasFraming() const
Definition: Analyzer.h:2612

+ Here is the call graph for this function:

Member Data Documentation

const std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::WindowFunction::args_
private

Definition at line 2639 of file Analyzer.h.

Referenced by deep_copy(), getArgs(), operator==(), and toString().

const std::vector<OrderEntry> Analyzer::WindowFunction::collation_
private

Definition at line 2645 of file Analyzer.h.

Referenced by deep_copy(), and getCollation().

const FrameBoundType Analyzer::WindowFunction::frame_bound_type_ {FrameBoundType::NONE}
private
const std::shared_ptr<Analyzer::Expr> Analyzer::WindowFunction::frame_end_bound_
private

Definition at line 2644 of file Analyzer.h.

Referenced by deep_copy(), getFrameEndBound(), operator==(), and toString().

const std::shared_ptr<Analyzer::Expr> Analyzer::WindowFunction::frame_start_bound_
private

Definition at line 2643 of file Analyzer.h.

Referenced by deep_copy(), getFrameStartBound(), operator==(), and toString().

const SqlWindowFunctionKind Analyzer::WindowFunction::kind_
private
const std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::WindowFunction::order_keys_
private

Definition at line 2641 of file Analyzer.h.

Referenced by deep_copy(), getOrderKeys(), operator==(), and toString().

const std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::WindowFunction::partition_keys_
private

Definition at line 2640 of file Analyzer.h.

Referenced by deep_copy(), getPartitionKeys(), and operator==().

constexpr std::array<SqlWindowFunctionKind, 3> Analyzer::WindowFunction::REQUIRE_HASH_TABLE_FOR_FRAMING
static

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