OmniSciDB  c0231cc57d
 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 2360 of file Analyzer.h.

Member Enumeration Documentation

Enumerator
NONE 
ROW 
RANGE 

Definition at line 2362 of file Analyzer.h.

2362 { 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 2382 of file Analyzer.h.

2391  : Expr(ti)
2392  , kind_(kind)
2393  , args_(args)
2394  , partition_keys_(partition_keys)
2395  , order_keys_(order_keys)
2396  , frame_bound_type_(frame_bound_type)
2397  , frame_start_bound_(frame_start_bound)
2398  , frame_end_bound_(frame_end_bound)
2399  , collation_(collation){};
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2468
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2465
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2464
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2463
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2466
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2467
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2469
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2462

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:2468
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2465
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2464
SQLTypeInfo type_info
Definition: Analyzer.h:183
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2463
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2466
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2467
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2469
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2462
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 2432 of file Analyzer.h.

References collation_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 2434 of file Analyzer.h.

References frame_bound_type_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2434  {
2435  return frame_bound_type_;
2436  }
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2466

+ Here is the caller graph for this function:

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

Definition at line 2425 of file Analyzer.h.

References CHECK, and frame_end_bound_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2425  {
2426  std::shared_ptr<WindowFrame> frame_end_bound =
2427  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2428  CHECK(frame_end_bound);
2429  return frame_end_bound.get();
2430  }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2468
#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 2418 of file Analyzer.h.

References CHECK, and frame_start_bound_.

Referenced by DeepCopyVisitor::visitWindowFunction().

2418  {
2419  std::shared_ptr<WindowFrame> frame_start_bound =
2420  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2421  CHECK(frame_start_bound);
2422  return frame_start_bound.get();
2423  }
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2467
#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 2414 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().

2414  {
2415  return order_keys_;
2416  }
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2465

+ Here is the caller graph for this function:

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

Definition at line 2410 of file Analyzer.h.

References partition_keys_.

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

2410  {
2411  return partition_keys_;
2412  }
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2464

+ Here is the caller graph for this function:

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

Definition at line 2454 of file Analyzer.h.

References AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING, and kind_.

Referenced by WindowFunctionContext::needsToBuildAggregateTree().

2454  {
2455  return std::any_of(
2458  [&](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2459  }
SqlWindowFunctionKind
Definition: sqldefs.h:113
static constexpr std::array< SqlWindowFunctionKind, 6 > AGGREGATION_TREE_REQUIRED_WINDOW_FUNCS_FOR_FRAMING
Definition: Analyzer.h:2373
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2462

+ Here is the caller graph for this function:

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

Definition at line 2442 of file Analyzer.h.

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

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

2442  {
2445  }
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2447
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2466
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2462

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

References frame_bound_type_, and ROW.

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

Definition at line 2447 of file Analyzer.h.

References FRAMING_ALLOWED_WINDOW_FUNCS.

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

2447  {
2448  return std::any_of(
2451  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2452  }
static constexpr std::array< SqlWindowFunctionKind, 8 > FRAMING_ALLOWED_WINDOW_FUNCS
Definition: Analyzer.h:2363
SqlWindowFunctionKind
Definition: sqldefs.h:113

+ Here is the caller graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2519 of file Analyzer.cpp.

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

2519  {
2520  const auto rhs_window = dynamic_cast<const WindowFunction*>(&rhs);
2521  if (!rhs_window) {
2522  return false;
2523  }
2524  if (kind_ != rhs_window->kind_ || args_.size() != rhs_window->args_.size() ||
2525  partition_keys_.size() != rhs_window->partition_keys_.size() ||
2526  order_keys_.size() != rhs_window->order_keys_.size() ||
2527  frame_bound_type_ != rhs_window->frame_bound_type_ ||
2528  frame_start_bound_.get() != rhs_window->frame_start_bound_.get() ||
2529  frame_end_bound_.get() != rhs_window->frame_end_bound_.get()) {
2530  return false;
2531  }
2532  return expr_list_match(args_, rhs_window->args_) &&
2533  expr_list_match(partition_keys_, rhs_window->partition_keys_) &&
2534  expr_list_match(order_keys_, rhs_window->order_keys_);
2535 }
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2468
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2465
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2464
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2463
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2466
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2467
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:4231
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:2382
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2462

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

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

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

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

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

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

Definition at line 2469 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 2468 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 2467 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 2465 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 2464 of file Analyzer.h.

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


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