Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed DataType propagation in joins #179

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- `DataType`` propagation in joins: if their is not INNEr or CROSS contraint, then the output `DataType`s must be optional [MR179](https://github.com/Qrlew/qrlew/pull/179)
### Added
- Implemented `Coalesce` [MR178](https://github.com/Qrlew/qrlew/pull/178)

Expand Down
13 changes: 11 additions & 2 deletions src/relation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -936,13 +936,21 @@ impl Join {
let (left_schema, right_schema) = operator.filtered_schemas(left, right);
let (left_is_unique, right_is_unique) =
operator.has_unique_constraint(left.schema(), right.schema());
let transform_datatype_in_optional_left: bool = match operator {
JoinOperator::LeftOuter(_) | JoinOperator::Inner(_) | JoinOperator::Cross=> false,
_ => true,
};
let transform_datatype_in_optional_right = match operator {
JoinOperator::RightOuter(_) | JoinOperator::Inner(_) | JoinOperator::Cross=> false,
_ => true,
};
let left_fields = left_names
.into_iter()
.zip(left_schema.iter())
.map(|(name, field)| {
Field::new(
name,
field.data_type(),
if transform_datatype_in_optional_left {DataType::optional(field.data_type())} else {field.data_type()},
if right_is_unique {
field.constraint()
} else {
Expand All @@ -956,7 +964,7 @@ impl Join {
.map(|(name, field)| {
Field::new(
name,
field.data_type(),
if transform_datatype_in_optional_right {DataType::optional(field.data_type())} else {field.data_type()},
if left_is_unique {
field.constraint()
} else {
Expand Down Expand Up @@ -1836,6 +1844,7 @@ mod tests {
let join: Join = Relation::join()
.left(table.clone())
.right(table.clone())
.left_outer()
.on(Expr::eq(
Expr::qcol(LEFT_INPUT_NAME, "id"),
Expr::qcol(RIGHT_INPUT_NAME, "id"),
Expand Down