Class SqlFunctions.RegexFunction

java.lang.Object
org.apache.calcite.runtime.SqlFunctions.RegexFunction
Enclosing class:
SqlFunctions

public static class SqlFunctions.RegexFunction extends Object
State for REGEXP_CONTAINS, REGEXP_EXTRACT, REGEXP_EXTRACT_ALL, REGEXP_INSTR, REGEXP_REPLACE, RLIKE.

Marked deterministic so that the code generator instantiates one once per query, not once per row.

  • Constructor Details

    • RegexFunction

      public RegexFunction()
  • Method Details

    • replaceNonDollarIndexedString

      public static String replaceNonDollarIndexedString(String replacement)
      Preprocesses double-backslash-based indexing for capturing groups into $-based indices recognized by java regex, throws an error for invalid escapes.
    • regexpContains

      public boolean regexpContains(String value, String regex)
      SQL REGEXP_CONTAINS(value, regexp) function. Throws a runtime exception for invalid regular expressions.
    • regexpExtract

      public @Nullable String regexpExtract(String value, String regex)
      SQL REGEXP_EXTRACT(value, regexp) function. Returns NULL if there is no match. Returns an exception if regex is invalid. Uses position=1 and occurrence=1 as default values when not specified.
    • regexpExtract

      public @Nullable String regexpExtract(String value, String regex, int position)
      SQL REGEXP_EXTRACT(value, regexp, position) function. Returns NULL if there is no match, or if position is beyond range. Returns an exception if regex or position is invalid. Uses occurrence=1 as default value when not specified.
    • regexpExtract

      public @Nullable String regexpExtract(String value, String regex, int position, int occurrence)
      SQL REGEXP_EXTRACT(value, regexp, position, occurrence) function. Returns NULL if there is no match, or if position or occurrence are beyond range. Returns an exception if regex, position or occurrence are invalid.
    • regexpExtractAll

      public List<String> regexpExtractAll(String value, String regex)
      SQL REGEXP_EXTRACT_ALL(value, regexp) function. Returns an empty array if there is no match, returns an exception if regex is invalid.
    • regexpInstr

      public int regexpInstr(String value, String regex)
      SQL 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.
    • regexpInstr

      public int regexpInstr(String value, String regex, int position)
      SQL 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.
    • regexpInstr

      public int regexpInstr(String value, String regex, int position, int occurrence)
      SQL REGEXP_INSTR(value, regexp, position, occurrence) function. Returns 0 if there is no match, regex is empty, or if position or occurrence are beyond range. Returns an exception if regex, position or occurrence are invalid. Uses occurrencePosition=0 as default value when not specified.
    • regexpInstr

      public int regexpInstr(String value, String regex, int position, int occurrence, int occurrencePosition)
      SQL REGEXP_INSTR(value, regexp, position, occurrence, occurrencePosition) function. Returns 0 if there is no match, regex is empty, or if position or occurrence are beyond range. Returns an exception if regex, position, occurrence or occurrencePosition are invalid.
    • regexpReplace

      public String regexpReplace(String s, String regex, String replacement)
      SQL REGEXP_REPLACE function with 3 arguments.
    • regexpReplace

      public String regexpReplace(String s, String regex, String replacement, int pos)
      SQL REGEXP_REPLACE function with 4 arguments.
    • regexpReplace

      public String regexpReplace(String s, String regex, String replacement, int pos, int occurrence)
      SQL REGEXP_REPLACE function with 5 arguments.
    • regexpReplace

      public String regexpReplace(String s, String regex, String replacement, int pos, int occurrence, @Nullable String matchType)
      SQL REGEXP_REPLACE function with 6 arguments.
    • regexpReplaceNonDollarIndexed

      public String regexpReplaceNonDollarIndexed(String s, String regex, String replacement)
      SQL REGEXP_REPLACE function with 3 arguments with \\ based indexing for capturing groups.
    • rlike

      public boolean rlike(String s, String pattern)
      SQL RLIKE function.