[ 
https://issues.apache.org/jira/browse/CALCITE-5979?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17771593#comment-17771593
 ] 

Julian Hyde edited comment on CALCITE-5979 at 10/3/23 6:26 PM:
---------------------------------------------------------------

Of the databases that support REGEXP_REPLACE, none uses '$' to indicate 
replacement groups. 
[Redshift|https://docs.aws.amazon.com/redshift/latest/dg/REGEXP_REPLACE.html] 
does not support replacement groups. BigQuery, 
[Oracle|https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/REGEXP_REPLACE.html#GUID-EA80A33C-441A-4692-A959-273B5A224490]
 and 
[Snowflake|https://docs.snowflake.com/en/sql-reference/functions/regexp_replace]
 use '\'. I think we should do the same.

The replacement string is not a regular expression, so it's fairly independent 
of the re2 vs java-regex discussion.

Your idea for preprocessing the replacement strings makes sense. Just remember 
that the replacement strings may not be literals. And be sure to include some 
hard cases such as escaped back-slashes (when they literally want a backslash), 
dollar signs, and integers greater than 9.


was (Author: julianhyde):
Of the databases that support REGEXP_REPLACE, none uses '$' to indicate 
replacement groups. Redshift does not support replacement groups. BigQuery, 
Oracle and Snowflake use '\'. I think we should do the same.

The replacement string is not a regular expression, so it's fairly independent 
of the re2 vs java-regex discussion.

Your idea for preprocessing the replacement strings makes sense. Just remember 
that the replacement strings may not be literals. And be sure to include some 
hard cases such as escaped back-slashes (when they literally want a backslash), 
dollar signs, and integers greater than 9.

> Add REGEXP_REPLACE function (enabled in BigQuery library)
> ---------------------------------------------------------
>
>                 Key: CALCITE-5979
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5979
>             Project: Calcite
>          Issue Type: Task
>            Reporter: Jerin John
>            Assignee: Jerin John
>            Priority: Major
>              Labels: pull-request-available
>
> Add support for [REGEXP_REPLACE 
> |https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#regexp_replace]
>  function from BigQuery.
> *{{REGEXP_REPLACE(value, regexp, replacement)}}*
> Returns a STRING where all substrings of {{value}} that match regular 
> expression {{regexp}} are replaced with {{{}replacement{}}}.
> backslashed-escaped digits (\1 to \9) can be used within the {{replacement}} 
> argument to insert text matching the corresponding parenthesized group in the 
> {{regexp}} pattern.
> Example (added one space between \ \ to override md formatting):
> {{SELECT REGEXP_REPLACE("abc'", "b(.)", "X\ \1") as result;}}
> |result|
> |aXc|



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to