MCPcopy Create free account
hub / github.com/apache/datafusion / infer_inner

Method infer_inner

datafusion/expr/src/logical_plan/builder.rs:349–373  ·  view source on GitHub ↗
(
        mut values: Vec<Vec<Expr>>,
        fields: ValuesFields,
        schema: &DFSchema,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
ValuesClass · 0.85
into_fieldsMethod · 0.80
LiteralInterface · 0.50
mapMethod · 0.45
iterMethod · 0.45
data_typeMethod · 0.45
cloneMethod · 0.45
cast_toMethod · 0.45

Tested by

no test coverage detected