From d86dae20221f5d65e1301373563706bcb435f7c2 Mon Sep 17 00:00:00 2001 From: nanderstabel Date: Fri, 19 Aug 2022 17:44:01 +0200 Subject: [PATCH] fix(binder): fix panic when index on non composite type (#4763) * fix panic * fix format * add test --- e2e_test/batch/aggregate/aggregate2/test.slt.part | 11 +++++++++++ e2e_test/batch/basic/array_access.slt.part | 7 +++++++ src/frontend/src/binder/expr/value.rs | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 e2e_test/batch/aggregate/aggregate2/test.slt.part diff --git a/e2e_test/batch/aggregate/aggregate2/test.slt.part b/e2e_test/batch/aggregate/aggregate2/test.slt.part new file mode 100644 index 0000000000000..c54d9987e5822 --- /dev/null +++ b/e2e_test/batch/aggregate/aggregate2/test.slt.part @@ -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; diff --git a/e2e_test/batch/basic/array_access.slt.part b/e2e_test/batch/basic/array_access.slt.part index 6eacaf4962882..1650128d9c922 100644 --- a/e2e_test/batch/basic/array_access.slt.part +++ b/e2e_test/batch/basic/array_access.slt.part @@ -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]; diff --git a/src/frontend/src/binder/expr/value.rs b/src/frontend/src/binder/expr/value.rs index dee7325a7685f..219f1bdb37c3e 100644 --- a/src/frontend/src/binder/expr/value.rs +++ b/src/frontend/src/binder/expr/value.rs @@ -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()), } }