Skip to content

Commit

Permalink
fix(binder): fix panic when index on non composite type (#4763)
Browse files Browse the repository at this point in the history
* fix panic

* fix format

* add test
  • Loading branch information
nanderstabel authored Aug 19, 2022
1 parent 0e6c653 commit d86dae2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions e2e_test/batch/aggregate/aggregate2/test.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copied from https://github.com/duckdb/duckdb (MIT licensed).
# Copyright 2018-2022 Stichting DuckDB Foundation

statement ok
SET RW_IMPLICIT_FLUSH TO true;

statement ok
create table t(v1 int);

statement ok
select * from t where v1[1]=1;
7 changes: 7 additions & 0 deletions e2e_test/batch/basic/array_access.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ NULL

statement error
select (ARRAY['foo', 'bar'])[];

# array access is not possible for non-composite types
statement error
select (1::INT)[1];

statement error
select ('a'::VARCHAR)[1];
6 changes: 5 additions & 1 deletion src/frontend/src/binder/expr/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ impl Binder {
FunctionCall::new_unchecked(ExprType::ArrayAccess, indexs, *return_type).into();
Ok(expr)
}
_ => panic!("Should be a List"),
data_type => Err(ErrorCode::BindError(format!(
"array index applied to type {}, which is not a composite type",
data_type
))
.into()),
}
}

Expand Down

0 comments on commit d86dae2

Please sign in to comment.