Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kecookier committed Jul 3, 2024
1 parent c2f6d5e commit 39df5c8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool SubstraitToVeloxPlanValidator::validateRegexExpr(
const auto& pattern = patternArg.literal().string();

std::string rewrite;
if (scalarFunction.arguments().size() > 2) {
if (name == "regexp_replace " && scalarFunction.arguments().size() > 2) {
const auto& rewriteArg = scalarFunction.arguments()[2].value();
if (!rewriteArg.has_literal() || !rewriteArg.literal().has_string()) {
LOG_VALIDATION_MSG("Rewrite is not string literal for " + name);
Expand Down
2 changes: 1 addition & 1 deletion cpp/velox/substrait/SubstraitToVeloxPlanValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class SubstraitToVeloxPlanValidator {

/// Validates regex functions.
/// Ensures the second pattern argument is a literal string.
/// Check if the pattern can pass with RE2 compilation.
/// Check if the pattern can pass with RE2 compilation and check rewriteString of regexp_replace is validate
bool validateRegexExpr(const std::string& name, const ::substrait::Expression::ScalarFunction& scalarFunction);

/// Validate Substrait scarlar function.
Expand Down
9 changes: 7 additions & 2 deletions cpp/velox/utils/Common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,23 @@ std::unique_ptr<re2::RE2> compilePattern(const std::string& pattern) {
return std::make_unique<re2::RE2>(re2::StringPiece(pattern), RE2::Quiet);
}

bool validatePattern(const std::string& pattern, const std::string& rewrite, std::string& error) {
bool validateRe2Function(const std::string& pattern, const std::string& rewrite, std::string& error) {
auto re2 = compilePattern(pattern);
if (!re2->ok()) {
error = "Pattern " + pattern + " compilation failed in RE2. Reason: " + re2->error();
return false;
}

if (!ensureRegexIsCompatible(pattern, error)) {
return false;
}

std::string err;
if (!rewrite.empty() && !re2->CheckRewriteString(re2::StringPiece(rewrite), &err)) {
error = "Rewrite " + rewrite + "check failed in RE2. Reason: " + err;
return false;
}
return ensureRegexIsCompatible(pattern, error);
return true;
}

} // namespace gluten
2 changes: 1 addition & 1 deletion cpp/velox/utils/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace gluten {
// Compile the given pattern and return the RE2 object.
inline std::unique_ptr<re2::RE2> compilePattern(const std::string& pattern);

bool validatePattern(const std::string& pattern, const std::string& rewrite, std::string& error);
bool validateRe2Function(const std::string& pattern, const std::string& rewrite, std::string& error);

static inline void fastCopy(void* dst, const void* src, size_t n) {
facebook::velox::simd::memcpy(dst, src, n);
Expand Down

0 comments on commit 39df5c8

Please sign in to comment.