321448 {
321449 auto &
root = bindings[0].get().Cast<BoundFunctionExpression>();
321450 auto &constant_expr = bindings[2].get().Cast<BoundConstantExpression>();
321451 D_ASSERT(
root.children.size() == 2);
321452
321453 if (constant_expr.value.IsNull()) {
321454 return make_uniq<BoundConstantExpression>(Value(
root.return_type));
321455 }
321456
321457
321458 if (!constant_expr.IsFoldable()) {
321459 return nullptr;
321460 }
321461
321463 D_ASSERT(constant_value.type() == constant_expr.return_type);
321464 auto &patt_str = StringValue::Get(constant_value);
321465
321466 bool is_not_like =
root.function.name ==
"!~~";
321467 if (PatternIsConstant(patt_str)) {
321468
321469 return make_uniq<BoundComparisonExpression>(is_not_like ? ExpressionType::COMPARE_NOTEQUAL
321470 : ExpressionType::COMPARE_EQUAL,
321471 std::move(
root.children[0]), std::move(
root.children[1]));
321472 } else if (PatternIsPrefix(patt_str)) {
321473
321474 return ApplyRule(
root, PrefixFun::GetFunction(), patt_str, is_not_like);
321475 } else if (PatternIsSuffix(patt_str)) {
321476
321477 return ApplyRule(
root, SuffixFun::GetFunction(), patt_str, is_not_like);
321478 } else if (PatternIsContains(patt_str)) {
321479
321480 return ApplyRule(
root, GetStringContains(), patt_str, is_not_like);
321481 }
321482 return nullptr;
321483}
static DUCKDB_API Value EvaluateScalar(ClientContext &context, const Expression &expr, bool allow_unfoldable=false)
Evaluate a scalar expression and fold it into a single value.
Definition duckdb.cpp:149993