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

Error if subqueries contain more than one result #5651

Merged
merged 18 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve naming and documentation
  • Loading branch information
frankmcsherry committed Mar 29, 2021
commit 1d7fb3109d1ba490a870c6fa0c745cb82ba2b4de
8 changes: 1 addition & 7 deletions src/expr/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,10 @@ pub enum EvalError {
Parse(ParseError),
ParseHex(ParseHexError),
Internal(String),
<<<<<<< HEAD
InfinityOutOfDomain(String),
NegativeOutOfDomain(String),
ZeroOutOfDomain(String),
=======
TooManyDamnRecords,
>>>>>>> ad2034333 (error if subqueries contain more than one result)
}

impl fmt::Display for EvalError {
Expand Down Expand Up @@ -960,7 +957,6 @@ impl fmt::Display for EvalError {
EvalError::Parse(e) => e.fmt(f),
EvalError::ParseHex(e) => e.fmt(f),
EvalError::Internal(s) => write!(f, "internal error: {}", s),
<<<<<<< HEAD
EvalError::InfinityOutOfDomain(s) => {
write!(f, "function {} is only defined for finite arguments", s)
}
Expand All @@ -970,6 +966,7 @@ impl fmt::Display for EvalError {
EvalError::ZeroOutOfDomain(s) => {
write!(f, "function {} is not defined for zero", s)
}
EvalError::TooManyDamnRecords => write!(f, "more than one record produced in subquery"),
}
}
}
Expand All @@ -985,9 +982,6 @@ impl EvalError {
"Input data is missing padding, is truncated, or is otherwise corrupted.".into(),
),
_ => None,
=======
EvalError::TooManyDamnRecords => write!(f, "more than one record produced in subquery"),
>>>>>>> ad2034333 (error if subqueries contain more than one result)
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/sql/src/plan/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,10 @@ impl HirScalarExpr {
let col_type = select.typ().column_types.into_last();

let inner_arity = get_inner.arity();
// We must determine a count for each `get_inner` prefix,
// and report an error if that count exceeds one.
let guarded = select.let_in(id_gen, |_id_gen, get_select| {
// We must determine a count for each `get_inner` prefix,
// and report an error if that count exceeds one.
// Count for each `get_inner` prefix.
let counts = get_select.clone().reduce(
(0..inner_arity).collect::<Vec<_>>(),
vec![expr::AggregateExpr {
Expand All @@ -688,7 +689,7 @@ impl HirScalarExpr {
)])
.project((0..inner_arity).collect::<Vec<_>>())
.map(vec![expr::MirScalarExpr::literal(
Err(expr::EvalError::TooManyDamnRecords),
Err(expr::EvalError::MultipleRowsFromSubquery),
col_type.clone().scalar_type,
)]);
// Return `get_select` and any errors added in.
Expand Down