You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "Anthrino (via GitHub)" <gi...@apache.org> on 2023/09/06 17:50:49 UTC
[GitHub] [calcite] Anthrino commented on a diff in pull request #3408: [CALCITE-5978] Add REGEXP_INSTR function (enabled in BigQuery library)
Anthrino commented on code in PR #3408:
URL: https://github.com/apache/calcite/pull/3408#discussion_r1317637600
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -488,13 +502,74 @@ public List<String> regexpExtractAll(String value, String regex) {
ImmutableList.Builder<String> matches = ImmutableList.builder();
while (matcher.find()) {
String match = matcher.group(matcher.groupCount());
- if (match != null && !match.isEmpty()) {
+ if (match != null) {
matches.add(match);
}
}
return matches.build();
}
+ /** SQL {@code REGEXP_INSTR(value, regexp)} function.
+ * Returns 0 if there is no match or regex is empty. Returns an exception if regex is invalid.
+ * Uses position=1, occurrence=1, occurrencePosition=0 as default values if not specified. */
+ public Integer regexpInstr(String value, String regex) {
+ return regexpInstr(value, regex, 1, 1, 0);
+ }
+
+ /** SQL {@code REGEXP_INSTR(value, regexp, position)} function.
+ * Returns 0 if there is no match, regex is empty, or if position is beyond range.
+ * Returns an exception if regex or position is invalid.
+ * Uses occurrence=1, occurrencePosition=0 as default value when not specified. */
+ public Integer regexpInstr(String value, String regex, int position) {
+ return regexpInstr(value, regex, position, 1, 0);
+ }
+
+ /** SQL {@code REGEXP_INSTR(value, regexp, position, occurrence)} function.
+ * Returns NULL if there is no match, regex is empty, or if position or occurrence
Review Comment:
My bad missed on correcting this instance, should be aligned with the others thanks for catching it!
--
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: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org