20 #include "../Analyzer/Analyzer.h"
21 #include "../Parser/ParserNode.h"
33 if (!func_oper || func_oper->getName() !=
"TRUNCATE") {
36 CHECK_EQ(
size_t(2), func_oper->getArity());
37 const auto arg = func_oper->getArg(0);
38 const auto& arg_ti = arg->get_type_info();
39 return arg_ti.is_integer() ? arg :
nullptr;
48 if (!const_ti.is_integer()) {
51 const auto& datum = const_expr->get_constval();
52 switch (const_ti.get_type()) {
54 return v == datum.tinyintval;
56 return v == datum.smallintval;
58 return v == datum.intval;
60 return v == datum.bigintval;
71 const auto extract_fn =
73 return (extract_fn && extract_fn->get_field() ==
kHOUR &&
74 *extract_fn->get_from_expr() == *ts)
78 const auto interval_multiplier_fn =
80 if (!interval_multiplier_fn) {
83 const auto interval_multiplier_mul =
85 if (!interval_multiplier_mul || interval_multiplier_mul->get_optype() !=
kMULTIPLY ||
90 interval_multiplier_mul->get_right_operand());
91 if (!extract_minus_one || extract_minus_one->get_optype() !=
kMINUS ||
95 const auto extract_fn =
97 if (!extract_fn || !(*extract_fn->get_from_expr() == *ts)) {
100 switch (extract_fn->get_field()) {
113 if (!mul_by_interval) {
118 auto interval_multiplier = mul_by_interval->get_left_operand();
125 interval_multiplier = mul_by_interval->get_right_operand();
127 const auto& interval_ti = interval->get_type_info();
131 const auto& datum = interval->get_constval();
132 switch (datum.bigintval) {
148 if (!uoper || uoper->get_optype() !=
kCAST) {
152 const auto& target_ti = uoper->get_type_info();
153 if (operand_ti.get_type() !=
kTIMESTAMP || target_ti.get_type() !=
kDATE) {
156 return uoper->get_own_operand();
169 const auto off_arg = dt_plus->
getArg(1);
const Analyzer::Expr * remove_cast_to_int(const Analyzer::Expr *expr)
DatetruncField get_dt_field(const Analyzer::Expr *ts, const Analyzer::Expr *interval_multiplier, const bool dt_hour)
const SQLTypeInfo & get_type_info() const
const Analyzer::Expr * getArg(const size_t i) const
const Expr * get_operand() const
bool match_const_integer(const Analyzer::Expr *expr, const int64_t v)
std::shared_ptr< Analyzer::Expr > remove_cast_to_date(const Analyzer::Expr *expr)
const Analyzer::Expr * remove_truncate_int(const Analyzer::Expr *expr)
std::string getName() const
std::shared_ptr< Analyzer::Expr > rewrite_to_date_trunc(const Analyzer::FunctionOper *dt_plus)
const std::shared_ptr< Analyzer::Expr > generate() const