Creates a schema for a join operation. The fields from the left side are first
(
left: &DFSchema,
right: &DFSchema,
join_type: &JoinType,
)
| 1660 | /// Creates a schema for a join operation. |
| 1661 | /// The fields from the left side are first |
| 1662 | pub 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 | } |
searching dependent graphs…