alamb commented on code in PR #10445:
URL: https://github.com/apache/datafusion/pull/10445#discussion_r1597428939


##########
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();

Review Comment:
   Hi @b41sh 👋 
   
   > . Do you mean to move the code for extracting the common types of values 
to type_coercion.rs? One problem is that optimizer crate depends on expr crate 
and we can't call the optimizer crate function in LogicalPlanBuilder. 
   
   I was more thinking something like
   1. Make no changes to `LogicalPlanBuilder` 
   2. Instead, add code that coerces (adds casts) to the values in 
`LogicalPlan::Values` as part of the `TypeCoercion` rule
   
   This would mean that the result of `LogicalPlanBuilder` would still have 
incompatible types until the `TypeCoercion` is run.
   
   The benefit of this approach would be that when the `TypeCoercion` rule  is 
run, it would have the entire plan, including the table into which the values 
were being inserted, and so could maybe pick better types
   
   The drawback is I think it would be a larger and more invasive change



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to