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

Method intersect_or_except

datafusion/expr/src/logical_plan/builder.rs:1377–1435  ·  view source on GitHub ↗

Process intersect or except

(
        left_plan: LogicalPlan,
        right_plan: LogicalPlan,
        join_type: JoinType,
        is_all: bool,
    )

Source from the content-addressed store, hash-verified

1375
1376 /// Process intersect or except
1377 fn intersect_or_except(
1378 left_plan: LogicalPlan,
1379 right_plan: LogicalPlan,
1380 join_type: JoinType,
1381 is_all: bool,
1382 ) -> Result<LogicalPlan> {
1383 let left_len = left_plan.schema().fields().len();
1384 let right_len = right_plan.schema().fields().len();
1385
1386 if left_len != right_len {
1387 return plan_err!(
1388 "INTERSECT/EXCEPT query must have the same number of columns. Left is {left_len} and right is {right_len}."
1389 );
1390 }
1391
1392 // Requalify sides if needed to avoid duplicate qualified field names
1393 // (e.g., when both sides reference the same table)
1394 let left_builder = LogicalPlanBuilder::from(left_plan);
1395 let right_builder = LogicalPlanBuilder::from(right_plan);
1396 let (left_builder, right_builder, _requalified) =
1397 requalify_sides_if_needed(left_builder, right_builder)?;
1398 let left_plan = left_builder.build()?;
1399 let right_plan = right_builder.build()?;
1400
1401 let join_keys = left_plan
1402 .schema()
1403 .fields()
1404 .iter()
1405 .zip(right_plan.schema().fields().iter())
1406 .map(|(left_field, right_field)| {
1407 (
1408 (Column::from_name(left_field.name())),
1409 (Column::from_name(right_field.name())),
1410 )
1411 })
1412 .unzip();
1413 if is_all {
1414 LogicalPlanBuilder::from(left_plan)
1415 .join_detailed(
1416 right_plan,
1417 join_type,
1418 join_keys,
1419 None,
1420 NullEquality::NullEqualsNull,
1421 )?
1422 .build()
1423 } else {
1424 LogicalPlanBuilder::from(left_plan)
1425 .distinct()?
1426 .join_detailed(
1427 right_plan,
1428 join_type,
1429 join_keys,
1430 None,
1431 NullEquality::NullEqualsNull,
1432 )?
1433 .build()
1434 }

Callers

nothing calls this directly

Calls 10

join_detailedMethod · 0.80
lenMethod · 0.45
fieldsMethod · 0.45
schemaMethod · 0.45
buildMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
nameMethod · 0.45
distinctMethod · 0.45

Tested by

no test coverage detected