OmniSciDB  a5dc49c757
 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 2860 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
NONE 
ROW 
RANGE 

Definition at line 2862 of file Analyzer.h.

2862 { 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 2901 of file Analyzer.h.

2910  : Expr(ti)
2911  , kind_(kind)
2912  , args_(args)
2913  , partition_keys_(partition_keys)
2914  , order_keys_(order_keys)
2915  , frame_bound_type_(frame_bound_type)
2916  , frame_start_bound_(frame_start_bound)
2917  , frame_end_bound_(frame_end_bound)
2918  , collation_(collation){};
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:3000
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2997
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2996
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2995
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:3001
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994

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:3000
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2997
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2996
SQLTypeInfo type_info
Definition: Analyzer.h:180
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2995
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:3001
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994
const std::vector<OrderEntry>& Analyzer::WindowFunction::getCollation ( ) const
inline

Definition at line 2951 of file Analyzer.h.

References collation_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 2953 of file Analyzer.h.

References frame_bound_type_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2953  {
2954  return frame_bound_type_;
2955  }
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998

+ Here is the caller graph for this function:

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

Definition at line 2944 of file Analyzer.h.

References CHECK, and frame_end_bound_.

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

2944  {
2945  std::shared_ptr<WindowFrame> frame_end_bound =
2946  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2947  CHECK(frame_end_bound);
2948  return frame_end_bound.get();
2949  }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:3000
#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 2937 of file Analyzer.h.

References CHECK, and frame_start_bound_.

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

2937  {
2938  std::shared_ptr<WindowFrame> frame_start_bound =
2939  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2940  CHECK(frame_start_bound);
2941  return frame_start_bound.get();
2942  }
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
#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 2929 of file Analyzer.h.

References partition_keys_.

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

2929  {
2930  return partition_keys_;
2931  }
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2996

+ Here is the caller graph for this function:

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

Definition at line 2973 of file Analyzer.h.

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

Referenced by WindowFunctionContext::needsToBuildAggregateTree().

2973  {
2974  return std::any_of(
2977  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2978  }
static constexpr std::array< SqlWindowFunctionKind, 9 > AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
Definition: Analyzer.h:2879
SqlWindowFunctionKind
Definition: sqldefs.h:129
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994
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 2961 of file Analyzer.h.

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

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

2961  {
2964  }
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2966
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994

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

References frame_bound_type_, and ROW.

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

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

2979  {
2980  return std::any_of(
2983  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2984  }
static constexpr std::array< SqlWindowFunctionKind, 7 > REQUIRE_HASH_TABLE_FOR_FRAMING
Definition: Analyzer.h:2892
SqlWindowFunctionKind
Definition: sqldefs.h:129
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994
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 2966 of file Analyzer.h.

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

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

2966  {
2967  return std::any_of(
2970  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2971  }
static constexpr std::array< SqlWindowFunctionKind, 14 > FRAMING_ALLOWED_WINDOW_FUNCS
Definition: Analyzer.h:2863
SqlWindowFunctionKind
Definition: sqldefs.h:129
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 2986 of file Analyzer.h.

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

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

2986  {
2987  return std::any_of(
2990  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2991  }
SqlWindowFunctionKind
Definition: sqldefs.h:129
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994
bool any_of(std::vector< Analyzer::Expr * > const &target_exprs)
static constexpr std::array< SqlWindowFunctionKind, 2 > FILLING_FUNCS_USING_WINDOW
Definition: Analyzer.h:2889

+ 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:3000
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2997
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2996
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2995
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
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:4598
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:2901
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 3116 of file Analyzer.cpp.

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

3116  {
3117  std::ostringstream oss;
3118  oss << "WindowFunction(" << kind_;
3119  for (const auto& arg : args_) {
3120  oss << " " << arg->toString();
3121  }
3122  if (hasFraming()) {
3123  oss << " Frame{";
3124  switch (frame_bound_type_) {
3125  case FrameBoundType::ROW: {
3126  oss << "ROW";
3127  break;
3128  }
3129  case FrameBoundType::RANGE: {
3130  oss << "RANGE";
3131  break;
3132  }
3133  default: {
3134  UNREACHABLE()
3135  << "Two bound types are supported for window framing: ROW and RANGE.";
3136  break;
3137  }
3138  }
3139  oss << " BETWEEN : " + frame_start_bound_->toString();
3140  oss << " AND : " + frame_end_bound_->toString();
3141  } else {
3142  if (!order_keys_.empty()) {
3143  oss << " (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
3144  } else {
3145  oss << " (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
3146  }
3147  }
3148  oss << "} )";
3149  return oss.str();
3150 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:3000
#define UNREACHABLE()
Definition: Logger.h:338
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2997
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2995
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2994
bool hasFraming() const
Definition: Analyzer.h:2961

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

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

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

Definition at line 3001 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 3000 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 2999 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 2997 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 2996 of file Analyzer.h.

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


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