findepi commented on code in PR #12864: URL: https://github.com/apache/datafusion/pull/12864#discussion_r1812014006
########## datafusion/expr/src/logical_plan/builder.rs: ########## @@ -196,16 +224,58 @@ impl LogicalPlanBuilder { } } - let empty_schema = DFSchema::empty(); + // Check the type of value against the schema + if let Some(schema) = schema { + Self::infer_values_from_schema(values, schema) + } else { + // Infer from data itself + Self::infer_data(values) + } + } + + fn infer_values_from_schema( + values: Vec<Vec<Expr>>, + schema: &DFSchema, + ) -> Result<Self> { + let n_cols = values[0].len(); + let mut field_types: Vec<DataType> = Vec::with_capacity(n_cols); + for j in 0..n_cols { + let field_type = schema.field(j).data_type(); + for row in values.iter() { + let value = &row[j]; + let data_type = value.get_type(schema)?; + + if !data_type.equals_datatype(field_type) { Review Comment: Doing this has consequences like https://github.com/apache/datafusion/pull/12864#issuecomment-2431080081 and https://github.com/apache/datafusion/pull/12864#issuecomment-2431086676. I don't see how it would be useful. Asking `value.get_type(schema)` with some special schema makes sense only for column references, and in VALUES there cannot be any (unless the purpose of this patch is to support correlated values, but it doesn't seem so). Did you mean `schema.field(j).data_type()`? But then i believe this is almost equivalent to https://github.com/apache/datafusion/pull/12104 which seemed not accepted so far. Except that PR did it for INSERT and this one does it for CTAS. cc @alamb -- 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