Skip to content

Commit

Permalink
Make binary operator type signatures less restrictive
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-spacetime committed Sep 23, 2024
1 parent 3fd6405 commit bb87e04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 5 additions & 6 deletions crates/planner/src/logical/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,9 @@ mod tests {
"select * from (select t.* from t join s)",
"select * from (select t.* from t join s on t.u32 = s.u32 where t.f32 = 0.1)",
"select * from (select t.* from t join (select s.u32 from s) s on t.u32 = s.u32)",
"select * from (select * from t union all select * from t)",
] {
let result = parse_and_type_sub(sql, &tx).inspect_err(|_| {
// println!("sql: {}\n\n\terr: {}\n", sql, err);
});
let result = parse_and_type_sub(sql, &tx);
assert!(result.is_ok());
}
}
Expand Down Expand Up @@ -391,10 +390,10 @@ mod tests {
"select * from (select s.* from t join (select s.u32 from s) s on t.u32 = s.u32)",
// Field bytes is no longer in scope
"select * from (select t.* from t join (select s.u32 from s) s on s.bytes = 0xABCD)",
// Union arguments are of different types
"select * from (select * from t union all select * from s)",
] {
let result = parse_and_type_sub(sql, &tx).inspect_err(|_| {
// println!("sql: {}\n\n\terr: {}\n", sql, err);
});
let result = parse_and_type_sub(sql, &tx);
assert!(result.is_err());
}
}
Expand Down
9 changes: 3 additions & 6 deletions crates/planner/src/logical/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,9 @@ impl Type {
/// Is this type compatible with this binary operator?
pub fn is_compatible_with(&self, op: BinOp) -> bool {
match (op, self) {
// Logic operators take booleans
(BinOp::And | BinOp::Or, Type::Alg(AlgebraicType::Bool)) => true,
// Comparison operators take integers or floats
(BinOp::Lt | BinOp::Gt | BinOp::Lte | BinOp::Gte, Type::Alg(t)) => t.is_integer() || t.is_float(),
// Equality supports booleans, numerics, strings, and bytes
(BinOp::Eq | BinOp::Ne, Type::Alg(t)) => {
(BinOp::And | BinOp::Or, _) => false,
(BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Gt | BinOp::Lte | BinOp::Gte, Type::Alg(t)) => {
t.is_bool()
|| t.is_integer()
|| t.is_float()
Expand All @@ -209,7 +206,7 @@ impl Type {
|| t.is_identity()
|| t.is_address()
}
_ => false,
(BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Gt | BinOp::Lte | BinOp::Gte, _) => false,
}
}

Expand Down

0 comments on commit bb87e04

Please sign in to comment.