OmniSciDB  72c90bc290
 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
 
bool isMissingValueFillingFunction () 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, 14 > 
FRAMING_ALLOWED_WINDOW_FUNCS
 
static constexpr std::array
< SqlWindowFunctionKind, 9 > 
AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
 
static constexpr std::array
< SqlWindowFunctionKind, 2 > 
FILLING_FUNCS_USING_WINDOW
 
static constexpr std::array
< SqlWindowFunctionKind, 7 > 
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 2729 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
NONE 
ROW 
RANGE 

Definition at line 2731 of file Analyzer.h.

2731 { 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 2770 of file Analyzer.h.

2779  : Expr(ti)
2780  , kind_(kind)
2781  , args_(args)
2782  , partition_keys_(partition_keys)
2783  , order_keys_(order_keys)
2784  , frame_bound_type_(frame_bound_type)
2785  , frame_start_bound_(frame_start_bound)
2786  , frame_end_bound_(frame_end_bound)
2787  , collation_(collation){};
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2869
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2866
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2865
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2864
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2868
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2870
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863

Member Function Documentation

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

Implements Analyzer::Expr.

Definition at line 239 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.

239  {
240  return makeExpr<WindowFunction>(type_info,
241  kind_,
242  args_,
244  order_keys_,
246  frame_start_bound_->deep_copy(),
247  frame_end_bound_->deep_copy(),
248  collation_);
249 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2869
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2866
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2865
SQLTypeInfo type_info
Definition: Analyzer.h:180
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2864
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2868
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2870
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863
const std::vector<OrderEntry>& Analyzer::WindowFunction::getCollation ( ) const
inline

Definition at line 2820 of file Analyzer.h.

References collation_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 2822 of file Analyzer.h.

References frame_bound_type_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2822  {
2823  return frame_bound_type_;
2824  }
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867

+ Here is the caller graph for this function:

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

Definition at line 2813 of file Analyzer.h.

References CHECK, and frame_end_bound_.

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

2813  {
2814  std::shared_ptr<WindowFrame> frame_end_bound =
2815  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2816  CHECK(frame_end_bound);
2817  return frame_end_bound.get();
2818  }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2869
#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 2806 of file Analyzer.h.

References CHECK, and frame_start_bound_.

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

2806  {
2807  std::shared_ptr<WindowFrame> frame_start_bound =
2808  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2809  CHECK(frame_start_bound);
2810  return frame_start_bound.get();
2811  }
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2868
#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 2798 of file Analyzer.h.

References partition_keys_.

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

2798  {
2799  return partition_keys_;
2800  }
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2865

+ Here is the caller graph for this function:

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

Definition at line 2842 of file Analyzer.h.

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

Referenced by WindowFunctionContext::needsToBuildAggregateTree().

2842  {
2843  return std::any_of(
2846  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2847  }
static constexpr std::array< SqlWindowFunctionKind, 9 > AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
Definition: Analyzer.h:2748
SqlWindowFunctionKind
Definition: sqldefs.h:122
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863
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 2830 of file Analyzer.h.

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

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

2830  {
2833  }
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2835
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863

+ 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 2828 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 2826 of file Analyzer.h.

References frame_bound_type_, and ROW.

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

Definition at line 2848 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().

2848  {
2849  return std::any_of(
2852  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2853  }
static constexpr std::array< SqlWindowFunctionKind, 7 > REQUIRE_HASH_TABLE_FOR_FRAMING
Definition: Analyzer.h:2761
SqlWindowFunctionKind
Definition: sqldefs.h:122
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863
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 2835 of file Analyzer.h.

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

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

2835  {
2836  return std::any_of(
2839  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2840  }
static constexpr std::array< SqlWindowFunctionKind, 14 > FRAMING_ALLOWED_WINDOW_FUNCS
Definition: Analyzer.h:2732
SqlWindowFunctionKind
Definition: sqldefs.h:122
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::isMissingValueFillingFunction ( ) const
inline

Definition at line 2855 of file Analyzer.h.

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

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

2855  {
2856  return std::any_of(
2859  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2860  }
SqlWindowFunctionKind
Definition: sqldefs.h:122
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)
static constexpr std::array< SqlWindowFunctionKind, 2 > FILLING_FUNCS_USING_WINDOW
Definition: Analyzer.h:2758

+ 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 2651 of file Analyzer.cpp.

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

2651  {
2652  const auto rhs_window = dynamic_cast<const WindowFunction*>(&rhs);
2653  if (!rhs_window) {
2654  return false;
2655  }
2656  if (kind_ != rhs_window->kind_ || args_.size() != rhs_window->args_.size() ||
2657  partition_keys_.size() != rhs_window->partition_keys_.size() ||
2658  order_keys_.size() != rhs_window->order_keys_.size() ||
2659  frame_bound_type_ != rhs_window->frame_bound_type_ ||
2660  frame_start_bound_.get() != rhs_window->frame_start_bound_.get() ||
2661  frame_end_bound_.get() != rhs_window->frame_end_bound_.get()) {
2662  return false;
2663  }
2664  return expr_list_match(args_, rhs_window->args_) &&
2665  expr_list_match(partition_keys_, rhs_window->partition_keys_) &&
2666  expr_list_match(order_keys_, rhs_window->order_keys_);
2667 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2869
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2866
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2865
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2864
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2868
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:4569
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:2770
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 3114 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.

3114  {
3115  std::string result = "WindowFunction(" + ::toString(kind_);
3116  for (const auto& arg : args_) {
3117  result += " " + arg->toString();
3118  }
3119  if (hasFraming()) {
3120  result += " Frame{";
3121  switch (frame_bound_type_) {
3122  case FrameBoundType::ROW: {
3123  result += "ROW";
3124  break;
3125  }
3126  case FrameBoundType::RANGE: {
3127  result += "RANGE";
3128  break;
3129  }
3130  default: {
3131  UNREACHABLE()
3132  << "Two bound types are supported for window framing: ROW and RANGE.";
3133  break;
3134  }
3135  }
3136  result += " BETWEEN : " + frame_start_bound_->toString();
3137  result += " AND : " + frame_end_bound_->toString();
3138  } else {
3139  if (!order_keys_.empty()) {
3140  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
3141  } else {
3142  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
3143  }
3144  }
3145  result += "} ";
3146  return result + ") ";
3147 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2869
#define UNREACHABLE()
Definition: Logger.h:338
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2866
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2864
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2867
std::string toString() const override
Definition: Analyzer.cpp:3114
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2868
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2863
bool hasFraming() const
Definition: Analyzer.h:2830

+ 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 2864 of file Analyzer.h.

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

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

Definition at line 2870 of file Analyzer.h.

Referenced by deep_copy(), and getCollation().

constexpr std::array<SqlWindowFunctionKind, 2> Analyzer::WindowFunction::FILLING_FUNCS_USING_WINDOW
static
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 2869 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 2868 of file Analyzer.h.

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

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

Definition at line 2866 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 2865 of file Analyzer.h.

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


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