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

Function build_join_schema

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

Creates a schema for a join operation. The fields from the left side are first

(
    left: &DFSchema,
    right: &DFSchema,
    join_type: &JoinType,
)

Source from the content-addressed store, hash-verified

1660/// Creates a schema for a join operation.
1661/// The fields from the left side are first
1662pub fn build_join_schema(
1663 left: &DFSchema,
1664 right: &DFSchema,
1665 join_type: &JoinType,
1666) -> Result<DFSchema> {
1667 fn nullify_fields<'a>(
1668 fields: impl Iterator<Item = (Option<&'a TableReference>, &'a Arc<Field>)>,
1669 ) -> Vec<(Option<TableReference>, Arc<Field>)> {
1670 fields
1671 .map(|(q, f)| {
1672 // TODO: find a good way to do that
1673 let field = f.as_ref().clone().with_nullable(true);
1674 (q.cloned(), Arc::new(field))
1675 })
1676 .collect()
1677 }
1678
1679 let right_fields = right.iter();
1680 let left_fields = left.iter();
1681
1682 let qualified_fields: Vec<(Option<TableReference>, Arc<Field>)> = match join_type {
1683 JoinType::Inner => {
1684 // left then right
1685 let left_fields = left_fields
1686 .map(|(q, f)| (q.cloned(), Arc::clone(f)))
1687 .collect::<Vec<_>>();
1688 let right_fields = right_fields
1689 .map(|(q, f)| (q.cloned(), Arc::clone(f)))
1690 .collect::<Vec<_>>();
1691 left_fields.into_iter().chain(right_fields).collect()
1692 }
1693 JoinType::Left => {
1694 // left then right, right set to nullable in case of not matched scenario
1695 let left_fields = left_fields
1696 .map(|(q, f)| (q.cloned(), Arc::clone(f)))
1697 .collect::<Vec<_>>();
1698 left_fields
1699 .into_iter()
1700 .chain(nullify_fields(right_fields))
1701 .collect()
1702 }
1703 JoinType::Right => {
1704 // left then right, left set to nullable in case of not matched scenario
1705 let right_fields = right_fields
1706 .map(|(q, f)| (q.cloned(), Arc::clone(f)))
1707 .collect::<Vec<_>>();
1708 nullify_fields(left_fields)
1709 .into_iter()
1710 .chain(right_fields)
1711 .collect()
1712 }
1713 JoinType::Full => {
1714 // left then right, all set to nullable in case of not matched scenario
1715 nullify_fields(left_fields)
1716 .into_iter()
1717 .chain(nullify_fields(right_fields))
1718 .collect()
1719 }

Callers 9

recompute_schemaMethod · 0.70
with_new_exprsMethod · 0.70
try_newMethod · 0.70
test_join_metadataFunction · 0.70
find_inner_joinFunction · 0.50
newMethod · 0.50

Calls 14

nullify_fieldsFunction · 0.85
mark_fieldFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
mapMethod · 0.45
clonedMethod · 0.45
into_iterMethod · 0.45
joinMethod · 0.45
lenMethod · 0.45
fieldsMethod · 0.45

Tested by 2

test_join_metadataFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…