23 const auto else_null =
36 zero->get_constval().bigintval == 0;
60 if (expr_pair_list.size() != 1) {
63 const auto& expr_pair = expr_pair_list.front();
64 const auto window_gt_zero =
69 const auto sum_window_expr =
71 if (!sum_window_expr || !
is_sum_kind(sum_window_expr->getKind())) {
74 const auto count_window_expr =
76 remove_cast(window_gt_zero->get_own_left_operand()));
77 if (!count_window_expr ||
84 CHECK(sum_window_expr);
85 auto sum_ti = sum_window_expr->get_type_info();
86 if (sum_ti.is_integer()) {
89 return makeExpr<Analyzer::WindowFunction>(
92 sum_window_expr->getArgs(),
93 sum_window_expr->getPartitionKeys(),
94 sum_window_expr->getOrderKeys(),
95 sum_window_expr->getFrameBoundType(),
96 sum_window_expr->getFrameStartBound()->deep_copy(),
97 sum_window_expr->getFrameEndBound()->deep_copy(),
98 sum_window_expr->getCollation());
104 cast_expr && cast_expr->get_optype() ==
kCAST ? cast_expr->get_operand() : expr);
105 if (!div_expr || div_expr->get_optype() !=
kDIVIDE) {
109 if (!sum_window_expr) {
112 const auto cast_count_window =
114 if (cast_count_window && cast_count_window->get_optype() !=
kCAST) {
118 cast_count_window ? cast_count_window->get_operand()
119 : div_expr->get_right_operand());
124 if (cast_count_window && cast_count_window->get_type_info().get_type() !=
125 sum_window_expr->get_type_info().get_type()) {
128 if (!
expr_list_match(sum_window_expr.get()->getArgs(), count_window->getArgs())) {
131 return makeExpr<Analyzer::WindowFunction>(
134 sum_window_expr->getArgs(),
135 sum_window_expr->getPartitionKeys(),
136 sum_window_expr->getOrderKeys(),
137 sum_window_expr->getFrameBoundType(),
138 sum_window_expr->getFrameStartBound()->deep_copy(),
139 sum_window_expr->getFrameEndBound()->deep_copy(),
140 sum_window_expr->getCollation());
const Expr * get_else_expr() const
bool matches_gt_bigint_zero(const Analyzer::BinOper *window_gt_zero)
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
std::shared_ptr< Analyzer::WindowFunction > rewrite_avg_window(const Analyzer::Expr *expr)
bool window_sum_and_count_match(const Analyzer::WindowFunction *sum_window_expr, const Analyzer::WindowFunction *count_window_expr)
std::shared_ptr< Analyzer::WindowFunction > rewrite_sum_window(const Analyzer::Expr *expr)
const Expr * get_right_operand() const
HOST DEVICE SQLTypes get_type() const
SQLOps get_optype() const
bool matches_else_null(const Analyzer::CaseExpr *case_expr)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
bool expr_list_match(const std::vector< std::shared_ptr< Analyzer::Expr >> &lhs, const std::vector< std::shared_ptr< Analyzer::Expr >> &rhs)
bool is_sum_kind(const SqlWindowFunctionKind kind)
const SQLTypeInfo & get_type_info() const
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const