You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/03 12:49:27 UTC

[GitHub] [arrow-datafusion] WinkerDu opened a new pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

WinkerDu opened a new pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142


   # Which issue does this PR close?
   
   <!--
   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 #2141 .
   
    # 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.  
   -->
   df now has not implemented `StringConcat` operator, like
   
   ```
   ❯ select 'aa' || 'b';
   NotImplemented("Unsupported SQL binary operator StringConcat")
   ```
   But Postgres SQL will come out results like
   
   ```
   select 'aa' || 'b';
    ?column? 
   ----------
    aab
   (1 row)
   ```
   
   # 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.
   -->
   Reuse df build-in `concat` string expression to do it.
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   No.
   
   <!--
   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



[GitHub] [arrow-datafusion] jackwener commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
jackwener commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841232235



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![
+        "+---------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(NULL) || Utf8(\"d\") |",
+        "+---------------------------------------+",
+        "| aad                                   |",
+        "+---------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+    Ok(())

Review comment:
       I think we can add more case test.
   
   For example
   
   ```
   string || non-string or non-string || string  
   ---like--- 
   input : 'Value: ' || 42 
   output : Value: 42
   
   ```




-- 
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



[GitHub] [arrow-datafusion] jackwener commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
jackwener commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841231240



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![

Review comment:
       It's different with pg.
   
   PG like this.
   ```sql
   test=# select 'sss' || null || 'aaa' as result;
    result
   --------
   
   (1 row)
   ```




-- 
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



[GitHub] [arrow-datafusion] WinkerDu commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841239314



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![

Review comment:
       @jackwener Thanks,  I am a bit conservative on what GP behaves like, we can discuss more on 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: github-unsubscribe@arrow.apache.org

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



[GitHub] [arrow-datafusion] jackwener commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
jackwener commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841231240



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![

Review comment:
       It's different with pg.
   
   PG like this.
   ```sql
   test=# select 'sss' || null || 'aaa'as result;
    result
   --------
   
   (1 row)
   ```




-- 
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



[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#issuecomment-1086892111


   @jackwener thank you for your comment.
   I'm not sure what GP behaves like is reasonable, PG build-in expression `concat` can take `NULL` like
   ```
   select concat('aa', NULL, 'b');
    concat 
   --------
    aab
   (1 row)
   ```
   I prefer unify the outputs of `||` and `concat`, what other contributors think of?


-- 
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



[GitHub] [arrow-datafusion] jackwener commented on pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
jackwener commented on pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#issuecomment-1086881244


   Great job! ❤


-- 
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



[GitHub] [arrow-datafusion] WinkerDu commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841239314



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![

Review comment:
       @jackwener Thanks,  I am a bit conservative on what PG behaves like, we can discuss more on 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: github-unsubscribe@arrow.apache.org

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



[GitHub] [arrow-datafusion] WinkerDu edited a comment on pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu edited a comment on pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#issuecomment-1086892111


   @jackwener thank you for your comment.
   I'm not sure what PG behaves like is reasonable, PG build-in expression `concat` can take `NULL` like
   ```
   select concat('aa', NULL, 'b');
    concat 
   --------
    aab
   (1 row)
   ```
   I prefer unify the outputs of `||` and `concat`, what other contributors think of?


-- 
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



[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#issuecomment-1086880759


   cc @Dandandan @alamb @xudong963 @yjshen 
   Please have a review, thank you.


-- 
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



[GitHub] [arrow-datafusion] WinkerDu commented on a change in pull request #2142: implement 'StringConcat' operator to support sql like "select 'aa' || 'b' "

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on a change in pull request #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841239409



##########
File path: datafusion/core/tests/sql/expr.rs
##########
@@ -280,6 +280,47 @@ async fn query_scalar_minus_array() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_string_concat_operator() -> Result<()> {
+    let ctx = SessionContext::new();
+    // concat 2 strings
+    let sql = "SELECT 'aa' || 'b'";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") |",
+        "+-------------------------+",
+        "| aab                     |",
+        "+-------------------------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+
+    // concat 4 strings as a string concat pipe.
+    let sql = "SELECT 'aa' || 'b' || 'cc' || 'd'";
+    let expected = vec![
+        "+----------------------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(\"b\") || Utf8(\"cc\") || Utf8(\"d\") |",
+        "+----------------------------------------------------+",
+        "| aabccd                                             |",
+        "+----------------------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+
+    // concat 3 strings with one is NULL
+    let sql = "SELECT 'aa' || NULL || 'd'";
+    let expected = vec![
+        "+---------------------------------------+",
+        "| Utf8(\"aa\") || Utf8(NULL) || Utf8(\"d\") |",
+        "+---------------------------------------+",
+        "| aad                                   |",
+        "+---------------------------------------+",
+    ];
+    let actual = execute_to_batches(&ctx, sql).await;
+    assert_batches_eq!(expected, &actual);
+    Ok(())

Review comment:
       @jackwener OK, I'll add more cases




-- 
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