Skip to content

Apache DataFusion SQL Query Engine

feat: Enable typed strings expressions for VALUES clause (#3018)

Stuart Carniec57fc863f3dd
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 423f8bce02..d93076fbdd 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";