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

Method infer_data

datafusion/expr/src/logical_plan/builder.rs:297–347  ·  view source on GitHub ↗
(values: Vec<Vec<Expr>>)

Source from the content-addressed store, hash-verified

295 }
296
297 fn infer_data(values: Vec<Vec<Expr>>) -> Result<Self> {
298 let n_cols = values[0].len();
299 let schema = DFSchema::empty();
300 let mut fields = ValuesFields::new();
301
302 for j in 0..n_cols {
303 let mut common_type: Option<DataType> = None;
304 let mut common_metadata: Option<FieldMetadata> = None;
305 for (i, row) in values.iter().enumerate() {
306 let value = &row[j];
307 let metadata = value.metadata(&schema)?;
308 if let Some(ref cm) = common_metadata {
309 if &metadata != cm {
310 return plan_err!(
311 "Inconsistent metadata across values list at row {i} column {j}. Was {:?} but found {:?}",
312 cm,
313 metadata
314 );
315 }
316 } else {
317 common_metadata = Some(metadata.clone());
318 }
319 let data_type = value.get_type(&schema)?;
320 if data_type == DataType::Null {
321 continue;
322 }
323
324 if let Some(prev_type) = common_type {
325 // get common type of each column values.
326 let data_types = vec![prev_type.clone(), data_type.clone()];
327 let Some(new_type) = type_union_resolution(&data_types) else {
328 return plan_err!(
329 "Inconsistent data type across values list at row {i} column {j}. Was {prev_type} but found {data_type}"
330 );
331 };
332 common_type = Some(new_type);
333 } else {
334 common_type = Some(data_type);
335 }
336 }
337 // assuming common_type was not set, and no error, therefore the type should be NULL
338 // since the code loop skips NULL
339 fields.push_with_metadata(
340 common_type.unwrap_or(DataType::Null),
341 true,
342 common_metadata,
343 );
344 }
345
346 Self::infer_inner(values, fields, &schema)
347 }
348
349 fn infer_inner(
350 mut values: Vec<Vec<Expr>>,

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
type_union_resolutionFunction · 0.85
push_with_metadataMethod · 0.80
emptyFunction · 0.50
lenMethod · 0.45
iterMethod · 0.45
metadataMethod · 0.45
cloneMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected