Skip to content

Commit 38b1af0

Browse files
committed
refactor: refine cast reloperator error info
1 parent ce031db commit 38b1af0

File tree

6 files changed

+79
-53
lines changed

6 files changed

+79
-53
lines changed

src/query/sql/src/planner/binder/bind_query/bind.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ impl Binder {
4545
let (limit, offset) = self.extract_limit_and_offset(query)?;
4646

4747
// Bind query body.
48-
let (mut s_expr, mut bind_context) = Box::pin(self.bind_set_expr(
49-
bind_context,
50-
&query.body,
51-
&query.order_by,
52-
limit.unwrap_or_default(),
53-
))
54-
.await?;
48+
let (mut s_expr, mut bind_context) =
49+
Box::pin(self.bind_set_expr(bind_context, &query.body, &query.order_by, limit)).await?;
5550

5651
// Bind order by for `SetOperation` and `Values`.
5752
s_expr = self

src/query/sql/src/planner/binder/bind_query/bind_select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Binder {
6868
bind_context: &mut BindContext,
6969
stmt: &SelectStmt,
7070
order_by: &[OrderByExpr],
71-
limit: usize,
71+
limit: Option<usize>,
7272
) -> Result<(SExpr, BindContext)> {
7373
if let Some(hints) = &stmt.hints {
7474
if let Some(e) = self.opt_hints_set_var(bind_context, hints).await.err() {
@@ -214,7 +214,7 @@ impl Binder {
214214
&select_list,
215215
&where_scalar,
216216
&order_items.items,
217-
limit,
217+
limit.unwrap_or_default(),
218218
)?;
219219
}
220220

src/query/sql/src/planner/binder/bind_query/bind_set_expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Binder {
2727
bind_context: &mut BindContext,
2828
set_expr: &SetExpr,
2929
order_by: &[OrderByExpr],
30-
limit: usize,
30+
limit: Option<usize>,
3131
) -> Result<(SExpr, BindContext)> {
3232
match set_expr {
3333
SetExpr::Select(stmt) => {

src/query/sql/src/planner/binder/bind_table_reference/bind_table_function.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ impl Binder {
104104
window_list: None,
105105
qualify: None,
106106
};
107-
let (srf_expr, mut bind_context) =
108-
self.bind_select(bind_context, &select_stmt, &[], 0).await?;
107+
let (srf_expr, mut bind_context) = self
108+
.bind_select(bind_context, &select_stmt, &[], None)
109+
.await?;
109110

110111
return self
111112
.extract_srf_table_function_columns(

src/query/sql/src/planner/binder/select.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ impl Binder {
125125
op: &SetOperator,
126126
all: &bool,
127127
) -> Result<(SExpr, BindContext)> {
128-
let (left_expr, left_bind_context) = self.bind_set_expr(bind_context, left, &[], 0).await?;
128+
let (left_expr, left_bind_context) =
129+
self.bind_set_expr(bind_context, left, &[], None).await?;
129130
let (right_expr, right_bind_context) =
130-
self.bind_set_expr(bind_context, right, &[], 0).await?;
131+
self.bind_set_expr(bind_context, right, &[], None).await?;
131132

132133
if left_bind_context.columns.len() != right_bind_context.columns.len() {
133134
return Err(ErrorCode::SemanticError(

src/query/sql/src/planner/plans/operator.rs

+68-39
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,10 @@ impl TryFrom<RelOperator> for Scan {
414414
if let RelOperator::Scan(value) = value {
415415
Ok(value)
416416
} else {
417-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Scan"))
417+
Err(ErrorCode::Internal(format!(
418+
"Cannot downcast {:?} to Scan",
419+
value.rel_op()
420+
)))
418421
}
419422
}
420423
}
@@ -432,9 +435,10 @@ impl TryFrom<RelOperator> for CteScan {
432435
if let RelOperator::CteScan(value) = value {
433436
Ok(value)
434437
} else {
435-
Err(ErrorCode::Internal(
436-
"Cannot downcast RelOperator to CteScan",
437-
))
438+
Err(ErrorCode::Internal(format!(
439+
"Cannot downcast {:?} to CteScan",
440+
value.rel_op()
441+
)))
438442
}
439443
}
440444
}
@@ -452,9 +456,10 @@ impl TryFrom<RelOperator> for MaterializedCte {
452456
if let RelOperator::MaterializedCte(value) = value {
453457
Ok(value)
454458
} else {
455-
Err(ErrorCode::Internal(
456-
"Cannot downcast RelOperator to MaterializedCte",
457-
))
459+
Err(ErrorCode::Internal(format!(
460+
"Cannot downcast {:?} to MaterializedCte",
461+
value.rel_op()
462+
)))
458463
}
459464
}
460465
}
@@ -471,9 +476,10 @@ impl TryFrom<RelOperator> for Join {
471476
if let RelOperator::Join(value) = value {
472477
Ok(value)
473478
} else {
474-
Err(ErrorCode::Internal(
475-
"Cannot downcast RelOperator to LogicalJoin",
476-
))
479+
Err(ErrorCode::Internal(format!(
480+
"Cannot downcast {:?} to Join",
481+
value.rel_op()
482+
)))
477483
}
478484
}
479485
}
@@ -490,9 +496,10 @@ impl TryFrom<RelOperator> for EvalScalar {
490496
if let RelOperator::EvalScalar(value) = value {
491497
Ok(value)
492498
} else {
493-
Err(ErrorCode::Internal(
494-
"Cannot downcast RelOperator to EvalScalar",
495-
))
499+
Err(ErrorCode::Internal(format!(
500+
"Cannot downcast {:?} to EvalScalar",
501+
value.rel_op()
502+
)))
496503
}
497504
}
498505
}
@@ -509,7 +516,10 @@ impl TryFrom<RelOperator> for Filter {
509516
if let RelOperator::Filter(value) = value {
510517
Ok(value)
511518
} else {
512-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Filter"))
519+
Err(ErrorCode::Internal(format!(
520+
"Cannot downcast {:?} to Filter",
521+
value.rel_op()
522+
)))
513523
}
514524
}
515525
}
@@ -526,9 +536,10 @@ impl TryFrom<RelOperator> for Aggregate {
526536
if let RelOperator::Aggregate(value) = value {
527537
Ok(value)
528538
} else {
529-
Err(ErrorCode::Internal(
530-
"Cannot downcast RelOperator to Aggregate",
531-
))
539+
Err(ErrorCode::Internal(format!(
540+
"Cannot downcast {:?} to Aggregate",
541+
value.rel_op()
542+
)))
532543
}
533544
}
534545
}
@@ -545,7 +556,10 @@ impl TryFrom<RelOperator> for Window {
545556
if let RelOperator::Window(value) = value {
546557
Ok(value)
547558
} else {
548-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Window"))
559+
Err(ErrorCode::Internal(format!(
560+
"Cannot downcast {:?} to Window",
561+
value.rel_op()
562+
)))
549563
}
550564
}
551565
}
@@ -562,7 +576,10 @@ impl TryFrom<RelOperator> for Sort {
562576
if let RelOperator::Sort(value) = value {
563577
Ok(value)
564578
} else {
565-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Sort"))
579+
Err(ErrorCode::Internal(format!(
580+
"Cannot downcast {:?} to Sort",
581+
value.rel_op()
582+
)))
566583
}
567584
}
568585
}
@@ -579,7 +596,10 @@ impl TryFrom<RelOperator> for Limit {
579596
if let RelOperator::Limit(value) = value {
580597
Ok(value)
581598
} else {
582-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Limit"))
599+
Err(ErrorCode::Internal(format!(
600+
"Cannot downcast {:?} to Limit",
601+
value.rel_op()
602+
)))
583603
}
584604
}
585605
}
@@ -596,9 +616,10 @@ impl TryFrom<RelOperator> for Exchange {
596616
if let RelOperator::Exchange(value) = value {
597617
Ok(value)
598618
} else {
599-
Err(ErrorCode::Internal(
600-
"Cannot downcast RelOperator to Exchange",
601-
))
619+
Err(ErrorCode::Internal(format!(
620+
"Cannot downcast {:?} to Exchange",
621+
value.rel_op()
622+
)))
602623
}
603624
}
604625
}
@@ -615,9 +636,10 @@ impl TryFrom<RelOperator> for UnionAll {
615636
if let RelOperator::UnionAll(value) = value {
616637
Ok(value)
617638
} else {
618-
Err(ErrorCode::Internal(
619-
"Cannot downcast RelOperator to UnionAll",
620-
))
639+
Err(ErrorCode::Internal(format!(
640+
"Cannot downcast {:?} to UnionAll",
641+
value.rel_op()
642+
)))
621643
}
622644
}
623645
}
@@ -634,9 +656,10 @@ impl TryFrom<RelOperator> for DummyTableScan {
634656
if let RelOperator::DummyTableScan(value) = value {
635657
Ok(value)
636658
} else {
637-
Err(ErrorCode::Internal(
638-
"Cannot downcast RelOperator to DummyTableScan",
639-
))
659+
Err(ErrorCode::Internal(format!(
660+
"Cannot downcast {:?} to DummyTableScan",
661+
value.rel_op()
662+
)))
640663
}
641664
}
642665
}
@@ -654,9 +677,10 @@ impl TryFrom<RelOperator> for ProjectSet {
654677
if let RelOperator::ProjectSet(value) = value {
655678
Ok(value)
656679
} else {
657-
Err(ErrorCode::Internal(
658-
"Cannot downcast RelOperator to ProjectSet",
659-
))
680+
Err(ErrorCode::Internal(format!(
681+
"Cannot downcast {:?} to ProjectSet",
682+
value.rel_op()
683+
)))
660684
}
661685
}
662686
}
@@ -680,9 +704,10 @@ impl TryFrom<RelOperator> for ConstantTableScan {
680704
if let RelOperator::ConstantTableScan(value) = value {
681705
Ok(value)
682706
} else {
683-
Err(ErrorCode::Internal(
684-
"Cannot downcast RelOperator to ConstantTableScan",
685-
))
707+
Err(ErrorCode::Internal(format!(
708+
"Cannot downcast {:?} to ConstantTableScan",
709+
value.rel_op()
710+
)))
686711
}
687712
}
688713
}
@@ -700,7 +725,10 @@ impl TryFrom<RelOperator> for Udf {
700725
if let RelOperator::Udf(value) = value {
701726
Ok(value)
702727
} else {
703-
Err(ErrorCode::Internal("Cannot downcast RelOperator to Udf"))
728+
Err(ErrorCode::Internal(format!(
729+
"Cannot downcast {:?} to Udf",
730+
value.rel_op()
731+
)))
704732
}
705733
}
706734
}
@@ -718,9 +746,10 @@ impl TryFrom<RelOperator> for AsyncFunction {
718746
if let RelOperator::AsyncFunction(value) = value {
719747
Ok(value)
720748
} else {
721-
Err(ErrorCode::Internal(
722-
"Cannot downcast RelOperator to AsyncFunction",
723-
))
749+
Err(ErrorCode::Internal(format!(
750+
"Cannot downcast {:?} to AsyncFunction",
751+
value.rel_op()
752+
)))
724753
}
725754
}
726755
}

0 commit comments

Comments
 (0)