-
Notifications
You must be signed in to change notification settings - Fork 466
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
sql: support USING on implicitly coercible data types #5313
sql: support USING on implicitly coercible data types #5313
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, do you have a source that the logic for coerce_homogenous_exprs is indeed what's needed here? Mostly just curious, seems right!
test/testdrive/joins.td
Outdated
@@ -239,3 +239,41 @@ Unable to automatically determine a timestamp for your query; this can happen if | |||
|
|||
! SELECT * FROM names FULL OUTER JOIN mods_unmat ON 1 = 0; | |||
Unable to automatically determine a timestamp for your query; this can happen if your query depends on non-materialized sources | |||
|
|||
# Test joins on implicitly coercible data types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this needs to be tested in testdrive as opposed to the sqllogictests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that an SLT here would be best!
src/sql/src/plan/query.rs
Outdated
for column_name in column_names { | ||
let (l, _) = left_scope.resolve_column(column_name)?; | ||
let (lhs, _) = left_scope.resolve_column(column_name)?; | ||
let (r, _) = right_scope.resolve_column(column_name)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: for consistency s/r/rhs/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, but I think a small reordering (of stuff that existed before) could improve clarity. 1s!
test/testdrive/joins.td
Outdated
@@ -239,3 +239,41 @@ Unable to automatically determine a timestamp for your query; this can happen if | |||
|
|||
! SELECT * FROM names FULL OUTER JOIN mods_unmat ON 1 = 0; | |||
Unable to automatically determine a timestamp for your query; this can happen if your query depends on non-materialized sources | |||
|
|||
# Test joins on implicitly coercible data types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that an SLT here would be best!
@justinj really, really good q re: As for a source, the logic is that for the join to work, the two expressions must be of the same type, as evidenced by the fact that Not sure if I under-, over-, or incorrect-dimensionally-shot your question, but please lmk! |
Ok, what do you think about restructuring the body of the loop in let (lhs, _) = left_scope.resolve_column(column_name)?;
let (mut rhs, _) = right_scope.resolve_column(column_name)?;
if lhs.level != 0 || rhs.level != 0 {
bail!(
"Internal error: name {} in USING resolved to outer column",
column_name
)
}
// The new column can be named using aliases from either the right or
// left.
let mut names = left_scope.items[lhs.column].names.clone();
names.extend(right_scope.items[rhs.column].names.clone());
// Adjust the RHS reference to its post-join location.
rhs.column += left_scope.len();
// Join keys must be resolved to same type.
let mut exprs = coerce_homogeneous_exprs(
&format!("NATURAL/USING join column {}", column_name),
&ecx,
vec![
CoercibleScalarExpr::Coerced(ScalarExpr::Column(lhs)),
CoercibleScalarExpr::Coerced(ScalarExpr::Column(rhs)),
],
None,
)?;
let (expr1, expr2) = (exprs.remove(0), exprs.remove(0));
join_exprs.push(ScalarExpr::CallBinary {
func: BinaryFunc::Eq,
expr1: Box::new(expr1.clone()),
expr2: Box::new(expr2.clone()),
});
map_exprs.push(ScalarExpr::CallVariadic {
func: VariadicFunc::Coalesce,
exprs: vec![expr1, expr2],
});
new_items.push(ScopeItem {
names,
expr: None,
nameable: true,
});
dropped_columns.insert(lhs.column);
dropped_columns.insert(rhs.column); The idea is to do the thing that requires the unadjusted RHS column, adjust the RHS column, and then do all the things that require the adjusted RHS column. |
93f40cd
to
ada366d
Compare
@benesch Nice 🙇🙇🙇 |
ada366d
to
1bb475c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks swell to me!
Fixes MaterializeInc/database-issues#1629
This change is