OmniSciDB  ca0c39ec8f
 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
 
- 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 (bool(*f)(const Expr *), 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, 8 > 
FRAMING_ALLOWED_WINDOW_FUNCS
 
static constexpr std::array
< SqlWindowFunctionKind, 6 > 
AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_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 2408 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
NONE 
ROW 
RANGE 

Definition at line 2410 of file Analyzer.h.

2410 { 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 2430 of file Analyzer.h.

2439  : Expr(ti)
2440  , kind_(kind)
2441  , args_(args)
2442  , partition_keys_(partition_keys)
2443  , order_keys_(order_keys)
2444  , frame_bound_type_(frame_bound_type)
2445  , frame_start_bound_(frame_start_bound)
2446  , frame_end_bound_(frame_end_bound)
2447  , collation_(collation){};
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2516
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2513
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2512
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2511
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2515
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2517
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510

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:2516
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2513
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2512
SQLTypeInfo type_info
Definition: Analyzer.h:183
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2511
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2515
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2517
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510
const std::vector<std::shared_ptr<Analyzer::Expr> >& Analyzer::WindowFunction::getArgs ( ) const
inline
const std::vector<OrderEntry>& Analyzer::WindowFunction::getCollation ( ) const
inline

Definition at line 2480 of file Analyzer.h.

References collation_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 2482 of file Analyzer.h.

References frame_bound_type_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2482  {
2483  return frame_bound_type_;
2484  }
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514

+ Here is the caller graph for this function:

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

Definition at line 2473 of file Analyzer.h.

References CHECK, and frame_end_bound_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2473  {
2474  std::shared_ptr<WindowFrame> frame_end_bound =
2475  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2476  CHECK(frame_end_bound);
2477  return frame_end_bound.get();
2478  }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2516
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 2466 of file Analyzer.h.

References CHECK, and frame_start_bound_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2466  {
2467  std::shared_ptr<WindowFrame> frame_start_bound =
2468  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2469  CHECK(frame_start_bound);
2470  return frame_start_bound.get();
2471  }
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2515
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 2462 of file Analyzer.h.

References order_keys_.

Referenced by Executor::codegenFrameBoundExpr(), WindowFunctionContext::compute(), WindowFunctionContext::createComparator(), RelAlgExecutor::createWindowFunctionContext(), ScalarExprToSql::visitWindowFunction(), DeepCopyVisitor::visitWindowFunction(), ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWindowFunction(), and window_function_requires_peer_handling().

2462  {
2463  return order_keys_;
2464  }
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2513

+ Here is the caller graph for this function:

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

Definition at line 2458 of file Analyzer.h.

References partition_keys_.

Referenced by RelAlgExecutor::computeWindow(), ScalarExprToSql::visitWindowFunction(), DeepCopyVisitor::visitWindowFunction(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWindowFunction().

2458  {
2459  return partition_keys_;
2460  }
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2512

+ Here is the caller graph for this function:

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

Definition at line 2502 of file Analyzer.h.

References AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING, and kind_.

Referenced by WindowFunctionContext::needsToBuildAggregateTree().

2502  {
2503  return std::any_of(
2506  [&](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2507  }
SqlWindowFunctionKind
Definition: sqldefs.h:114
static constexpr std::array< SqlWindowFunctionKind, 6 > AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
Definition: Analyzer.h:2421
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510

+ Here is the caller graph for this function:

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

Definition at line 2490 of file Analyzer.h.

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

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

2490  {
2493  }
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2495
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510

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

References frame_bound_type_, and ROW.

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

Definition at line 2495 of file Analyzer.h.

References FRAMING_ALLOWED_WINDOW_FUNCS.

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

2495  {
2496  return std::any_of(
2499  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2500  }
static constexpr std::array< SqlWindowFunctionKind, 8 > FRAMING_ALLOWED_WINDOW_FUNCS
Definition: Analyzer.h:2411
SqlWindowFunctionKind
Definition: sqldefs.h:114

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2524 of file Analyzer.cpp.

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

2524  {
2525  const auto rhs_window = dynamic_cast<const WindowFunction*>(&rhs);
2526  if (!rhs_window) {
2527  return false;
2528  }
2529  if (kind_ != rhs_window->kind_ || args_.size() != rhs_window->args_.size() ||
2530  partition_keys_.size() != rhs_window->partition_keys_.size() ||
2531  order_keys_.size() != rhs_window->order_keys_.size() ||
2532  frame_bound_type_ != rhs_window->frame_bound_type_ ||
2533  frame_start_bound_.get() != rhs_window->frame_start_bound_.get() ||
2534  frame_end_bound_.get() != rhs_window->frame_end_bound_.get()) {
2535  return false;
2536  }
2537  return expr_list_match(args_, rhs_window->args_) &&
2538  expr_list_match(partition_keys_, rhs_window->partition_keys_) &&
2539  expr_list_match(order_keys_, rhs_window->order_keys_);
2540 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2516
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2513
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2512
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2511
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2515
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:4242
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:2430
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

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

2947  {
2948  std::string result = "WindowFunction(" + ::toString(kind_);
2949  for (const auto& arg : args_) {
2950  result += " " + arg->toString();
2951  }
2952  if (hasFraming()) {
2953  result += " Frame{";
2954  switch (frame_bound_type_) {
2955  case FrameBoundType::ROW: {
2956  result += "ROW";
2957  break;
2958  }
2959  case FrameBoundType::RANGE: {
2960  result += "RANGE";
2961  break;
2962  }
2963  default: {
2964  UNREACHABLE()
2965  << "Two bound types are supported for window framing: ROW and RANGE.";
2966  break;
2967  }
2968  }
2969  result += " BETWEEN : " + frame_start_bound_->toString();
2970  result += " AND : " + frame_end_bound_->toString();
2971  } else {
2972  if (!order_keys_.empty()) {
2973  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)";
2974  } else {
2975  result += " (RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)";
2976  }
2977  }
2978  result += "} ";
2979  return result + ") ";
2980 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2516
#define UNREACHABLE()
Definition: Logger.h:266
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2513
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2511
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2514
std::string toString() const override
Definition: Analyzer.cpp:2947
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2515
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2510
bool hasFraming() const
Definition: Analyzer.h:2490

+ Here is the call graph for this function:

Member Data Documentation

constexpr std::array<SqlWindowFunctionKind, 6> Analyzer::WindowFunction::AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
static
const std::vector<std::shared_ptr<Analyzer::Expr> > Analyzer::WindowFunction::args_
private

Definition at line 2511 of file Analyzer.h.

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

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

Definition at line 2517 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 2516 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 2515 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 2513 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 2512 of file Analyzer.h.

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


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