jayzhan211 commented on code in PR #10445:
URL: https://github.com/apache/datafusion/pull/10445#discussion_r1597437435
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -188,37 +181,61 @@ impl LogicalPlanBuilder {
n_cols
);
}
- field_types = row
- .iter()
- .enumerate()
- .map(|(j, expr)| {
- if let Expr::Literal(ScalarValue::Null) = expr {
- nulls.push((i, j));
- Ok(field_types[j].clone())
- } else {
- let data_type = expr.get_type(&empty_schema)?;
- if let Some(prev_data_type) = &field_types[j] {
- if prev_data_type != &data_type {
- return plan_err!("Inconsistent data type
across values list at row {i} column {j}. Was {prev_data_type} but found
{data_type}")
+ }
+
+ let empty_schema = DFSchema::empty();
+ let mut field_types: Vec<DataType> = Vec::with_capacity(n_cols);
+ for j in 0..n_cols {
+ let mut common_type: Option<DataType> = None;
+ for (i, row) in values.iter().enumerate() {
+ let value = &row[j];
+ if let Expr::Literal(ScalarValue::Null) = value {
+ continue;
+ } else {
+ let data_type = value.get_type(&empty_schema)?;
+ if let Some(prev_type) = common_type {
+ // get common type of each row values.
+ match comparison_coercion(&data_type, &prev_type) {
Review Comment:
Pull string coercion part out of `string_coercion` as `pure_string_coercion`
```
(Utf8, Utf8) => Some(Utf8),
(LargeUtf8, Utf8) => Some(LargeUtf8),
(Utf8, LargeUtf8) => Some(LargeUtf8),
(LargeUtf8, LargeUtf8) => Some(LargeUtf8),
```
Ideally, values coercion should follow what `union`, `case` does
https://www.postgresql.org/docs/current/typeconv-oper.html
But the actual behavior is expected to follow what postgres or duckdb or
other well-known db does.
I would expect the coercion rule that is included to have the corresponding
test covered.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]