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

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

renato2099 commented on code in PR #2142:
URL: https://github.com/apache/arrow-datafusion/pull/2142#discussion_r841282224


##########
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:
   as a user I would also expect that any operation involving  a `null` value would actually return `null` since `null != empty`, maybe there is a SQL spec somewhere we could check?



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

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