This is an automated email from the ASF dual-hosted git repository.

jayzhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 58c32cbbb5 Add DuckDB struct test and row as alias (#12841)
58c32cbbb5 is described below

commit 58c32cbbb5463ff5a5a8d56a777f62a8433a4083
Author: Jay Zhan <[email protected]>
AuthorDate: Fri Oct 11 07:47:36 2024 +0800

    Add DuckDB struct test and row as alias (#12841)
    
    * add duckdb struct n row
    
    Signed-off-by: jayzhan211 <[email protected]>
    
    * fmt
    
    Signed-off-by: jayzhan211 <[email protected]>
    
    ---------
    
    Signed-off-by: jayzhan211 <[email protected]>
---
 datafusion/functions/src/core/mod.rs          |  1 +
 datafusion/functions/src/core/struct.rs       |  6 ++++
 datafusion/sqllogictest/test_files/struct.slt | 49 +++++++++++++++++++++++++++
 3 files changed, 56 insertions(+)

diff --git a/datafusion/functions/src/core/mod.rs 
b/datafusion/functions/src/core/mod.rs
index 1c69f9c9b2..cf64c03766 100644
--- a/datafusion/functions/src/core/mod.rs
+++ b/datafusion/functions/src/core/mod.rs
@@ -107,5 +107,6 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
         get_field(),
         coalesce(),
         version(),
+        r#struct(),
     ]
 }
diff --git a/datafusion/functions/src/core/struct.rs 
b/datafusion/functions/src/core/struct.rs
index bdddbb81be..5eea7dd48d 100644
--- a/datafusion/functions/src/core/struct.rs
+++ b/datafusion/functions/src/core/struct.rs
@@ -57,6 +57,7 @@ fn struct_expr(args: &[ColumnarValue]) -> 
Result<ColumnarValue> {
 #[derive(Debug)]
 pub struct StructFunc {
     signature: Signature,
+    aliases: Vec<String>,
 }
 
 impl Default for StructFunc {
@@ -69,6 +70,7 @@ impl StructFunc {
     pub fn new() -> Self {
         Self {
             signature: Signature::variadic_any(Volatility::Immutable),
+            aliases: vec![String::from("row")],
         }
     }
 }
@@ -81,6 +83,10 @@ impl ScalarUDFImpl for StructFunc {
         "struct"
     }
 
+    fn aliases(&self) -> &[String] {
+        &self.aliases
+    }
+
     fn signature(&self) -> &Signature {
         &self.signature
     }
diff --git a/datafusion/sqllogictest/test_files/struct.slt 
b/datafusion/sqllogictest/test_files/struct.slt
index d2e7160d00..67cd7d71fc 100644
--- a/datafusion/sqllogictest/test_files/struct.slt
+++ b/datafusion/sqllogictest/test_files/struct.slt
@@ -373,3 +373,52 @@ You reached the bottom!
 
 statement ok
 drop view complex_view;
+
+# Test row alias
+
+query ?
+select row('a', 'b');
+----
+{c0: a, c1: b}
+
+##################################
+# Switch Dialect to DuckDB
+##################################
+
+statement ok
+set datafusion.sql_parser.dialect = 'DuckDB';
+
+statement ok
+CREATE TABLE struct_values (
+    s1 struct(a int, b varchar),
+    s2 struct(a int, b varchar)
+) AS VALUES
+  (row(1, 'red'), row(1, 'string1')),
+  (row(2, 'blue'), row(2, 'string2')),
+  (row(3, 'green'), row(3, 'string3'))
+;
+
+statement ok
+drop table struct_values;
+
+statement ok
+create table t (c1 struct(r varchar, b int), c2 struct(r varchar, b float)) as 
values (
+    row('red', 2),
+    row('blue', 2.3)
+);
+
+query ??
+select * from t;
+----
+{r: red, b: 2} {r: blue, b: 2.3}
+
+# TODO: Should be coerced to float
+query T
+select arrow_typeof(c1) from t;
+----
+Struct([Field { name: "r", data_type: Utf8, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Int32, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])
+
+query T
+select arrow_typeof(c2) from t;
+----
+Struct([Field { name: "r", data_type: Utf8, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Float32, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }])


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to