You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/08/03 23:41:40 UTC

[arrow-datafusion] branch master updated: feat: Enable typed strings expressions for VALUES clause (#3018)

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

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new c57fc863f feat: Enable typed strings expressions for VALUES clause (#3018)
c57fc863f is described below

commit c57fc863f3dd04210347ccd527a7b5ffaab41f2c
Author: Stuart Carnie <st...@gmail.com>
AuthorDate: Thu Aug 4 09:41:36 2022 +1000

    feat: Enable typed strings expressions for VALUES clause (#3018)
    
    * feat: Add support for typed strings to VALUES clause
    
    * chore: Tidy up 🧹
---
 datafusion/sql/src/planner.rs | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 423f8bce0..d93076fbd 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -1613,6 +1613,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                                 &schema,
                                 &mut HashMap::new(),
                             ),
+                        SQLExpr::TypedString { data_type, value } => Ok(Expr::Cast {
+                            expr: Box::new(lit(value)),
+                            data_type: convert_data_type(&data_type)?,
+                        }),
                         other => Err(DataFusionError::NotImplemented(format!(
                             "Unsupported value {:?} in a values list expression",
                             other
@@ -1809,11 +1813,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             }),
 
             SQLExpr::TypedString {
-                ref data_type,
-                ref value,
+                data_type,
+                value,
             } => Ok(Expr::Cast {
-                expr: Box::new(lit(&**value)),
-                data_type: convert_data_type(data_type)?,
+                expr: Box::new(lit(value)),
+                data_type: convert_data_type(&data_type)?,
             }),
 
             SQLExpr::IsNull(expr) => Ok(Expr::IsNull(Box::new(
@@ -3247,6 +3251,17 @@ mod tests {
         );
     }
 
+    #[test]
+    fn select_from_typed_string_values() {
+        quick_test(
+            "SELECT col1, col2 FROM (VALUES (TIMESTAMP '2021-06-10 17:01:00Z', DATE '2004-04-09')) as t (col1, col2)",
+            "Projection: #t.col1, #t.col2\
+            \n  Projection: #t.column1 AS col1, #t.column2 AS col2, alias=t\
+            \n    Projection: #column1, #column2, alias=t\
+            \n      Values: (CAST(Utf8(\"2021-06-10 17:01:00Z\") AS Timestamp(Nanosecond, None)), CAST(Utf8(\"2004-04-09\") AS Date32))",
+        );
+    }
+
     #[test]
     fn select_simple_aggregate_repeated_aggregate_with_repeated_aliases() {
         let sql = "SELECT MIN(age) AS a, MIN(age) AS a FROM person";