Skip to content

Commit

Permalink
Let function validation fail for lookaround pattern in RE2-based impl…
Browse files Browse the repository at this point in the history
…ementation (facebookincubator#124)
  • Loading branch information
PHILO-HE authored and zhejiangxiaomai committed Feb 27, 2023
1 parent 74de41d commit b5ae610
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions velox/functions/sparksql/RegexFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ void ensureRegexIsCompatible(
// instead adds the character ].
} else if (*c == ']' && charClassStart + 1 != c) {
charClassStart = nullptr;
} else if (*c == '(' && c + 3 < pattern.end() && *(c + 1) == '?') {
// RE2 doesn't support lookaround (lookahead or lookbehind), so we should exclude such patterns:
// (?=), (?!), (?<=), (?<!).
if (*(c + 2) == '=' || *(c + 2) == '!') {
VELOX_USER_FAIL("{} does NOT support lookahead in RE2-based implementation.", functionName)
} else if (*(c + 2) == '<' && (*(c + 3) == '=' || *(c + 3) == '!')) {
VELOX_USER_FAIL("{} does NOT support lookbehind in RE2-based implementation.", functionName)
}
}
}
}
Expand Down

0 comments on commit b5ae610

Please sign in to comment.