323014 {
323015 auto &
root = bindings[0].get().Cast<BoundFunctionExpression>();
323016 auto &constant_expr = bindings[2].get().Cast<BoundConstantExpression>();
323017 D_ASSERT(
root.children.size() == 2 ||
root.children.size() == 3);
323018 auto regexp_bind_data =
root.bind_info.get()->Cast<RegexpMatchesBindData>();
323019
323021 D_ASSERT(constant_value.type() == constant_expr.return_type);
323022
323023 duckdb_re2::RE2::Options parsed_options = regexp_bind_data.options;
323024
323025 if (constant_expr.value.IsNull()) {
323026 return make_uniq<BoundConstantExpression>(Value(
root.return_type));
323027 }
323028 auto patt_str = StringValue::Get(constant_value);
323029
323030
323031 if (!constant_expr.IsFoldable()) {
323032 return nullptr;
323033 };
323034
323035 duckdb_re2::RE2 pattern(patt_str, parsed_options);
323036 if (!pattern.ok()) {
323037 return nullptr;
323038 }
323039
323040 LikeString like_string;
323041
323042
323043 if (pattern.Regexp()->op() == duckdb_re2::kRegexpLiteralString ||
323044 pattern.Regexp()->op() == duckdb_re2::kRegexpLiteral) {
323045
323046 LikeString escaped_like_string = GetLikeStringEscaped(pattern.Regexp(), true);
323047 if (!escaped_like_string.exists) {
323048 return nullptr;
323049 }
323050
323051
323052 if (
root.children.size() == 3) {
323053 root.children.pop_back();
323054 D_ASSERT(
root.children.size() == 2);
323055 }
323056
323057 auto parameter = make_uniq<BoundConstantExpression>(Value(std::move(escaped_like_string.like_string)));
323058 auto contains = make_uniq<BoundFunctionExpression>(
root.return_type, GetStringContains(),
323059 std::move(
root.children),
nullptr);
323060 contains->children[1] = std::move(parameter);
323061
323062 return std::move(contains);
323063 } else if (pattern.Regexp()->op() == duckdb_re2::kRegexpConcat) {
323064 like_string = LikeMatchFromRegex(pattern);
323065 } else {
323066 like_string.exists = false;
323067 }
323068
323069 if (!like_string.exists) {
323070 return nullptr;
323071 }
323072
323073
323074 if (
root.children.size() == 3) {
323075 root.children.pop_back();
323076 D_ASSERT(
root.children.size() == 2);
323077 }
323078
323079 auto like_expression =
323080 make_uniq<BoundFunctionExpression>(
root.return_type, LikeFun::GetFunction(), std::move(
root.children),
nullptr);
323081 auto parameter = make_uniq<BoundConstantExpression>(Value(std::move(like_string.like_string)));
323082 like_expression->children[1] = std::move(parameter);
323083 return std::move(like_expression);
323084}
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