Skip to content

Commit

Permalink
add cast support inside values() (#3447)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmitchener authored Sep 12, 2022
1 parent c5c1dae commit 3e56a0f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
28 changes: 28 additions & 0 deletions datafusion/core/tests/sql/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,34 @@ async fn select_values_list() -> Result<()> {
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "EXPLAIN VALUES ('1'::float)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------------+-----------------------------------+",
"| plan_type | plan |",
"+---------------+-----------------------------------+",
"| logical_plan | Values: (Float32(1) AS Utf8(\"1\")) |",
"| physical_plan | ValuesExec |",
"| | |",
"+---------------+-----------------------------------+",
];
assert_batches_eq!(expected, &actual);
}
{
let sql = "EXPLAIN VALUES (('1'||'2')::int unsigned)";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+---------------+------------------------------------------------+",
"| plan_type | plan |",
"+---------------+------------------------------------------------+",
"| logical_plan | Values: (UInt32(12) AS Utf8(\"1\") || Utf8(\"2\")) |",
"| physical_plan | ValuesExec |",
"| | |",
"+---------------+------------------------------------------------+",
];
assert_batches_eq!(expected, &actual);
}
Ok(())
}

Expand Down
8 changes: 8 additions & 0 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
expr: Box::new(lit(value)),
data_type: convert_data_type(&data_type)?,
}),
SQLExpr::Cast { expr, data_type } => Ok(Expr::Cast {
expr: Box::new(self.sql_expr_to_logical_expr(
*expr,
&schema,
&mut HashMap::new(),
)?),
data_type: convert_data_type(&data_type)?,
}),
other => Err(DataFusionError::NotImplemented(format!(
"Unsupported value {:?} in a values list expression",
other
Expand Down

0 comments on commit 3e56a0f

Please sign in to comment.