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

refactor: refine cast reloperator error info #15648

Merged
merged 1 commit into from
May 27, 2024
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
9 changes: 2 additions & 7 deletions src/query/sql/src/planner/binder/bind_query/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ impl Binder {
let (limit, offset) = self.extract_limit_and_offset(query)?;

// Bind query body.
let (mut s_expr, mut bind_context) = Box::pin(self.bind_set_expr(
bind_context,
&query.body,
&query.order_by,
limit.unwrap_or_default(),
))
.await?;
let (mut s_expr, mut bind_context) =
Box::pin(self.bind_set_expr(bind_context, &query.body, &query.order_by, limit)).await?;

// Bind order by for `SetOperation` and `Values`.
s_expr = self
Expand Down
4 changes: 2 additions & 2 deletions src/query/sql/src/planner/binder/bind_query/bind_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Binder {
bind_context: &mut BindContext,
stmt: &SelectStmt,
order_by: &[OrderByExpr],
limit: usize,
limit: Option<usize>,
) -> Result<(SExpr, BindContext)> {
if let Some(hints) = &stmt.hints {
if let Some(e) = self.opt_hints_set_var(bind_context, hints).await.err() {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Binder {
&select_list,
&where_scalar,
&order_items.items,
limit,
limit.unwrap_or_default(),
)?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Binder {
bind_context: &mut BindContext,
set_expr: &SetExpr,
order_by: &[OrderByExpr],
limit: usize,
limit: Option<usize>,
) -> Result<(SExpr, BindContext)> {
match set_expr {
SetExpr::Select(stmt) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ impl Binder {
window_list: None,
qualify: None,
};
let (srf_expr, mut bind_context) =
self.bind_select(bind_context, &select_stmt, &[], 0).await?;
let (srf_expr, mut bind_context) = self
.bind_select(bind_context, &select_stmt, &[], None)
.await?;

return self
.extract_srf_table_function_columns(
Expand Down
5 changes: 3 additions & 2 deletions src/query/sql/src/planner/binder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ impl Binder {
op: &SetOperator,
all: &bool,
) -> Result<(SExpr, BindContext)> {
let (left_expr, left_bind_context) = self.bind_set_expr(bind_context, left, &[], 0).await?;
let (left_expr, left_bind_context) =
self.bind_set_expr(bind_context, left, &[], None).await?;
let (right_expr, right_bind_context) =
self.bind_set_expr(bind_context, right, &[], 0).await?;
self.bind_set_expr(bind_context, right, &[], None).await?;

if left_bind_context.columns.len() != right_bind_context.columns.len() {
return Err(ErrorCode::SemanticError(
Expand Down
107 changes: 68 additions & 39 deletions src/query/sql/src/planner/plans/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ impl TryFrom<RelOperator> for Scan {
if let RelOperator::Scan(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Scan"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Scan",
value.rel_op()
)))
}
}
}
Expand All @@ -432,9 +435,10 @@ impl TryFrom<RelOperator> for CteScan {
if let RelOperator::CteScan(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to CteScan",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to CteScan",
value.rel_op()
)))
}
}
}
Expand All @@ -452,9 +456,10 @@ impl TryFrom<RelOperator> for MaterializedCte {
if let RelOperator::MaterializedCte(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to MaterializedCte",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to MaterializedCte",
value.rel_op()
)))
}
}
}
Expand All @@ -471,9 +476,10 @@ impl TryFrom<RelOperator> for Join {
if let RelOperator::Join(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to LogicalJoin",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Join",
value.rel_op()
)))
}
}
}
Expand All @@ -490,9 +496,10 @@ impl TryFrom<RelOperator> for EvalScalar {
if let RelOperator::EvalScalar(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to EvalScalar",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to EvalScalar",
value.rel_op()
)))
}
}
}
Expand All @@ -509,7 +516,10 @@ impl TryFrom<RelOperator> for Filter {
if let RelOperator::Filter(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Filter"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Filter",
value.rel_op()
)))
}
}
}
Expand All @@ -526,9 +536,10 @@ impl TryFrom<RelOperator> for Aggregate {
if let RelOperator::Aggregate(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to Aggregate",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Aggregate",
value.rel_op()
)))
}
}
}
Expand All @@ -545,7 +556,10 @@ impl TryFrom<RelOperator> for Window {
if let RelOperator::Window(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Window"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Window",
value.rel_op()
)))
}
}
}
Expand All @@ -562,7 +576,10 @@ impl TryFrom<RelOperator> for Sort {
if let RelOperator::Sort(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Sort"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Sort",
value.rel_op()
)))
}
}
}
Expand All @@ -579,7 +596,10 @@ impl TryFrom<RelOperator> for Limit {
if let RelOperator::Limit(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Limit"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Limit",
value.rel_op()
)))
}
}
}
Expand All @@ -596,9 +616,10 @@ impl TryFrom<RelOperator> for Exchange {
if let RelOperator::Exchange(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to Exchange",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Exchange",
value.rel_op()
)))
}
}
}
Expand All @@ -615,9 +636,10 @@ impl TryFrom<RelOperator> for UnionAll {
if let RelOperator::UnionAll(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to UnionAll",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to UnionAll",
value.rel_op()
)))
}
}
}
Expand All @@ -634,9 +656,10 @@ impl TryFrom<RelOperator> for DummyTableScan {
if let RelOperator::DummyTableScan(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to DummyTableScan",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to DummyTableScan",
value.rel_op()
)))
}
}
}
Expand All @@ -654,9 +677,10 @@ impl TryFrom<RelOperator> for ProjectSet {
if let RelOperator::ProjectSet(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to ProjectSet",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to ProjectSet",
value.rel_op()
)))
}
}
}
Expand All @@ -680,9 +704,10 @@ impl TryFrom<RelOperator> for ConstantTableScan {
if let RelOperator::ConstantTableScan(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to ConstantTableScan",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to ConstantTableScan",
value.rel_op()
)))
}
}
}
Expand All @@ -700,7 +725,10 @@ impl TryFrom<RelOperator> for Udf {
if let RelOperator::Udf(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal("Cannot downcast RelOperator to Udf"))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to Udf",
value.rel_op()
)))
}
}
}
Expand All @@ -718,9 +746,10 @@ impl TryFrom<RelOperator> for AsyncFunction {
if let RelOperator::AsyncFunction(value) = value {
Ok(value)
} else {
Err(ErrorCode::Internal(
"Cannot downcast RelOperator to AsyncFunction",
))
Err(ErrorCode::Internal(format!(
"Cannot downcast {:?} to AsyncFunction",
value.rel_op()
)))
}
}
}
Loading