Uh oh!
There was an error while loading. Please reload this page.
Support struct_expr generate struct in sql - #2389
Conversation
Uh oh!
There was an error while loading. Please reload this page.
| BuiltinScalarFunction::Struct => { | ||
| let fields = input_expr_types | ||
| .iter() | ||
| .map(|x| Field::new("item", x.clone(), true)) |
There was a problem hiding this comment.
This looks like it is generating a struct where all of the fields have the same name. I would expect that to cause an error.
There was a problem hiding this comment.
Fix, It should only need the DataType info, no need for fields name
| .map(|(i, arg)| -> (Field, ArrayRef) { | ||
| match arg.data_type() { | ||
| DataType::Utf8 => ( | ||
| Field::new(&*format!("f_{}", i), DataType::Utf8, true), |
There was a problem hiding this comment.
format!("f_{}", i) is duplicated in each match. Could we create the column name once before the match statement?
There was a problem hiding this comment.
Sure! Thanks for your advice.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Andy Grove <andygrove73@gmail.com>
| Field::new(field_name.as_str(), arg.data_type().clone(), true), | ||
| arg.clone(), | ||
| ), | ||
| data_type => unimplemented!("struct not support {} type", data_type), |
There was a problem hiding this comment.
We should return an Err rather than panic here
andygrove
left a comment
There was a problem hiding this comment.
LGTM once the error handling is updated to return Err rather than panic. Thanks @Ted-Jiang
Uh oh!
There was an error while loading. Please reload this page.
Which issue does this PR close?
Related #2043.
Rationale for this change
Support construct a struct in SQL.
What changes are included in this PR?
Are there any user-facing changes?
Now the struct Field only support default name like
f_nI want to use `select struct(1 as a)' as field name, but got error in parsing
I think it should fix in sql-parse, if wrong plz correct me.
I will create follow up ticket for this, if this PR is fine.