Anthrino commented on code in PR #3408:
URL: https://github.com/apache/calcite/pull/3408#discussion_r1317644115
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -404,16 +404,39 @@ private Pattern validateRegexPattern(String regex, String
methodName) {
}
}
- /** Helper for multiple capturing group regex check in REGEXP_EXTRACT fns.
*/
+ /** Helper for multiple capturing group regex check in REGEXP_* fns. */
private void checkMultipleCapturingGroupsInRegex(Matcher matcher, String
methodName) {
if (matcher.groupCount() > 1) {
throw RESOURCE.multipleCapturingGroupsForRegexpExtract(
Integer.toString(matcher.groupCount()), methodName).ex();
}
}
+ /** Helper for checking values of position and occurrence arguments in
REGEXP_* fns.
+ * Regex Fns not using occurrencePosition param pass a default value as 0.
+ * Throws an exception or returns true in case of failed value checks. */
+ private boolean checkPosOccurrenceParamValues(int position,
+ int occurrence, int occurrencePosition, String value, String
methodName) {
+ if (position <= 0) {
+ throw
RESOURCE.invalidIntegerInputForRegexpFunctions(Integer.toString(position),
+ "position", methodName).ex();
+ }
+ if (occurrence <= 0) {
+ throw
RESOURCE.invalidIntegerInputForRegexpFunctions(Integer.toString(occurrence),
+ "occurrence", methodName).ex();
+ }
+ if (occurrencePosition < 0 || occurrencePosition > 1) {
+ throw
RESOURCE.invalidIntegerInputForRegexpFunctions(Integer.toString(occurrencePosition),
+ "occurrence_position", methodName).ex();
+ }
+ if (position > value.length()) {
Review Comment:
kept it this way since thats the failing condition, can be inverted too is
that to make it more intuitive with return values true/false or for some other
reason?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]