From 38b1af0303246b9d32cee2b88ff064250fe502a5 Mon Sep 17 00:00:00 2001 From: xudong963 Date: Mon, 27 May 2024 16:04:36 +0800 Subject: [PATCH] refactor: refine cast reloperator error info --- .../sql/src/planner/binder/bind_query/bind.rs | 9 +- .../planner/binder/bind_query/bind_select.rs | 4 +- .../binder/bind_query/bind_set_expr.rs | 2 +- .../bind_table_function.rs | 5 +- src/query/sql/src/planner/binder/select.rs | 5 +- src/query/sql/src/planner/plans/operator.rs | 107 +++++++++++------- 6 files changed, 79 insertions(+), 53 deletions(-) diff --git a/src/query/sql/src/planner/binder/bind_query/bind.rs b/src/query/sql/src/planner/binder/bind_query/bind.rs index 62cb67853f06..91a2b907cc9b 100644 --- a/src/query/sql/src/planner/binder/bind_query/bind.rs +++ b/src/query/sql/src/planner/binder/bind_query/bind.rs @@ -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 diff --git a/src/query/sql/src/planner/binder/bind_query/bind_select.rs b/src/query/sql/src/planner/binder/bind_query/bind_select.rs index ff223627dcfd..aea4e487368e 100644 --- a/src/query/sql/src/planner/binder/bind_query/bind_select.rs +++ b/src/query/sql/src/planner/binder/bind_query/bind_select.rs @@ -68,7 +68,7 @@ impl Binder { bind_context: &mut BindContext, stmt: &SelectStmt, order_by: &[OrderByExpr], - limit: usize, + limit: Option, ) -> Result<(SExpr, BindContext)> { if let Some(hints) = &stmt.hints { if let Some(e) = self.opt_hints_set_var(bind_context, hints).await.err() { @@ -214,7 +214,7 @@ impl Binder { &select_list, &where_scalar, &order_items.items, - limit, + limit.unwrap_or_default(), )?; } diff --git a/src/query/sql/src/planner/binder/bind_query/bind_set_expr.rs b/src/query/sql/src/planner/binder/bind_query/bind_set_expr.rs index d5f937a99682..cd58ac497ef9 100644 --- a/src/query/sql/src/planner/binder/bind_query/bind_set_expr.rs +++ b/src/query/sql/src/planner/binder/bind_query/bind_set_expr.rs @@ -27,7 +27,7 @@ impl Binder { bind_context: &mut BindContext, set_expr: &SetExpr, order_by: &[OrderByExpr], - limit: usize, + limit: Option, ) -> Result<(SExpr, BindContext)> { match set_expr { SetExpr::Select(stmt) => { diff --git a/src/query/sql/src/planner/binder/bind_table_reference/bind_table_function.rs b/src/query/sql/src/planner/binder/bind_table_reference/bind_table_function.rs index bbc87d96663f..9acdd0a9bde8 100644 --- a/src/query/sql/src/planner/binder/bind_table_reference/bind_table_function.rs +++ b/src/query/sql/src/planner/binder/bind_table_reference/bind_table_function.rs @@ -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( diff --git a/src/query/sql/src/planner/binder/select.rs b/src/query/sql/src/planner/binder/select.rs index 37b54ad0280b..8831f2b01407 100644 --- a/src/query/sql/src/planner/binder/select.rs +++ b/src/query/sql/src/planner/binder/select.rs @@ -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( diff --git a/src/query/sql/src/planner/plans/operator.rs b/src/query/sql/src/planner/plans/operator.rs index 3008b8a49b9f..74c70b99c53e 100644 --- a/src/query/sql/src/planner/plans/operator.rs +++ b/src/query/sql/src/planner/plans/operator.rs @@ -414,7 +414,10 @@ impl TryFrom 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() + ))) } } } @@ -432,9 +435,10 @@ impl TryFrom 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() + ))) } } } @@ -452,9 +456,10 @@ impl TryFrom 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() + ))) } } } @@ -471,9 +476,10 @@ impl TryFrom 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() + ))) } } } @@ -490,9 +496,10 @@ impl TryFrom 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() + ))) } } } @@ -509,7 +516,10 @@ impl TryFrom 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() + ))) } } } @@ -526,9 +536,10 @@ impl TryFrom 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() + ))) } } } @@ -545,7 +556,10 @@ impl TryFrom 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() + ))) } } } @@ -562,7 +576,10 @@ impl TryFrom 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() + ))) } } } @@ -579,7 +596,10 @@ impl TryFrom 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() + ))) } } } @@ -596,9 +616,10 @@ impl TryFrom 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() + ))) } } } @@ -615,9 +636,10 @@ impl TryFrom 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() + ))) } } } @@ -634,9 +656,10 @@ impl TryFrom 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() + ))) } } } @@ -654,9 +677,10 @@ impl TryFrom 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() + ))) } } } @@ -680,9 +704,10 @@ impl TryFrom 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() + ))) } } } @@ -700,7 +725,10 @@ impl TryFrom 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() + ))) } } } @@ -718,9 +746,10 @@ impl TryFrom 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() + ))) } } }