You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Syleechan (via GitHub)" <gi...@apache.org> on 2023/11/10 08:27:44 UTC

[PR] feat:implement posgres style 'overlay' string function [arrow-datafusion]

Syleechan opened a new pull request, #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117

   ## Which issue does this PR close?
   https://www.postgresql.org/docs/current/functions-string.html#:~:text=overlay%20(%20string,4)%20%E2%86%92%20Thomas 
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "Ted-Jiang (via GitHub)" <gi...@apache.org>.
Ted-Jiang merged PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#issuecomment-1807101427

   
   > Thank you for your contribution!
   > 
   > Could you move tests to [sqllogictest](https://github.com/apache/arrow-datafusion/blob/main/datafusion/sqllogictest/README.md), and add [SQL reference](https://github.com/apache/arrow-datafusion/blob/main/docs/source/user-guide/sql/scalar_functions.md)?
   
   I agree -- thank you @Syleechan 
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement posgres style 'overlay' string function [arrow-datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#issuecomment-1806218659

   Thank you for your contribution!
   
   Could you move tests to [sqllogictest](https://github.com/apache/arrow-datafusion/blob/main/datafusion/sqllogictest/README.md), and add [SQL reference](https://github.com/apache/arrow-datafusion/blob/main/docs/source/user-guide/sql/scalar_functions.md)?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "Syleechan (via GitHub)" <gi...@apache.org>.
Syleechan commented on code in PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#discussion_r1391911287


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1120,6 +1121,21 @@ Returns UUID v4 string value which is unique per row.
 uuid()
 ```
 
+### `overlay`
+
+Returns the string which is replaced by another string from the specified position and specified count length
+
+```
+overlay(str PLACING substr FROM pos [FOR count])
+```
+

Review Comment:
   To resolve the conflict, I have added this, thanks



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "Syleechan (via GitHub)" <gi...@apache.org>.
Syleechan commented on code in PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#discussion_r1391911647


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1120,6 +1121,21 @@ Returns UUID v4 string value which is unique per row.
 uuid()
 ```
 
+### `overlay`
+
+Returns the string which is replaced by another string from the specified position and specified count length
+
+```
+overlay(str PLACING substr FROM pos [FOR count])
+```
+
+#### Arguments
+
+- **str**: String expression to operate on.
+- **substr**: the string to replace part of str.
+- **pos**: the start position to replace of str.
+- **count**: the count of characters to be replaced from start position of str.If not specified, will use substr length instead.

Review Comment:
   resolved, thanks.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "Syleechan (via GitHub)" <gi...@apache.org>.
Syleechan commented on code in PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#discussion_r1391911934


##########
datafusion/sqllogictest/test_files/functions.slt:
##########
@@ -815,3 +815,33 @@ SELECT products.* REPLACE (price*2 AS price, product_id+1000 AS product_id) FROM
 1002 OldBrand Product 2 59.98
 1003 OldBrand Product 3 79.98
 1004 OldBrand Product 4 99.98
+
+#overlay tests
+statement ok
+CREATE TABLE over_test(
+  str TEXT,
+  characters TEXT,
+  pos INT,
+  len INT
+) as VALUES
+  ('123', 'abc', 4, 5),
+  ('abcdefg', 'qwertyasdfg', 1, 7),
+  ('xyz', 'ijk', 1, 2),
+  ('Txxxxas', 'hom', 2, 4)

Review Comment:
   Have added these cases, thanks.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "Syleechan (via GitHub)" <gi...@apache.org>.
Syleechan commented on PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#issuecomment-1807694805

   Thanks @2010YOUY01, @alamb . I have added the sqllogic test and sql reference.
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat:implement postgres style 'overlay' string function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8117:
URL: https://github.com/apache/arrow-datafusion/pull/8117#discussion_r1391532651


##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1120,6 +1121,21 @@ Returns UUID v4 string value which is unique per row.
 uuid()
 ```
 
+### `overlay`
+
+Returns the string which is replaced by another string from the specified position and specified count length
+
+```
+overlay(str PLACING substr FROM pos [FOR count])
+```
+

Review Comment:
   Having the example made it much easier for me to see what was going on in postgres. Can we add an example here as well?
   
   ```suggestion
   For example, `overlay('Txxxxas' placing 'hom' from 2 for 4) → Thomas`
   ```
   



##########
datafusion/sqllogictest/test_files/functions.slt:
##########
@@ -815,3 +815,33 @@ SELECT products.* REPLACE (price*2 AS price, product_id+1000 AS product_id) FROM
 1002 OldBrand Product 2 59.98
 1003 OldBrand Product 3 79.98
 1004 OldBrand Product 4 99.98
+
+#overlay tests
+statement ok
+CREATE TABLE over_test(
+  str TEXT,
+  characters TEXT,
+  pos INT,
+  len INT
+) as VALUES
+  ('123', 'abc', 4, 5),
+  ('abcdefg', 'qwertyasdfg', 1, 7),
+  ('xyz', 'ijk', 1, 2),
+  ('Txxxxas', 'hom', 2, 4)

Review Comment:
   Can you please also test `NULL` handling here? I think your code handles it properly, but it would be good to have this in the SQL tests. We can do this as a follow on PR if you prefer. 
   
   Specifically
   ```suggestion
     ('Txxxxas', 'hom', 2, 4),
     (NULL, 'hom', 2, 4), -- expect NULL output
     ('Txxxxas', 'hom', NULL, 4), -- expect NULL output
     ('Txxxxas', 'hom', 2, NULL) -- expect NULL output
   ```



##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1120,6 +1121,21 @@ Returns UUID v4 string value which is unique per row.
 uuid()
 ```
 
+### `overlay`
+
+Returns the string which is replaced by another string from the specified position and specified count length
+
+```
+overlay(str PLACING substr FROM pos [FOR count])
+```
+

Review Comment:
   Having the example made it much easier for me to see what was going on in postgres. Can we add an example here as well?
   
   ```suggestion
   For example, `overlay('Txxxxas' placing 'hom' from 2 for 4) → Thomas`
   ```
   



##########
docs/source/user-guide/sql/scalar_functions.md:
##########
@@ -1120,6 +1121,21 @@ Returns UUID v4 string value which is unique per row.
 uuid()
 ```
 
+### `overlay`
+
+Returns the string which is replaced by another string from the specified position and specified count length
+
+```
+overlay(str PLACING substr FROM pos [FOR count])
+```
+
+#### Arguments
+
+- **str**: String expression to operate on.
+- **substr**: the string to replace part of str.
+- **pos**: the start position to replace of str.
+- **count**: the count of characters to be replaced from start position of str.If not specified, will use substr length instead.

Review Comment:
   ```suggestion
   - **count**: the count of characters to be replaced from start position of str. If not specified, will use substr length instead.
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org