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

feat(function-v2): add tuple() and get() for tuple #8372

Merged
merged 17 commits into from
Oct 21, 2022
13 changes: 9 additions & 4 deletions src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,21 +1823,26 @@ impl<'a> TypeChecker<'a> {
MapAccessor::Period { key } | MapAccessor::Colon { key } => {
Literal::String(key.name.clone())
}
MapAccessor::PeriodNumber { key } => Literal::Integer(key - 1),
MapAccessor::PeriodNumber { key } => Literal::Integer(key),
_ => unreachable!(),
};

match accessor_lit {
Literal::Integer(idx) => {
if idx as usize >= inner_types.len() {
if idx == 0 {
return Err(ErrorCode::SemanticError(format!(
"tuple index is starting from 1, but 0 is found",
)));
}
if idx as usize > inner_types.len() {
return Err(ErrorCode::SemanticError(format!(
"tuple index {} is out of bounds for length {}",
idx,
inner_types.len()
)));
}
let inner_name = inner_names.get(idx as usize).unwrap();
let inner_type = inner_types.get(idx as usize).unwrap();
let inner_name = inner_names.get(idx as usize - 1).unwrap();
andylokandy marked this conversation as resolved.
Show resolved Hide resolved
let inner_type = inner_types.get(idx as usize - 1).unwrap();
names.push(inner_name.clone());
data_types.push(inner_type.clone());
}
Expand Down