| 347 | } |
| 348 | |
| 349 | fn infer_inner( |
| 350 | mut values: Vec<Vec<Expr>>, |
| 351 | fields: ValuesFields, |
| 352 | schema: &DFSchema, |
| 353 | ) -> Result<Self> { |
| 354 | let fields = fields.into_fields(); |
| 355 | // wrap cast if data type is not same as common type. |
| 356 | for row in &mut values { |
| 357 | for (j, field_type) in fields.iter().map(|f| f.data_type()).enumerate() { |
| 358 | if let Expr::Literal(ScalarValue::Null, metadata) = &row[j] { |
| 359 | row[j] = Expr::Literal( |
| 360 | ScalarValue::try_from(field_type)?, |
| 361 | metadata.clone(), |
| 362 | ); |
| 363 | } else { |
| 364 | row[j] = std::mem::take(&mut row[j]).cast_to(field_type, schema)?; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | let dfschema = DFSchema::from_unqualified_fields(fields, HashMap::new())?; |
| 370 | let schema = DFSchemaRef::new(dfschema); |
| 371 | |
| 372 | Ok(Self::new(LogicalPlan::Values(Values { schema, values }))) |
| 373 | } |
| 374 | |
| 375 | /// Convert a table provider into a builder with a TableScan |
| 376 | /// |