jayzhan211 commented on code in PR #12864: URL: https://github.com/apache/datafusion/pull/12864#discussion_r1812163418
########## 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) { + if can_cast_types(&data_type, field_type) { + } else { Review Comment: We are checking whether we can cast the given data type to the one in the schema, so I think the existing code is the correct one. -- 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