529 const auto cast_ti =
casts_[bin_oper];
532 if ((cast_ti.is_integer() || cast_ti.is_fp()) && lhs_ti.is_integer() &&
533 cast_ti.get_size() > lhs_ti.get_size() &&
537 left_operand = left_operand->deep_copy()->add_cast(cast_ti);
538 right_operand = right_operand->deep_copy()->add_cast(cast_ti);
543 const auto lhs =
visit(left_operand.get());
544 const auto rhs =
visit(right_operand.get());
549 const auto& rhs_ti = rhs->get_type_info();
553 if (const_lhs && const_rhs && lhs_type == rhs_type) {
554 auto lhs_datum = const_lhs->get_constval();
555 auto rhs_datum = const_rhs->get_constval();
556 Datum result_datum = {};
558 if (
foldOper(optype, lhs_type, lhs_datum, rhs_datum, result_datum, result_type)) {
561 return makeExpr<Analyzer::Constant>(result_type,
false, result_datum);
566 return makeExpr<Analyzer::Constant>(ti,
false, result_datum);
571 if (optype ==
kAND && lhs_type == rhs_type && lhs_type ==
kBOOLEAN) {
572 if (const_rhs && !const_rhs->get_is_null()) {
573 auto rhs_datum = const_rhs->get_constval();
574 if (rhs_datum.boolval ==
false) {
578 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
583 if (const_lhs && !const_lhs->get_is_null()) {
584 auto lhs_datum = const_lhs->get_constval();
585 if (lhs_datum.boolval ==
false) {
589 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
595 if (optype ==
kOR && lhs_type == rhs_type && lhs_type ==
kBOOLEAN) {
596 if (const_rhs && !const_rhs->get_is_null()) {
597 auto rhs_datum = const_rhs->get_constval();
598 if (rhs_datum.boolval ==
true) {
602 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
607 if (const_lhs && !const_lhs->get_is_null()) {
608 auto lhs_datum = const_lhs->get_constval();
609 if (lhs_datum.boolval ==
true) {
613 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
620 if (!lhs_ti.get_notnull()) {
621 CHECK(!rhs_ti.get_notnull());
628 return makeExpr<Analyzer::BinOper>(ti,
635 CHECK(rhs_ti.get_notnull());
637 if (optype ==
kEQ || optype ==
kLE || optype ==
kGE) {
640 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
643 if (optype ==
kNE || optype ==
kLT || optype ==
kGT) {
646 return makeExpr<Analyzer::Constant>(
kBOOLEAN,
false, d);
651 return makeExpr<Analyzer::Constant>(lhs_type,
false, d);
655 if (optype ==
kDIVIDE && const_rhs && rhs_ti.is_fp()) {
656 auto rhs_datum = const_rhs->get_constval();
657 std::shared_ptr<Analyzer::Expr> recip_rhs =
nullptr;
658 if (rhs_ti.get_type() ==
kFLOAT) {
659 if (rhs_datum.floatval == 1.0) {
662 auto f = std::fabs(rhs_datum.floatval);
663 if (
f > 1.0 || (
f != 0.0 && 1.0 <
f * std::numeric_limits<float>::max())) {
664 rhs_datum.floatval = 1.0 / rhs_datum.floatval;
665 recip_rhs = makeExpr<Analyzer::Constant>(rhs_type,
false, rhs_datum);
667 }
else if (rhs_ti.get_type() ==
kDOUBLE) {
668 if (rhs_datum.doubleval == 1.0) {
671 auto d = std::fabs(rhs_datum.doubleval);
672 if (d > 1.0 || (d != 0.0 && 1.0 < d * std::numeric_limits<double>::max())) {
673 rhs_datum.doubleval = 1.0 / rhs_datum.doubleval;
674 recip_rhs = makeExpr<Analyzer::Constant>(rhs_type,
false, rhs_datum);
678 return makeExpr<Analyzer::BinOper>(ti,
687 return makeExpr<Analyzer::BinOper>(ti,
bool get_contains_agg() const
std::shared_ptr< Analyzer::Expr > visit(const Analyzer::Expr *expr) const
SQLOps get_optype() const
bool foldOper(SQLOps optype, SQLTypes type, Datum lhs, Datum rhs, Datum &result, SQLTypes &result_type) const
const SQLTypeInfo & get_type_info() const
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
std::unordered_map< const Analyzer::Expr *, const SQLTypeInfo > casts_
const Expr * get_left_operand() const
const std::shared_ptr< Analyzer::Expr > get_own_right_operand() const
const std::shared_ptr< Analyzer::Expr > get_own_left_operand() const
SQLQualifier get_qualifier() const