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

fix(binder): bind correlated column without intermediate RwError #6194

Merged
merged 3 commits into from
Nov 3, 2022
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
31 changes: 20 additions & 11 deletions src/frontend/src/binder/bind_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use parse_display::Display;
use risingwave_common::catalog::Field;
use risingwave_common::error::{ErrorCode, Result};

type LiteResult<T> = std::result::Result<T, ErrorCode>;

use crate::binder::COLUMN_GROUP_PREFIX;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -102,13 +104,14 @@ impl BindContext {
&self,
table_name: &Option<String>,
column_name: &String,
) -> Result<usize> {
) -> LiteResult<usize> {
match &self.get_column_binding_indices(table_name, column_name)?[..] {
[] => unreachable!(),
[idx] => Ok(*idx),
_ => Err(
ErrorCode::InternalError(format!("Ambiguous column name: {}", column_name)).into(),
),
_ => Err(ErrorCode::InternalError(format!(
"Ambiguous column name: {}",
column_name
))),
}
}

Expand All @@ -119,7 +122,7 @@ impl BindContext {
&self,
table_name: &Option<String>,
column_name: &String,
) -> Result<Vec<usize>> {
) -> LiteResult<Vec<usize>> {
match table_name {
Some(table_name) => {
if let Some(group_id_str) = table_name.strip_prefix(COLUMN_GROUP_PREFIX) {
Expand All @@ -136,7 +139,11 @@ impl BindContext {
}
}

fn get_indices_with_group_id(&self, group_id: u32, column_name: &String) -> Result<Vec<usize>> {
fn get_indices_with_group_id(
&self,
group_id: u32,
column_name: &String,
) -> LiteResult<Vec<usize>> {
let group = self.column_group_context.groups.get(&group_id).unwrap();
if let Some(name) = &group.column_name {
debug_assert_eq!(name, column_name);
Expand All @@ -151,7 +158,7 @@ impl BindContext {
}
}

pub fn get_unqualified_indices(&self, column_name: &String) -> Result<Vec<usize>> {
pub fn get_unqualified_indices(&self, column_name: &String) -> LiteResult<Vec<usize>> {
let columns = self
.indices_of
.get(column_name)
Expand All @@ -170,7 +177,10 @@ impl BindContext {
}
}
}
Err(ErrorCode::InternalError(format!("Ambiguous column name: {}", column_name)).into())
Err(ErrorCode::InternalError(format!(
"Ambiguous column name: {}",
column_name
)))
} else {
Ok(columns.to_vec())
}
Expand Down Expand Up @@ -252,7 +262,7 @@ impl BindContext {
&self,
column_name: &String,
table_name: &String,
) -> Result<usize> {
) -> LiteResult<usize> {
let column_indexes = self
.indices_of
.get(column_name)
Expand All @@ -265,8 +275,7 @@ impl BindContext {
None => Err(ErrorCode::ItemNotFound(format!(
"missing FROM-clause entry for table \"{}\"",
table_name
))
.into()),
))),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/binder/expr/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ impl Binder {
}
Err(e) => {
// If the error message is not that the column is not found, throw the error
if let ErrorCode::ItemNotFound(_) = e.inner() {
if let ErrorCode::ItemNotFound(_) = e {
} else {
return Err(e);
return Err(e.into());
}
}
}

// Try to find a correlated column in `upper_contexts`, starting from the innermost context.
let mut err = ErrorCode::ItemNotFound(format!("Invalid column: {}", column_name)).into();
let mut err = ErrorCode::ItemNotFound(format!("Invalid column: {}", column_name));
for (i, (context, _)) in self.upper_subquery_contexts.iter().rev().enumerate() {
// `depth` starts from 1.
let depth = i + 1;
Expand All @@ -92,6 +92,6 @@ impl Binder {
}
}
}
Err(err)
Err(err.into())
}
}
4 changes: 2 additions & 2 deletions src/frontend/src/binder/relation/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ impl Binder {
}
let indices_l = match old_context.get_unqualified_indices(&column.value) {
Err(e) => {
if let ErrorCode::ItemNotFound(_) = e.inner() {
if let ErrorCode::ItemNotFound(_) = e {
continue;
} else {
return Err(e);
return Err(e.into());
}
}
Ok(idxs) => idxs,
Expand Down