319712 {
319713 auto &
root = bindings[0].get().Cast<BoundFunctionExpression>();
319714 auto &constant = bindings[1].get().Cast<BoundConstantExpression>();
319715 idx_t constant_child =
root.children[0].get() == &constant ? 0 : 1;
319716 D_ASSERT(
root.children.size() == 2);
319718
319719 if (constant.value.IsNull()) {
319720 return make_uniq<BoundConstantExpression>(Value(
root.return_type));
319721 }
319722 auto &func_name =
root.function.name;
319723 if (func_name == "+") {
319724 if (constant.value == 0) {
319725
319726
319727 return std::move(
root.children[1 - constant_child]);
319728 }
319729 } else if (func_name == "-") {
319730 if (constant_child == 1 && constant.value == 0) {
319731
319732
319733 return std::move(
root.children[1 - constant_child]);
319734 }
319735 } else if (func_name == "*") {
319736 if (constant.value == 1) {
319737
319738 return std::move(
root.children[1 - constant_child]);
319739 } else if (constant.value == 0) {
319740
319741 return ExpressionRewriter::ConstantOrNull(std::move(
root.children[1 - constant_child]),
319743 }
319744 } else if (func_name == "//") {
319745 if (constant_child == 1) {
319746 if (constant.value == 1) {
319747
319748 return std::move(
root.children[1 - constant_child]);
319749 } else if (constant.value == 0) {
319750
319751 return make_uniq<BoundConstantExpression>(Value(
root.return_type));
319752 }
319753 }
319754 } else {
319755 throw InternalException("Unrecognized function name in ArithmeticSimplificationRule");
319756 }
319757 return nullptr;
319758}
static DUCKDB_API Value Numeric(const LogicalType &type, int64_t value)
Create a Numeric value of the specified type with the specified value.
Definition duckdb.cpp:133053
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237